Half size line follower

Steps 1-3
LEDs and Button


Step 1

This step will show you the various LEDs that are on the half-sized line follower.
The picture below shows the 3 LEDs that can be controlled.
It also shows the button, which can be used by your program

 
  The LEDs have been given names you can use in your program.

  The numbers in brackets are used to choose
  which Pi Pico input/output pin we are talking about.

This is the python code you need to set up the names of the 3 LEDs.
do this at the start of your program
But what is a "Pin"?
At the very start of your program you must "import" the definition of a Pin from the "machine"
You will be using time delays , so you need to import time as well:


This is the python code for turning on an LED.
Do this in your program, when you want it to go on.

And for turning off


This while loop turns them on and off repeatedly


So here is the complete program:
Step 2

This step will show you the line sensors for the half-sized line follower.
The picture below shows the Trigger LEDs that are needed for line sensing.
It also shows the two light sensors, which detect the line.

 
  The 2 LEDs are both controlled from the same Pin.

The sensor with no name on the right is the stop sensor
we will come to that later



This is the python code you need to set up the names of the LED and sensors.
do this at the start of your program
But what is an "ADC"?
At the very start of your program you must "import" the definition of an ADC from the "machine"
This is in addition to the Pin, and time.
An ADC is an Analogue to Digital Convertor.


This is the python code for turning on the trigger illumination LED.
Do this in your program, when you want it to go on.

Step 3

This step will show you how to read the button using Python


This is the python code you need to set up the Pin to read the button.
do this at the start of your program
Why "Pin.PULL_DOWN"?
We need a pull down because of how it has been wired.
The input is connected to the power voltage only when the button is pressed.
If it is not pressed, it's not connected to anything,
and can pick up static electricity causing it to spuriously trigger
The Pull down forces it to zero volts if the button is not pressed.

This is the python code for checking if the button is pressed.
Do this in your program, when you want to see if it pressed or not.

Here's the python code for lighting a LED if the button is pressed.


If you put this in a loop, it will check continuously
But you will need an "else" clause to switch off the LED when the button is not pressed.
So here is the complete program:
notice it doesnt turn off

© Copyright St Albans Robots