turn on a LED when the button is pressed and let it on
until the button is pressed again
*/
int pinButton = 8;
int LED = 2;
int stateLED = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 200;
void setup() {
pinMode(pinButton, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
stateButton = digitalRead(pinButton);
if(stateButton == HIGH && previous == LOW && millis() - time > debounce) {
if(stateLED == HIGH){
stateLED = LOW;
} else {
stateLED = HIGH;
}
time = millis();
}
digitalWrite(LED, stateLED);
previous == stateButton;
}
if(stateButton == HIGH && previous == LOW && millis() - time > debounce)
i don`t get this line of code and what & implementation in this code
i have some knowledge with c
UKHeliBob:
I guess that you copied this code from a Web page and it included HTML characters such as & as a substitute for &
the place i copied this from is using a code format so i dont think HTML got to it
but i will try that edit
but can you explain please
what this -time debounce about ?
Ma-Mi:
the place i copied this from is using a code format so i dont think HTML got to it
Dude, HTML most certainly got into it.
Ma-Mi:
but can you explain please
what this -time debounce about ?
Any mechanical switch has "bounce" - it doen't just go on and off. When you operate the switch, it will go on-off a couple of times because of its mechanical elasticity. To deal with this, when a switch changes state sketches will usually ignore any further changes on the switch for a short interval of time - a few milliseconds or so.