Now that we have tested the motors, servos, camera, and LEDs, it's time to modify the code into classes to give it more unity. In this section, we will make T.A.R.A.S dance.
Modifying the robot car Python code
Move the wheels
Let's start by encapsulating the code that moves the wheels on the robot car:
- Open up Thonny from Application Menu | Programming | Thonny Python IDE
- Click on the New icon to create a new file
- Type the following code into the file:
from gpiozero import Robot
from time import sleep
class RobotWheels:
robot = Robot(left=(5, 6), right=(22, 27))
def __init__(self):
pass
def move_forward(self):
self.robot.forward(0.2)
def move_backwards(self):
self...