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) if (buttons & cwiid.BTN_UP): robot.forward(speed) if (buttons & cwiid.BTN_DOWN): robot.backward(speed) if (buttons & cwiid.BTN_B): robot.stop()
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()