vitesse = 255 if lettre == "z": spytank.avance(vitesse) elif lettre == "q": spytank.gauche(vitesse) elif lettre == "s": spytank.recule(vitesse) elif lettre == "d": spytank.droite(vitesse) elif lettre == "a": spytank.stop() elif lettre == "e": spytank.led(0,1) spytank.led(1,1) spytank.led(2,1) spytank.led(3,1) elif lettre == "r": spytank.led(0,0) spytank.led(1,0) spytank.led(2,0) spytank.led(3,0) elif lettre == "a" : spytank.stop() elif lettre == "c" : spytank.stop()
def run(self): """Code à exécuter pendant l'exécution du thread.""" while True: dist = spytank.litDistance() if dist < 25: spytank.stop() spytank.led(0, 1) spytank.led(1, 1) spytank.led(2, 1) spytank.led(3, 1) self.stop = True else: spytank.led(0, 0) spytank.led(1, 0) spytank.led(2, 0) spytank.led(3, 0) self.stop = False print(dist) time.sleep(0.5)
#!/usr/bin/env python import spytank import time for i in range(4): spytank.led(i, 1) time.sleep(0.25) time.sleep(1) for i in range(4): spytank.led(i, 0) time.sleep(0.25) spytank.avance(150) time.sleep(1) spytank.stop() time.sleep(1) spytank.recule(150) time.sleep(1) spytank.stop() time.sleep(1) spytank.droite(150) time.sleep(1) spytank.stop() time.sleep(1) print(spytank.gauche(150)) time.sleep(1) print(spytank.stop())
import spytank import time spytank.init('/dev/ttyUSB0') print('led gauche') spytank.led(spytank.LED_GAUCHE, 1) time.sleep(0.3) spytank.led(spytank.LED_GAUCHE, 0) time.sleep(0.3) print(' --') print('led droite') spytank.led(spytank.LED_DROITE, 1) time.sleep(0.3) spytank.led(spytank.LED_DROITE, 0) time.sleep(0.3) print(' --') print('avance') spytank.avance(80) time.sleep(4) spytank.stop() time.sleep(0.5) print('recule') spytank.recule(80) time.sleep(4) spytank.stop() time.sleep(0.5) print('droite') spytank.droite(80) time.sleep(4)
print("en écoute...") thread = network.newThread(socket.accept()) thread.start() #notre communication lettre = thread.clientsocket.recv(4096) lettre = lettre.decode("utf-8") print("message reçu : ", lettre) if lettre == "z": spytank.avance(125) elif lettre == "q": spytank.gauche(125) elif lettre == "s": spytank.droite(125) elif lettre == "d": spytank.recule(125) elif lettre == "e": spytank.led(0, 1) spytank.led(0, 1) spytank.led(0, 1) spytank.led(0, 1) elif lettre == "a": spytank.stop() elif lettre == "c": spytank.stop() continuer = False thread.clientsocket.send("j'ai bien reçu le message".encode())