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 #89 background imageLoading...
Page #89 background image
Need support? support.freenove.com
85
Chapter 4 Light tracing Car
www.freenove.com
The code is 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
import time
from Motor import *
from ADC import *
class Light:
def run(self):
try:
self.adc=Adc()
self.PWM=Motor()
self.PWM.setMotorModel(0,0,0,0)
while True:
L = self.adc.recvADC(0)
R = self.adc.recvADC(1)
if L < 2.99 and R < 2.99 :
self.PWM.setMotorModel(600,600,600,600)
elif abs(L-R)<0.15:
self.PWM.setMotorModel(0,0,0,0)
elif L > 3 or R > 3:
if L > R :
self.PWM.setMotorModel(-1200,-1200,1400,1400)
elif R > L :
self.PWM.setMotorModel(1400,1400,-1200,-1200)
except KeyboardInterrupt:
led_Car.PWM.setMotorModel(0,0,0,0)
if __name__=='__main__':
print ('Program is starting ... ')
led_Car=Light()
led_Car.run()
Result analysis
When the voltages of left and right photoresistor are less than 2.99V, the car move forward straightly. And
when one of the voltages is greater than 3V:
If the left voltage is greater than the right, the car turns left.
If the right voltage is greater than the left, the car turns right.
You can change the judgment of the program to achieve the result you want, according to the light intensity
of the environment.

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