Author Topic: A Simple Binary Display Clock  (Read 3256 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
A Simple Binary Display Clock
« on: December 31, 2020, 01:13:24 pm »
A Simplistic Binary Displayed Clock.

Code: QB64: [Select]
  1. 'Simple Binary Display Clock
  2. 'UniKorn ProDucKions 2020
  3. 'Last program of 2020 for me...
  4.  
  5. SCREEN _NEWIMAGE(640, 400, 32) 'Main Layer
  6. Clock& = _NEWIMAGE(640, 400, 32) 'Clock Base Layer
  7. Mix& = _NEWIMAGE(640, 400, 32) 'Composite Layer
  8. '---Draw Clock Base---
  9. _DEST Clock&
  10. Blank_Clock
  11. '---------------------
  12. _DEST Mix& 'draw only to mix layer
  13.  
  14. DO 'Run Our simple Binary Display Clock
  15.  _PUTIMAGE , Clock&, Mix& 'Place the blank clock
  16.  H$ = LEFT$(TIME$, 2) 'Get the Hours
  17.  M$ = MID$(TIME$, 4, 2) 'Get the Minutes
  18.  S$ = RIGHT$(TIME$, 2) 'Get the Seconds
  19.  MS$ = RIGHT$(STR$(TIMER), 2) 'Get The MilliSeconds
  20.  '"Light up" the LEDs
  21.  Light_Hour_LEDs H$
  22.  Light_Minute_LEDs M$
  23.  Light_Second_LEDs S$
  24.  Light_MilliSecond_LEDs MS$
  25.  '-------------------
  26.  _PUTIMAGE , Mix&, _DISPLAY 'Push our Clock to the display
  27.  _LIMIT 60
  28.  
  29. _DEST _DISPLAY 'Return Output to Screen layer
  30.  
  31.  
  32. SUB Blank_Clock
  33.  '------------------Blank LEDs---------------------
  34.  LINE (210, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'hours 10s
  35.  LINE (210, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  36.  LINE (220, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'hours 1s
  37.  LINE (220, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  38.  LINE (220, 140)-STEP(4, 4), _RGB32(80, 80, 80), BF
  39.  LINE (220, 160)-STEP(4, 4), _RGB32(80, 80, 80), BF
  40.  
  41.  LINE (260, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'minutes 10s
  42.  LINE (260, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  43.  LINE (260, 140)-STEP(4, 4), _RGB32(80, 80, 80), BF
  44.  LINE (270, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'minutes 1s
  45.  LINE (270, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  46.  LINE (270, 140)-STEP(4, 4), _RGB32(80, 80, 80), BF
  47.  LINE (270, 160)-STEP(4, 4), _RGB32(80, 80, 80), BF
  48.  
  49.  LINE (310, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'seconds 10s
  50.  LINE (310, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  51.  LINE (310, 140)-STEP(4, 4), _RGB32(80, 80, 80), BF
  52.  LINE (320, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'seconds 1s
  53.  LINE (320, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  54.  LINE (320, 140)-STEP(4, 4), _RGB32(80, 80, 80), BF
  55.  LINE (320, 160)-STEP(4, 4), _RGB32(80, 80, 80), BF
  56.  
  57.  LINE (360, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'Milliseconds 10s
  58.  LINE (360, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  59.  LINE (360, 140)-STEP(4, 4), _RGB32(80, 80, 80), BF
  60.  LINE (360, 160)-STEP(4, 4), _RGB32(80, 80, 80), BF
  61.  LINE (370, 100)-STEP(4, 4), _RGB32(80, 80, 80), BF 'Milliseconds 1s
  62.  LINE (370, 120)-STEP(4, 4), _RGB32(80, 80, 80), BF
  63.  LINE (370, 140)-STEP(4, 4), _RGB32(80, 80, 80), BF
  64.  LINE (370, 160)-STEP(4, 4), _RGB32(80, 80, 80), BF
  65.  '-------------------------------------------------
  66.  '----------------------Headers---------------------
  67.  LINE (210, 60)-STEP(4, 19), _RGB32(192, 192, 0), BF 'H
  68.  LINE (215, 68)-STEP(4, 4), _RGB32(192, 192, 0), BF
  69.  LINE (220, 60)-STEP(4, 19), _RGB32(192, 192, 0), BF
  70.  
  71.  LINE (260, 60)-STEP(4, 19), _RGB32(192, 192, 0), BF 'M
  72.  LINE (265, 64)-STEP(4, 4), _RGB32(192, 192, 0), BF
  73.  LINE (270, 60)-STEP(4, 19), _RGB32(192, 192, 0), BF
  74.  
  75.  LINE (320, 60)-STEP(4, 4), _RGB32(192, 192, 0), BF 'S
  76.  LINE (315, 65)-STEP(4, 4), _RGB32(192, 192, 0), BF
  77.  LINE (320, 70)-STEP(4, 4), _RGB32(192, 192, 0), BF
  78.  LINE (315, 75)-STEP(4, 4), _RGB32(192, 192, 0), BF
  79.  
  80.  LINE (350, 60)-STEP(4, 19), _RGB32(192, 192, 0), BF 'MS
  81.  LINE (355, 64)-STEP(4, 4), _RGB32(192, 192, 0), BF
  82.  LINE (360, 60)-STEP(4, 19), _RGB32(192, 192, 0), BF
  83.  LINE (375, 60)-STEP(4, 4), _RGB32(192, 192, 0), BF
  84.  LINE (370, 65)-STEP(4, 4), _RGB32(192, 192, 0), BF
  85.  LINE (375, 70)-STEP(4, 4), _RGB32(192, 192, 0), BF
  86.  LINE (370, 75)-STEP(4, 4), _RGB32(192, 192, 0), BF
  87.  '--------------------------------------------------
  88.  
  89. SUB Light_Hour_LEDs (Hour$)
  90.  Tens%% = VAL(LEFT$(Hour$, 1))
  91.  Ones%% = VAL(RIGHT$(Hour$, 1))
  92.  'tens LEDs
  93.  IF _READBIT(Tens%%, 0) THEN LINE (210, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF 'for 12 hour clock
  94.  IF _READBIT(Tens%%, 1) THEN LINE (210, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF 'for 24 hour clock
  95.  'Ones LEDs
  96.  IF _READBIT(Ones%%, 0) THEN LINE (220, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF 'hours 1s
  97.  IF _READBIT(Ones%%, 1) THEN LINE (220, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF
  98.  IF _READBIT(Ones%%, 2) THEN LINE (220, 140)-STEP(4, 4), _RGB32(255, 0, 0), BF
  99.  IF _READBIT(Ones%%, 3) THEN LINE (220, 160)-STEP(4, 4), _RGB32(255, 0, 0), BF
  100.  
  101. SUB Light_Minute_LEDs (Minute$)
  102.  Tens%% = VAL(LEFT$(Minute$, 1))
  103.  Ones%% = VAL(RIGHT$(Minute$, 1))
  104.  'tens LEDs
  105.  IF _READBIT(Tens%%, 0) THEN LINE (260, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  106.  IF _READBIT(Tens%%, 1) THEN LINE (260, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  107.  IF _READBIT(Tens%%, 2) THEN LINE (260, 140)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  108.  'Ones LEDs
  109.  IF _READBIT(Ones%%, 0) THEN LINE (270, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  110.  IF _READBIT(Ones%%, 1) THEN LINE (270, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF
  111.  IF _READBIT(Ones%%, 2) THEN LINE (270, 140)-STEP(4, 4), _RGB32(255, 0, 0), BF
  112.  IF _READBIT(Ones%%, 3) THEN LINE (270, 160)-STEP(4, 4), _RGB32(255, 0, 0), BF
  113.  
  114. SUB Light_Second_LEDs (Second$)
  115.  Tens%% = VAL(LEFT$(Second$, 1))
  116.  Ones%% = VAL(RIGHT$(Second$, 1))
  117.  'tens LEDs
  118.  IF _READBIT(Tens%%, 0) THEN LINE (310, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  119.  IF _READBIT(Tens%%, 1) THEN LINE (310, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  120.  IF _READBIT(Tens%%, 2) THEN LINE (310, 140)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  121.  'Ones LEDs
  122.  IF _READBIT(Ones%%, 0) THEN LINE (320, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  123.  IF _READBIT(Ones%%, 1) THEN LINE (320, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF
  124.  IF _READBIT(Ones%%, 2) THEN LINE (320, 140)-STEP(4, 4), _RGB32(255, 0, 0), BF
  125.  IF _READBIT(Ones%%, 3) THEN LINE (320, 160)-STEP(4, 4), _RGB32(255, 0, 0), BF
  126.  
  127. SUB Light_MilliSecond_LEDs (MilliSecond$)
  128.  Tens%% = VAL(LEFT$(MilliSecond$, 1))
  129.  Ones%% = VAL(RIGHT$(MilliSecond$, 1))
  130.  'tens LEDs
  131.  IF _READBIT(Tens%%, 0) THEN LINE (360, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  132.  IF _READBIT(Tens%%, 1) THEN LINE (360, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  133.  IF _READBIT(Tens%%, 2) THEN LINE (360, 140)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  134.  IF _READBIT(Tens%%, 3) THEN LINE (360, 160)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  135.  'Ones LEDs
  136.  IF _READBIT(Ones%%, 0) THEN LINE (370, 100)-STEP(4, 4), _RGB32(255, 0, 0), BF '
  137.  IF _READBIT(Ones%%, 1) THEN LINE (370, 120)-STEP(4, 4), _RGB32(255, 0, 0), BF
  138.  IF _READBIT(Ones%%, 2) THEN LINE (370, 140)-STEP(4, 4), _RGB32(255, 0, 0), BF
  139.  IF _READBIT(Ones%%, 3) THEN LINE (370, 160)-STEP(4, 4), _RGB32(255, 0, 0), BF
Granted after becoming radioactive I only have a half-life!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: A Simple Binary Display Clock
« Reply #1 on: January 01, 2021, 12:21:26 am »
Pretty interesting Cobalt, probably way over my head on how to use it, but pretty neat!