Le bouton B remet le compteur à 0 Cas de plusieurs entrées à la salle de spectacle Plusieurs cartes pour compter les personnes Une carte centralise le compte total Nécessité de connecter nos objets via radio
Programme hex from microbit import * import radio # LES FEUX DE VELO - PROGRAMME EMETTEUR # SI ON APPUIE SUR LE BOUTON A ON ENVOIE A PAR ONDES RADIOS # SI ON APPUIE SUR LE BOUTON B ON ENVOIE B PAR ONDES RADIOS radio.config(group=1) radio.config(channel=5) radio.on()
while True: # ON ENVOIE A PAR ONDES RADIOS A if button_a.was_pressed(): radio.send("A")
# ON ENVOIE B PAR ONDES RADIOS B if button_b.was_pressed(): radio.send("B")
Programme hex from microbit import * import radio # LES FEUX DE VELO - PROGRAMME EMETTEUR # SI ON APPUIE SUR LE BOUTON A ON ENVOIE A PAR ONDES RADIOS # SI ON APPUIE SUR LE BOUTON B ON ENVOIE B PAR ONDES RADIOS radio.config(group=1) radio.config(channel=5) radio.on() while True: # ON ENVOIE A PAR ONDES RADIOS A if button_a.was_pressed(): radio.send("A") # ON ENVOIE B PAR ONDES RADIOS B if button_b.was_pressed(): radio.send("B")
Programme hex from microbit import * import radio # Configuration radio radio.config(group=1) radio.config(channel=5) radio.on() while True: i = 0 while i < 2: i = i + 1 display.show(Image.ARROW_N) sleep(200) display.clear() display.set_pixel(2, 2, 9) sleep(100) display.clear() if radio.receive() == "A": i = 0 while i < 5: i = i + 1 display.show(Image.ARROW_W) sleep(500) display.clear() display.set_pixel(2, 2, 9) sleep(200) display.clear() if radio.receive() == "B": i = 0 while i < 5: i = i + 1 display.show(Image.ARROW_E) sleep(500) display.clear() display.set_pixel(2, 2, 9) sleep(200) display.clear() display.clear()
Programme hex from microbit import * import radio # LES FEUX DE VELO - PROGRAMME EMETTEUR # SI ON APPUIE SUR LE BOUTON A ON ENVOIE A PAR ONDES RADIOS # SI ON APPUIE SUR LE BOUTON B ON ENVOIE B PAR ONDES RADIOS radio.config(group=1) radio.config(channel=5) radio.on() while True: # ON ENVOIE A PAR ONDES RADIOS A if button_a.was_pressed(): radio.send("A") # ON ENVOIE B PAR ONDES RADIOS B if button_b.was_pressed(): radio.send("B") Programme PYTHON RECEPTEUR :
Programme hex from microbit import * import radio # Configuration radio radio.config(group=1) radio.config(channel=5) radio.on() while True: i = 0 while i < 2: i = i + 1 display.show(Image.ARROW_N) sleep(200) display.clear() display.set_pixel(2, 2, 9) sleep(100) display.clear() if radio.receive() == "A": i = 0 while i < 5: i = i + 1 display.scroll('<') sleep(500) display.clear() if radio.receive() == "B": i = 0 while i < 5: i = i + 1 display.scroll('>') sleep(500) display.clear() display.clear()
Indiquer la direction par un simple mouvement de la tete – la carte maitre se trouve sur le casque du vélo
INDICE
PROGRAMME SUR UNE SEULE CARTE AVEC L’ACCELEROMETRE : from microbit import * while True: abscisse = accelerometer.get_x() if abscisse > 500: display.show(Image.ARROW_E) elif abscisse < -500: display.show(Image.ARROW_W) else: display.show(Image.ARROW_N) ------------------------------------------------------------ Programme PYTHON EMETTEUR :
Programme hex from microbit import * import radio # LES FEUX DE VELO - PROGRAMME EMETTEUR radio.config(group=1) radio.config(channel=5) radio.on() while True: abscisse = accelerometer.get_x() # ON ENVOIE B PAR ONDES RADIOS if abscisse > 500: radio.send("B") # ON ENVOIE A PAR ONDES RADIOS elif abscisse < -500: radio.send("A") Programme PYTHON RECEPTEUR :
Dans ce 1 er exercice – 1 seul feu pour commencer Feu rouge allumé – on s’arrête Temps d’attente 2 secondes Feu rouge éteint – on passe Temps d’attente 2 secondes
# Appel de la bibliothèque "microbit" from microbit import * # Boucle infinie while True: # Feu rouge allumé pin0.write_digital(1) # Attendre 2 secondes sleep(2000) # Feu rouge éteint pin0.write_digital(0) # Attendre 2 secondes sleep(2000)
PROJET 4 - COMMENT REALISER UN FEU DE TRAVAUX - 2 FEUX ?
PROGRAMME 2 : exercice 2.mp4 Comment piloter un feu de chantier ? (système embarqué très simple) Dans ce 2 eme exercice – 2 feux Feu rouge – on s’arrête Feu orange on passe Temps d’attente 2 secondes PROGRAMME 2 :
from microbit import * # 10 secondes DUREE = 10 attente = DUREE feuRouge = True def afficheRouge(): for x in range(3, 5): for y in range(2): display.set_pixel(x, y, 9) for x in range(3, 5): for y in range(3, 5): display.set_pixel(x, y, 0) def afficheOrange(): for x in range(3, 5): for y in range(2): display.set_pixel(x, y, 0) for x in range(3, 5): for y in range(3, 5): display.set_pixel(x, y, 4) def afficheAttente(attente): for x in range(2): for y in range(5): display.set_pixel(x, y, 0 if 5*x+y >= attente else 9) while True: # Affichage Rouge / Orange if feuRouge: afficheRouge() else: afficheOrange() # Gestion de l'attente sleep(1000) attente -= 1 afficheAttente(attente) # Alternance du feu if attente == 0: feuRouge = not feuRouge attente = DUREE
PROJET 7 - COMMENT PROGRAMMER LES 2 FEUX EN LIAISON RADIO ?
PROGRAMME 5 : les feux sont en opposition ! Les 2 feux affichent le même compte à rebours PROGRAMME 5 EMETTEUR :