Version avec LED, clignotante
Méthode : Code feu Maître
1
from microbit import *
2
from time import ticks_ms
3
import radio
4
5
radio.config(group=2)
6
radio.on()
7
8
DUREE = 10 # 10 secondes
9
attente = DUREE
10
feuRouge = True
11
clignotant = ticks_ms()
12
13
def afficheRouge():
14
pin1.write_digital(1)
15
pin0.write_digital(0)
16
17
def afficheOrange():
18
pin1.write_digital(0)
19
# orange clignotant20
if ticks_ms()-clignotant < 500:
21
pin0.write_digital(1)
22
else:23
pin0.write_digital(0)
24
25
def afficheAttente(attente):
26
display.show(str(attente))
27
28
while True:
29
if feuRouge :
30
afficheRouge()31
else :32
afficheOrange()33
34
# Action toutes les secondes35
if ticks_ms()-clignotant > 1000:
36
clignotant = ticks_ms()
37
attente -= 1
38
afficheAttente(attente)
39
radio.send(str(attente))
40
41
# Alternance du feu42
if attente == 0 :
43
attente=DUREE
44
feuRouge = not feuRouge
45
if feuRouge :
46
radio.send("VERT")
47
else:48
radio.send("ROUGE")
Méthode : Code feu Esclave
1
from microbit import *
2
from time import ticks_ms
3
import radio
4
5
radio.config(group=2)
6
radio.on()
7
8
feuRouge = True
9
clignotant = ticks_ms()
10
11
def afficheRouge():
12
pin1.write_digital(1)
13
pin0.write_digital(0)
14
15
def afficheOrange():
16
pin1.write_digital(0)
17
# orange clignotant18
if ticks_ms()-clignotant < 500:
19
pin0.write_digital(1)
20
else:21
pin0.write_digital(0)
22
23
def afficheAttente(attente):
24
display.show(str(attente))
25
26
while True:
27
# Traitement des messages du maitre28
incoming = radio.receive()
29
if incoming:
30
if incoming == "VERT" :
31
feuRouge = False
32
elif incoming == "ROUGE" :
33
feuRouge = True
34
elif len(incoming)==1:
35
afficheAttente(int(incoming))
36
37
# Affichage Rouge / Orange38
if feuRouge :
39
afficheRouge()40
else :41
afficheOrange()42
43
# Compteur temps à 0 toute les secondes44
if ticks_ms()-clignotant > 1000:
45
clignotant = ticks_ms()