Discussion in "Project Addition or Changes" started by    cuteguy570    Jan 24, 2010.
Sun Jan 24 2010, 12:32 am
#1
I need to write a program that repeatedly reads the value on Port1[4]. When the switch is pressed, a binary 1 will be present on Port1[4]. The program should detect the low-to-high transition and turn on the LED. When the switch is released the program should detect the high-to-low transition but not do anything. When the switch is pressed again, it should turn the LED off. In essence, your program should poll the switch and toggle the LED every time it is pressed.
Sun Jan 24 2010, 04:15 pm
#2
what is the problem?
Sun Jan 24 2010, 11:47 pm
#3
I don't know what theory behind polling switches is can anyone explain to me. I also don't know how to write the code in C for doing what especially the part where the switch should keep track of what previous state it is in as based on that toggle the LED
Mon Jan 25 2010, 12:13 am
#4


I need to write a program that repeatedly reads the value on Port1[4]. When the switch is pressed, a binary 1 will be present on Port1[4].

cuteguy570


Well you do understand the theory of polling, because you just described it

How you implement the logic of your problem depends on your style of programming
You could go this way.

Create a variable to record the state of the bit you are testing
Save the state of the bit.

Now loop...
Read the port.
Is the bit the same as that stored ?
If yes.. do nothing start the loop again.
If no.. it has changed
Save the new state of the bit.
If it is now high toggle the led
If low, do nothing
start the loop again.

I'll leave the details of toggling the LED to you



[ Edited Mon Jan 25 2010, 12:14 am ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am