From d211dae7b08ea546ba5bdd0bcd3b1679dbbc1705 Mon Sep 17 00:00:00 2001 From: Ben Nuttall Date: Mon, 17 Oct 2016 15:41:55 +0100 Subject: [PATCH] Use GPIO Zero for RTK MCB --- src/en/overlay/rtk-000-001.md | 38 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/en/overlay/rtk-000-001.md b/src/en/overlay/rtk-000-001.md index 60fc2a8..4cf0889 100644 --- a/src/en/overlay/rtk-000-001.md +++ b/src/en/overlay/rtk-000-001.md @@ -43,30 +43,20 @@ pin: ###A quick and easy way to start driving motors on your Raspberry Pi ```python -##Simple motor script for the RTK-000-001 -import RPi.GPIO as GPIO -import time -#Set to broadcom pin numbers -GPIO.setmode(GPIO.BCM) +from gpiozero import RyanteckRobot +from time import sleep -#Motor 1 = Pins 17 and 18 -#Motor 2 = Pins 22 and 23 -GPIO.setup(17, GPIO.OUT) -GPIO.setup(18, GPIO.OUT) +robot = RyanteckRobot() -#Now loop forever turning one direction for 5 seconds, then the other -while (True): - #Sleep 1 second then turn 17 on - GPIO.output(18, 0) - time.sleep(1) - GPIO.output(17, 1); - time.sleep(5); - #And now the other way round - GPIO.output(17, 0) - time.sleep(1); - GPIO.output(18, 1); - time.sleep(5); - #And loop back around -#And final cleanup -GPIO.cleanup() +while True: + robot.forward() + sleep(5) + robot.left() + sleep(1) + robot.backward() + sleep(5) + robot.right() + sleep(1) + robot.stop() + sleep(1) ```