-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandLights2.spin
66 lines (53 loc) · 1.18 KB
/
RandLights2.spin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
VAR
byte scanVal
long scanStack[12]
PUB blinken | rand, direction, out, bn, lastCnt, delay
dira[16..23]~~
scanVal:=0
direction:=1
cognew(scanCog(clkfreq/100),@scanStack)
delay := clkfreq >> 2
repeat
waitcnt(clkfreq/32 + cnt)
if scanVal & 1 == 1
rand := cnt
quit
lastCnt:=cnt
repeat
?rand
repeat bn from 0 to 31
if direction==1
out<<=1
out+=rand>>bn & 1
else
out>>=1
out&=$7f
out+=(rand>>bn & 1) << 7
if scanVal & $80 == $80
!direction
scanVal:=0
if scanVal & $10 == $10
out:=0
scanVal:=0
if scanVal & $40 == $40
delay<<=1
scanVal:=0
if scanVal & $20 == $20
delay>>=1
scanVal:=0
outa[23..16]:=out
lastCnt+=delay
waitcnt(lastCnt)
pub scanCog(delay) | pads
repeat
outa[0..7]~~
dira[0..7]~~
dira[0..7]~
waitcnt(delay+cnt)
pads := $ff & !ina[7..0]
if pads<>0
scanVal:=pads
waitcnt((delay * 20) +cnt)