Created
December 7, 2013 16:03
-
-
Save Pharylon/7844378 to your computer and use it in GitHub Desktop.
Binary Clock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CON | |
_clkmode=xtal1+pll16x | |
_xinfreq=5_000_000 '5Mhz Crystal | |
CLK_FREQ = ((_clkmode-xtal1)>>6)*_xinfreq | |
MS_001 = CLK_FREQ / 1_000 | |
HPin = 27 | |
MPin = 26 | |
SPin = 16 | |
VAR | |
byte Time[6] | |
long DrawStack[20] | |
long InputStack[20] | |
byte ButtonPressed | |
pub Main | x,y | |
SetStartTime | |
CogNew(Display, @DrawStack) | |
CogNew(Input, @InputStack) | |
repeat | |
Tick | |
Pause(1000) | |
Pri Display | i | |
repeat | |
repeat i from 0 to 5 | |
If Time[i] == 1 | |
LightPixel(i, 7) | |
elseif Time[i] == 2 | |
LightPixel(i, 6) | |
elseif Time[i] == 3 | |
LightPixel(i, 7) | |
LightPixel(i, 6) | |
elseif Time[i] == 4 | |
LightPixel(i, 5) | |
elseif Time[i] == 5 | |
LightPixel(i, 5) | |
LightPixel(i, 7) | |
elseif Time[i] == 6 | |
LightPixel(i, 5) | |
LightPixel(i, 6) | |
elseif Time[i] == 7 | |
LightPixel(i, 5) | |
LightPixel(i, 6) | |
LightPixel(i, 7) | |
elseif Time[i] == 8 | |
LightPixel(i, 4) | |
elseif Time[i] == 9 | |
LightPixel(i, 4) | |
LightPixel(i, 7) | |
pri Tick | |
Time[5]++ | |
if Time[5] == 10 | |
Time[5] := 0 | |
Time[4]++ | |
If Time[4] == 6 | |
Time[4] := 0 | |
TickMinute | |
pri TickMinute | |
Time[3]++ | |
if Time[3] == 10 | |
Time[3] := 0 | |
Time[2]++ | |
If Time[2] == 6 | |
Time[2] := 0 | |
Time[3] := 0 | |
TickHour | |
pri TickHour | |
Time[1]++ | |
If Time[0] == 2 AND Time[1] == 5 | |
Time[0] := 0 | |
Time[1] := 1 | |
ElseIf Time[1] == 10 | |
Time[1] := 0 | |
Time[0]++ | |
PRI lightPixel(X, Y) | |
dira[0..8] := 0 | |
dira[X] := 1 | |
outa[X] := 0 | |
if X > Y | |
dira[Y] := 1 | |
outa[Y] := 1 | |
else | |
dira[Y + 1] := 1 | |
outa[Y + 1] := 1 | |
PRI pause(ms) | t | |
t := cnt | |
repeat ms | |
waitcnt(t += MS_001) | |
PRI SetStartTime | |
Time[0] := 1 | |
Time[1] := 9 | |
Time[2] := 4 | |
Time[3] := 1 | |
time[4] := 0 | |
Time[5] := 0 | |
dira[HPin] := 0 | |
dira[SPin] := 0 | |
dira[MPin] := 0 | |
pri Input | |
repeat | |
if ina[HPin] == 1 | |
TickHour | |
waitcnt(clkfreq/2 + cnt) | |
elseif ina[MPin] == 1 | |
Time[3]++ | |
if Time[3] == 10 | |
Time[3] := 0 | |
Time[2]++ | |
If Time[2] == 6 | |
Time[2] := 0 | |
Time[3] := 0 | |
waitcnt(clkfreq/2 + cnt) | |
elseif ina[SPin] == 1 | |
Time[4] := 0 | |
Time[5] := 0 | |
waitcnt(clkfreq/2 + cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment