Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:58 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PiciMite Simple Binary Clock

Author Message
Bleep
Guru

Joined: 09/01/2022
Location: United Kingdom
Posts: 633
Posted: 01:08pm 21 Feb 2022
Copy link to clipboard 
Print this post



Continuing on the clock theme, here is a simple binary clock, using the Pimoroni 320x240 Pico display, it reads from top to bottom, Seconds, Minutes, Hours, Day(of month), Month, Year(minus 2000). So the picture reads 11:55:58 21/02/22
If you don't like the ordering it is simple to change, just change what goes in each of the elements of array digit() you will need to then check that the appropriate elements are being checked by the code for screen updates.
Screen brightness is controlled by pressing the edge buttons, up is 'Y' or 'B', Down is 'X' or 'A'.
' Very simple binary clock, Seconds, Minutes, Hours, Day of month, Month, Year(less 2000)
' only good till 2063!
' Four push switches are
' Top Left/Right     = Brightness up
' Bottom Left/Right  = Brightness down

' turn off default typing and force explicit typing
Option DEFAULT NONE
Option EXPLICIT
' turn off RGB LED on panel while running
SetPin GP6, DIN
SetPin GP7, DIN
SetPin GP8, DIN
' turn off blinking LED while running
SetPin GP25, DOUT
' setup inputs for 4 push buttons, A,B,X,Y
SetPin GP12, DIN, PULLUP
SetPin GP13, DIN, PULLUP
SetPin GP14, DIN, PULLUP
SetPin GP15, DIN, PULLUP
' Screen = 320*240
Const width = 320
Const height = 240
Const update = 100 ' update at 10Hz
Colour RGB(WHITE), RGB(BLACK) ' Set the default colours
Font 1, 3 ' Set the default font
Dim INTEGER digit(5), digitl(5), dig, bit, bitpat

' set screen backlight to mid value
Dim INTEGER bright = 28
Backlight bright

CLS

Do
' only update time/date digits when required
   digit(5) = Eval(Right$(Time$, 2))  ' seconds
   If digit(5) <> digitl(5) Then
     digit(4) = Eval(Mid$(Time$, 4, 2)) ' minutes
     If digit(4) <> digitl(4) Then
       digit(3) = Eval(Left$(Time$, 2))   ' hours
       If digit(3) <> digitl(3) Then
         digit(2) = Eval(Left$(Date$, 2))   ' day of month
         digit(1) = Eval(Mid$(Date$, 4, 2)) ' month
         digit(0) = Eval(Right$(Date$, 4))-2000 ' year
       EndIf
     EndIf
   EndIf

' loop for each time/date digit
   For dig=0 To 5
' has the numeric time/date value changed
     If digit(dig) <> digitl(dig) Then
     digitl(dig)=digit(dig)
     bitpat=digit(dig)
       For bit=0 To 5
' calculate the binary pattern for this digit
         If bitpat Mod 2 = 0 Then
           Box (5-bit)*56, (5-dig)*41, 40, 36, 0,, RGB(0,20,0)
         Else
           Box (5-bit)*56, (5-dig)*41, 40, 36, 0,, RGB(0,250,0)
         EndIf
         bitpat=bitpat\2
       Next
     EndIf
   Next

' change brightness
   If Not Pin(GP12) Or Not Pin(GP13) Or Not Pin(GP14) Or Not Pin(GP15) Then
     If Not Pin(GP15) Or Not Pin(GP13) Then
       bright = bright + 4
       If bright >96 Then bright = 100
     Else
       bright = bright - 4
       If bright <4 Then bright = 0
     EndIf
     Backlight bright
   EndIf
   Pause update ' wait before doing next screen update
Loop


OPTIONS for Pimoroni Display and DS3231 RTC also SD card for program loading.
OPTION CPUSPEED 48000
OPTION COLOURCODE ON
OPTION DISPLAY 49, 100
OPTION SYSTEM SPI GP18,GP19,GP4
OPTION SDCARD GP5
OPTION LCDPANEL ST7789_320, L,GP16,GP22,GP17,GP20
OPTION SYSTEM I2C GP0, GP1
OPTION AUTORUN ON
OPTION RTC AUTO ENABLE

Edited 2022-02-21 23:11 by Bleep
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 07:57am 22 Feb 2022
Copy link to clipboard 
Print this post

Funny clock.

I have seen dual binary clock, but this I have never seen before.
My mind can translate from 4 bits to numbers, but this requires real dee thinking.
And since all is green, I got lost a bit.

But it is a funny project.
PicomiteVGA PETSCII ROBOTS
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025