EasyManuals Logo

Freenove 4WD Smart Car Board for Raspberry Pi User Manual

Default Icon
132 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #93 background imageLoading...
Page #93 background image
Need support? support.freenove.com
89
Chapter 6 Infrared Line Tracking Car
www.freenove.com
The code is as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
from Motor import *
import RPi.GPIO as GPIO
IR01 = 14
IR02 = 15
IR03 = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(IR01,GPIO.IN)
GPIO.setup(IR02,GPIO.IN)
GPIO.setup(IR03,GPIO.IN)
class Line_Tracking:
def run(self):
while True:
self.LMR=0x00
if GPIO.input(IR01)==True:
self.LMR=(self.LMR | 4)
if GPIO.input(IR02)==True:
self.LMR=(self.LMR | 2)
if GPIO.input(IR03)==True:
self.LMR=(self.LMR | 1)
if self.LMR==2:
PWM.setMotorModel(800,800,800,800)
elif self.LMR==4:
PWM.setMotorModel(-1500,-1500,2500,2500)
elif self.LMR==6:
PWM.setMotorModel(-2000,-2000,4000,4000)
elif self.LMR==1:
PWM.setMotorModel(2500,2500,-1500,-1500)
elif self.LMR==3:
PWM.setMotorModel(4000,4000,-2000,-2000)
elif self.LMR==7:
pass
infrared=Line_Tracking()
# Main program logic follows:
if __name__ == '__main__':
print ('Program is starting ... ')
try:
infrared.run()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be
executed.
PWM.setMotorModel(0,0,0,0)

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove 4WD Smart Car Board for Raspberry Pi and is the answer not in the manual?

Freenove 4WD Smart Car Board for Raspberry Pi Specifications

General IconGeneral
BrandFreenove
Model4WD Smart Car Board for Raspberry Pi
CategoryMicrocontrollers
LanguageEnglish