I didn't quite understand what you ment 232...
You said to reconstruct the code, but isn't my loop the way to show?
void loop(){
if (buttonNumber == 0 ) {
Serial.println("State0 High");
digitalWrite(pin0, HIGH);
} else {
Serial.println("State0 Low");
digitalWrite(pin0, LOW);
}
}
I did some minor changes, moved the int buttonNumber = 0; before setup,
But the code will not count. Tried to set the buttonNumber to 2, and then the next output worked, so it is just the counter that is giving me a hard time, the rest works..
const int pin0 = 6;
const int pin1 = 2;
const int pin2 = 3;
const int pin3 = 5;
const int button = 7;
int buttonState = 0;
int buttonNumber = 2;
void setup() {
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin0, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
buttonState = digitalRead(button);
if (buttonState == HIGH) {
buttonNumber++;
}
if (buttonNumber == 4)
buttonNumber = 1;
if (buttonNumber == 0) {
digitalWrite(pin0, HIGH);
} else {
digitalWrite(pin0, LOW);
}
if (buttonNumber == 1) {
digitalWrite(pin1, HIGH);
} else {
digitalWrite(pin1, LOW);
}
if (buttonNumber == 2) {
digitalWrite(pin2, HIGH);
} else {
digitalWrite(pin2, LOW);
}
if (buttonNumber == 3) {
digitalWrite(pin3, HIGH);
} else {
digitalWrite(pin3, LOW);
}
}