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

DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am
ChrisLub
Tue Apr 23 2024, 05:21 pm