Hi
I think it's very simple problem.
I want a counter that's counts up from 0 to 3 and then Counts down from 3 to 0 then i push the button up or down.
I Think its wrong in the IF(….)
const int buttonPinup = 2; // the number of the pushbutton pin
const int buttonPindown = 3; // the number of the pushbutton pin
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int count = 0;
void setup() {
Serial.begin(115200);
pinMode(buttonPinup, INPUT);
pinMode(buttonPindown, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPinup);
buttonState2 = digitalRead(buttonPindown);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
if ( count >= 0 and count == 2 ); {
count = count +1;
delay(500);
Serial.println(count);
}
}
else if (buttonState2 == HIGH) {
if (count >= 0 and count <= 2); {
count = count -1;
delay(500);
Serial.println(count);
} }}