# Wiimote GPIOZero code by Yasmin Bey from gpiozero import RyanteckRobot import cwiid, time robot = RyanteckRobot() button_delay = 0.01 print("Hold down buttons 1 and 2 to start the connection process!") time.sleep(1) try: wiimote = cwiid.Wiimote() except RuntimeError: print("Failed connection. Please re-run the program!") quit() print("Connection successful. Buttons will be active after 2 seconds") wiimote.rumble = 1 # This can be removed if you don't want the remote to rumble when connected! time.sleep(2) wiimote.rumble = 0 wiimote.rpt_mode = cwiid.RPT_BTN while True: buttons = wiimote.state["buttons"] speed = 0.7 # This can be altered between 0 and 1, dependent on requirements. if (buttons & cwiid.BTN_LEFT): robot.left(speed) if (buttons & cwiid.BTN_RIGHT): robot.right(speed)
import RPi.GPIO as GPIO from gpiozero import RyanteckRobot robot = RyanteckRobot() GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(21, GPIO.IN) # Left GPIO.setup(26, GPIO.IN) # Right while True: if GPIO.input(21) == GPIO.input(26): print("forward") robot.forward() if GPIO.input(21) != 0: print("left") robot.left() if GPIO.input(26) != 0: print("right") robot.right()
import RPi.GPIO as GPIO import time from gpiozero import RyanteckRobot robot = RyanteckRobot() GPIO.setmode(GPIO.BCM) TRIG = 24 #Change to match GPIO pins used ECHO = 25 GPIO.setup(TRIG, GPIO.OUT) GPIO.setup(ECHO, GPIO.IN) print("Measuring the distance!") while True: GPIO.output(TRIG, 0) time.sleep(2) # Wait for sensor to settle GPIO.output(TRIG, 1) # Sending out a signal time.sleep(0.00001) GPIO.output(TRIG, 0) while GPIO.input(ECHO) == 0: pulse_start = time.time() while GPIO.input(ECHO) == 1: pulse_end = time.time() pulse_length = pulse_end - pulse_start distance = pulse_length * 17150 print(distance) if distance >= 5:
import RPi.GPIO as GPIO import time from gpiozero import RyanteckRobot robot = RyanteckRobot() GPIO.setmode(GPIO.BCM) TRIG = 24 #Change to match GPIO pins used ECHO = 25 GPIO.setup(TRIG,GPIO.OUT) GPIO.setup(ECHO,GPIO.IN) print("Measuring the distance!") while True: GPIO.output(TRIG, 0) time.sleep(2) # Wait for sensor to settle GPIO.output(TRIG, 1) # Sending out a signal time.sleep(0.00001) GPIO.output(TRIG, 0) while GPIO.input(ECHO) == 0: pulse_start = time.time() while GPIO.input(ECHO) == 1: pulse_end = time.time() pulse_length = pulse_end - pulse_start distance = pulse_length * 17150