Stehe wieder mal am Berg!
Hallo zusammen
Habe folgendes Sketch und verstehe nicht, warum das letzte "if" nicht greift.
if(buttonPresses >= 10)
{
digitalWrite(4, LOW);
buttonPresses = 0;
hier das ganze Sketch:
/*
* Counting presses
*/
int switchPin = 2; // switch is connected to pin 2
int val; // variable for reading the pin status
int buttonState; // variable to hold the button state
int buttonPresses = 0; // how many times the button has been pressed
void setup() {
pinMode(switchPin, INPUT); // Set the switch pin as input
Serial.begin(9600); // Set up serial communication at 9600bps
buttonState = digitalRead(switchPin); // read the initial state
}
void loop(){
val = digitalRead(switchPin); // read input value and store it in val
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
buttonPresses++; // increment the buttonPresses variable
Serial.print("Button has been pressed ");
Serial.print(buttonPresses);
Serial.println(" times");
delay(500);
if(buttonPresses <= 5)
{
digitalWrite(4, LOW);
if(buttonPresses >= 5)
{
digitalWrite(4, HIGH);
if(buttonPresses >= 10)
{
digitalWrite(4, LOW);
buttonPresses = 0;
}
}
}
}
}
buttonState = val; // save the new state in our variable
}