need explanation of this little code step by step

djsfantasi

Joined Apr 11, 2010
9,156
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?
 

Thread Starter

ect_09

Joined May 6, 2012
180
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?
thanks for answering,
can you explain this line???
Code:
if (Button(&Switch_Port, Switch_Pin, Debounce_Time, 0))
 

djsfantasi

Joined Apr 11, 2010
9,156
In the link you provided, there is a detailed description. "Bounce" is a library function; supplied as part if the language for the specific purpose of debouncing the switch. It is represented by the first line of my explanation.
 
Last edited:
Top