//Please Comment Liberally First, write a program to turn on only one LED and th
ID: 638936 • Letter: #
Question
//Please Comment Liberally
First, write a program to turn on only one LED and then turn off the same LED.
Improve the program by making the LED blink.
The next part of the lab is to read the input switches, one from the Walk push button and the other indicating a car at the crossing. As switches are mechanical objects, some de-bounce time (dead time) will also be placed in the program. You will control each LED with one switch; as long as the switch is active the respective LED is ON and when switch is inactive, the corresponding LED is OFF. Then, the LED will be made to blink as long as switch is ON.
Finally, you will write a little traffic light controller where the green or red stays ON while the corresponding switch is ON. If more than one switch is activated, then ON the red light.
LED's simulate the traffic lights and the switches simulate the walk push button and the car presence sensor at a crossroad.
Input and Output Assignment
P3.1 pin 19 active Low Input, SW1 (Walk push button)
P3.2 pin 18 active Low Input, SW2 (Car present at the crossing))
P1.3 pin 9 Output active High, Red LED
P1.1 pin 11 Output, active High, Green LED
The term active low indicates that the micro-controller must be programmed in a manner such that the switch is made or activated when P3.2 or P3.1 read low logic.
Correspondingly the term active high means that to activate an LED the corresponding
microcontroller pin must generate high logic. The port directional register defines the state (input or output) of the micro-controller I/O lines.
Explanation / Answer
Toggle LED using Pushbutton
Lets get into next project which is even more interesting. Here we are going to toggle an LED using a push button switch. Toggle means to change state. Our objective here is turn LED ON with first push button press and turn LED OFF with next push button press. This cycle of ON and OFF should continue with each push button press. The same circuit diagram given above is enough to do this project as we are not manipulating any hardware connection. We just need to change our software (sketch) to change the behavior of this circuit.
Here is the sketch to toggle an LED using push button switch.
I used a
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.