Page 123 - TCS ICT Book 8
P. 123
The City School 2021-2022
Bumble-Pi Programming
Enter the following code in Python IDLE and save the file name as SRC
# importing the libraries
from Bluetooth import *
import RPi.GPIO as GPIO
# Addressing the GPIO Pins as per Pi Shield configuration
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(16,GPIO.OUT) Programming Robots & Single-Board Computers
# Creating variables for motor functionality
MotorL1 = 21
MotorL2 = 18
enA = 20
MotorR1 = 26
MotorR2 = 12
enB = 19
# initializing the output pins
GPIO.setup(MotorL1,GPIO.OUT)
GPIO.setup(MotorL2,GPIO.OUT)
GPIO.setup(enA,GPIO.OUT)
GPIO.setup(MotorR1,GPIO.OUT)
GPIO.setup(MotorR2,GPIO.OUT)
GPIO.setup(enB,GPIO.OUT)
GPIO.output(MotorL1,False)
GPIO.output(MotorL2,False)
GPIO.output(MotorR1,False)
GPIO.output(MotorR2,False)
#setting up the speed of motors
p=GPIO.PWM(enA,1000)
p.start(75)
q=GPIO.PWM(enB,1000)
q.start(75)
123

