-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtraffic-lights-revisited-nano
73 lines (62 loc) · 1.94 KB
/
traffic-lights-revisited-nano
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
66
67
68
69
70
71
72
\ ******************************************************************************
\ Example of FORTH traffic light management
\
\ Forth version: Flash Forth (http://flashforth.com/)
\ for ARDUINO NANO
\ author: M PETREMANN
\ Creation: 25 mai 2019
\ Modification: 30 nov 2019
\ ******************************************************************************
decimal
-readwrite \ delete precedents definitions created after -readwrite
marker -readwrite \ define marker -readwrite
decimal
\ PORTB
43 constant PORTD \ Port D Data Register
42 constant DDRD \ Port D Data Direction Register
\ 41 constant PIND \ Port D Input Pins - unused
: defLED: ( PORTx mask --- <word> | <word> --- mask port)
create
, , \ compile PORT and min mask
does>
dup @ \ push pin mask
swap 2+ @ \ push PORT
;
\ définition LED.xx
eeprom
PORTD $10 defLED: LED.red
PORTD $08 defLED: LED.yellow
PORTD $04 defLED: LED.green
: led.ON ( <pin> ---)
mset ; \ turn pin ON
: led.OFF ( <pin> ---)
mclr ; \ turn pin OFF
: init.LEDs ( ---)
LED.red drop
LED.yellow drop +
LED.green drop + DDRD mset ;
: traffic.lights ( ---)
LED.green led.ON 3000 ms LED.green led.OFF
LED.yellow led.ON 800 ms LED.yellow led.OFF
LED.red led.ON 3000 ms LED.red led.OFF ;
\ trafic.lights execute one light cycle
: lights.loop ( ---)
init.LEDs
begin
traffic.lights
key? until ;
\ german trafic light style
: D.traffic ( ---)
LED.green led.ON 3000 ms LED.green led.OFF
LED.yellow led.ON 800 ms LED.yellow led.OFF
LED.red led.ON 3000 ms
LED.yellow led.ON 800 ms
\ simultaneous red and yellow ON
LED.red led.OFF \ simultaneous red and yellow OFF
LED.yellow led.OFF ;
\ trafic.lights execute one light cycle
: D.lights.loop ( ---)
init.LEDs
begin
D.traffic
key? until ;