User Manual
38
2. Here write two main functions/modules including light following calibration and light following
in the main program.
Subflow of Light Follower Calibration Function
We need to configure three light-sensitive components separately, so we set three lists to store
the values in A0, A1, and A2 collected for multiple times. Then pick out the minimum values,
which are the ouput analog values in the brightest conditions.
Since the light source we use is much brighter than the ambient light, we should take the
output values in the brightest conditions as reference.
Besides, we should set a threshold value - when the gap between the collected value of the
light source and that of the environment is beyond the threshold, trigger the value switching
to 0 or 1. Here we use [0,0,0] to represent the three photoresistors’ status when they are not
triggered. "0" will become "1" when the value detected of the corresponding photoresistor is
higher than the threshold. Thus we can set the related action of the car according to the
three-element list.
If there is light detected, the car will move and follow it; if there is no light detected, the car
will stop temporarily and keep turning to detect in a circle.
Subflow of Light Following Function
Calibrate
Check light
following
function
Start
Keyboard
Interrupt
Y
End
N
Calibratio
n function
Light
following
subfuncti
on
Calibration
function
Create lists for
collected values
Car runs in a circle
to collect light
values in different
directions
Store groups of
collected value in
the lists
Take the min
values of each
sensor as
reference
Upload trigger
threshold values to
parameters of
class library
Four wheels back
to standby