Version 1 avec LED
Méthode : Première carte
1
from microbit import *
2
import radio
3
4
radio.config(group=2)
5
radio.on()
6
7
feuRouge = True
8
9
def afficheRouge():
10
pin1.write_digital(1)
11
pin0.write_digital(0)
12
def afficheOrange():
13
pin1.write_digital(0)
14
pin0.write_digital(1)
15
def afficheAttente(attente):
16
display.show(str(attente))
17
18
while True:
19
# Traitement des messages20
incoming = radio.receive()
21
if incoming:
22
if incoming == "VERT" :
23
feuRouge = False
24
elif incoming == "ROUGE" :
25
feuRouge = True
26
elif len(incoming) ==1:
27
afficheAttente(int(incoming))
28
29
# Affichage Rouge / Orange30
if feuRouge :
31
afficheRouge()32
else :33
afficheOrange()Méthode : Seconde carte
1
from microbit import *
2
import radio
3
4
radio.config(group=2)
5
radio.on()
6
7
DUREE = 10 # 10 secondes
8
attente = DUREE
9
feuRouge = True
10
11
def afficheRouge():
12
pin1.write_digital(1)
13
pin0.write_digital(0)
14
def afficheOrange():
15
pin1.write_digital(0)
16
pin0.write_digital(1)
17
def afficheAttente(attente):
18
display.show(str(attente))
19
20
while True:
21
# Affichage Rouge / Orange22
if feuRouge :
23
afficheRouge()24
else :25
afficheOrange()26
27
# Gestion de l'attente28
sleep(1000)
29
attente -= 1
30
afficheAttente(attente)
31
radio.send(str(attente))
32
33
# Alternance du feu34
if attente == 0 :
35
attente=DUREE
36
feuRouge = not feuRouge
37
if feuRouge :
38
radio.send("VERT")
39
else:40
radio.send("ROUGE")