普通小车:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from gpiozero import Robot from time import sleep from gpiozero.pins.pigpio import PiGPIOFactory factory = PiGPIOFactory(host='raspberry00.local') robot = Robot(left=(15, 14), right=(18, 23),pin_factory=factory) for i in range(4): robot.forward() sleep(2) robot.right() sleep(0.5) robot.stop() |
https://gpiozero.readthedocs.io/en/stable/recipes.html#robot
键控小车:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from gpiozero import Robot from time import sleep from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero import Button factory = PiGPIOFactory(host='raspberry00.local') robot = Robot(left=(15, 14), right=(18, 23),pin_factory=factory) button = Button(21,pin_factory=factory) button.wait_for_press()# wait for button pressed print("Button was pressed") for i in range(4): robot.forward() sleep(2) robot.right() sleep(0.5) robot.stop() |
转载请注明:徐自远的乱七八糟小站 » 20181009 让树莓派小车动起来