Code:
do
{ if (Button(&Switch_Port, Switch_Pin, Debounce_Time, 0)) {
if (!Switch) { LED = ~LED; }
while (!Switch); // Wait for release of the button } }
while(1); // Infinite Loop }
do
{ if (Button(&Switch_Port, Switch_Pin, Debounce_Time, 0)) {
if (!Switch) { LED = ~LED; }
while (!Switch); // Wait for release of the button } }
while(1); // Infinite Loop }
thanks for answering,It looks like the code bit you posted got truncated. No worries, as you posted the link.
LED, Switch_port,switch_pin,Debounce_time and Switch are defined earlier in the program. Switch_port is the port to which the switch is connected; Switch_pin is the specific pin debounce time is used in the library function "Bounce". Switch is the position/pin of the switch. LED is the position of the LED. The code bit operates as follows.
- Debounce the switch
- If the switch is pressed, ~Switch, toggle the state of the LED. Note that when the switch is pressed, it sends a 0 to the pin. Hence, we test for the inverse of switch.
- Wait for the switch to be released.
- Repeat (forever)
Any questions?
if (Button(&Switch_Port, Switch_Pin, Debounce_Time, 0))
by Duane Benson
by Aaron Carman
by Duane Benson
by Jake Hertz