Debounce it,debounce it...i like to debounce it...
Now iam very happy.It works very well with momentary and latching swichtes.I have already thought that the delay can only be a problem solution and not the final solution.Thank you very mutch-now i can debouncing.
This is the code I used for it:
int LightPin = 12;
int lightState = LOW;
int buttonState = 0;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup()
{
pinMode(LightPin, OUTPUT);
pinMode(BUTTON_PIN_1, INPUT);
digitalWrite(LightPin, lightState);
void loop() {
int reading = digitalRead(BUTTON_PIN_1);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
lightState = !lightState;
}
}
}
digitalWrite(LightPin, lightState);
lastButtonState = reading;
Maybe someone can use this code for his own projekt...
Thank you very mutch for your help Wotever,again and again and again...