Virtual LED Clock For Windows By Trent Jackson


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Nice project Trent!

    I would like to see the algo you have for the calendar, if I may.

    Thanks, Ioannis

  2. #2
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    I wrote this calendar in VB early this year ....

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1651&stc=1&d=117946954 4">
    <hr/>

    Portion of code for generating the dates in ea month (2000 - 2100)
    Code:
    Public Sub Draw_Calendar()
       '-----------------------------------------------------------------------------
       '// Build / draw calendar onto field where user can actively select from it
       '-----------------------------------------------------------------------------
       
       Dim Print_Y      As Integer 'Contains current X-axis for printing
       Dim Print_X      As Integer 'Y-axis
       Dim Date_Num     As String  'Holds current day for the selected month
       Dim Cal_Col      As Integer 'Column in (6x7) matrix
       Dim Cal_Row      As Integer 'Row
       Dim Days_From_01 As Long    'Total days from the year 0001
       Dim Start_Day    As Long    'First day of the month
       Dim i            As Long    'General working var
       ReDim Grid_Dat(6, 7)        'Grid contents (all the dates in the month)
       
       '// From Jan 0001 to 2000 there's 730127 days (Crucial needed key to this algorithm)
       Days_From_01 = 730127
       
       '// Wipe area ready for new print / render
       Calendar_Field.Cls
       
       If Draw_3D_Cells.Checked Then
          Blit_3D_Cells
       End If
       
       Days_In_Months(2) = 28 'Assume no leap
       '// Check for leap year with currently selected year
       If Is_Leap_Year(Set_Year) Then Days_In_Months(2) = 29
       
       '// Add up total days from yr 2000 until selected yr
       For i = 2000 To Set_Year - 1
           Days_In_Year = 365     'No leap
       
       '// Check for leap
           If Is_Leap_Year(i) Then
              Days_In_Year = 366  'Leap
           End If
       
       '// Sum it all
           Days_From_01 = Days_From_01 + Days_In_Year
       Next i
    
       '// Add up total days until a month before the selected month
       For i = 1 To (Set_Month - 1)
           Days_From_01 = Days_From_01 + Days_In_Months(i)
       Next i
    
       '// Swap vars (new meaninful name with what we're about to do next)
       Start_Day = Days_From_01
    
       '// Dec week until we find the start day of the month
       Do While Start_Day > 7: Start_Day = Start_Day - 7: Loop
    
       '// Reset to 0 if > 7
       Start_Day = Start_Day Mod 7
       
       '// Starting print coords
       Print_X = (Start_Day * 23) + 5
       Print_Y = 5
       
       '// Starting col in sync with the actual first day of the month
       Cal_Col = Start_Day
       
       '// Loop through days in month (1 to total)         '
       For i = 1 To Days_In_Months(Set_Month)
       
       '// Set new row after 7 across (gird is 6x7)
           If Print_X > 160 Then                           '
              Print_Y = Print_Y + 23                       'Inc
              Print_X = 5                                  'Reset
              Cal_Row = Cal_Row + 1                        'Inc
              Cal_Col = 0                                  'Reset
           End If
                  
       '// Copy var to string
           Date_Num = Trim(Str(i))
           
       '// Add space for single digit vals (center alignment)
           If Len(Date_Num) = 1 Then
              Date_Num = Space(1) & Date_Num
           End If
           
       '// Print date to feild using the TextOut API (much faster)
           TextOut Calendar_Field.hdc, Print_X, Print_Y, Date_Num, Len(Date_Num)
                 
       '// Store locations in grid array for later usage (user clicks fields)
           Grid_Dat(Cal_Row, Cal_Col) = Date_Num
           
       '// Inc X-axis for printing and col pos
           Print_X = Print_X + 23
           Cal_Col = Cal_Col + 1
       Next
       
       Start_Day = Start_Day + Set_Day                     'Set start day in month
       Cal_Col = 0                                         'Reset col & row
       Cal_Row = 0                                         '
          
       '-----------------------------------------------------------------------------
       '// Here we need to locate the col & row in the grid that matches first day
       '-----------------------------------------------------------------------------
       For i = 0 To Start_Day - 1                          'Loop through
           Cal_Col = Cal_Col + 1                           'Inc col
           If Cal_Col = 7 Then                             'New row?
              Cal_Row = Cal_Row + 1                        'Inc row
              Cal_Col = 0                                  'Reset col
           End If
       Next
       
       If Show_3D_Sel.Checked Then
       '// Blit selected 3D cell
          BitBlt Calendar_Field.hdc, Cal_Col * 23 + 3, Cal_Row * 23 + 3, 20, 20, Selected_3D.hdc, 0, 0, SrcCopy
          
       '// Rectangle around it
          Rectangle Calendar_Field.hdc, Cal_Col * 23 + 3, Cal_Row * 23 + 3, 23 + Cal_Col * 23, 23 + Cal_Row * 23
          
       '// Show day inside cell
          TextOut Calendar_Field.hdc, Cal_Col * 23 + 5, Cal_Row * 23 + 5, Grid_Dat(Cal_Row, Cal_Col), Len(Grid_Dat(Cal_Row, Cal_Col))
          '//
       Else '(Show 2D selector)
          '//
       '// Position selector square to selected day in the month
          Selector.Move (Cal_Col * 23) + 5, (Cal_Row * 23) + 5
       
       '// Show date inside square
          Selector.Cls
          TextOut Selector.hdc, 1, 0, Grid_Dat(Cal_Row, Cal_Col), Len(Grid_Dat(Cal_Row, Cal_Col))
       End If
          
       '// Build return string (mm-dd-yy)
       Return_Date = Set_Month & "-" & Grid_Dat(Cal_Row, Cal_Col) & "-" & Set_Year
       Call Extract_Date_Specifics
       
       '// Update bottom portion of picker with a readout of the selected date
       Show_Date.Caption = Format(Return_Date, IIf(Show_Long_Date.Checked, "dddd, mmmm d, yyyy", "dd/mm/yyyy"))
       
       '// Reset (var only used by Set_Picker_Date proc to force a sel)
       Set_Day = 0
    
       '// Draw grid? (optional)
       If Show_Grid.Checked Then
          Draw_Grid
       End If
       
       Calendar_Field.Refresh
    End Sub
    *Definitely not directly applicable to PBP, there's lot of work needed to port it. Be great if PBP supported strings & string manipulation !
    <br/>
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by T.Jackson; - 18th May 2007 at 07:43.

  3. #3
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by Ioannis View Post
    Nice project Trent!

    I would like to see the algo you have for the calendar, if I may.

    Thanks, Ioannis
    By the way - you have some nice products!

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Thanks for the post. I thought it was for the PIC itself though!

    Thanks also for the comment about my products. Wait to see the new ones!

    Regards,
    Ioannis

  5. #5
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    No worries. A calendar project for PBP is kind of swimming around in my mind a bit at the moment, so don't be too surprised to see something a bit further down the track.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Thanks! If I 'll find the time, I may do it first! Will see..

    Ioannis

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts