Here is the code and I have problem with the last if.. Till the last if, everything worked just fine. I mean. I wrote the code till the last if on the bottom of the code.. literally the last if
It says: 63:4:error: expected unqualified-if before if. exit status 1
It also appears smth red at digitalWrite(ledPin2, LOW); What is the solution?
const int buttonPin1 = 5; // the number of the pushbutton pin
const int buttonPin2 = 4;
const int buttonPin3 = 3;
const int buttonPin4 = 2;
const int ledPin1 = 10; // the number of the LED pin
const int ledPin3 = 12;
const int ledPin2 = 11;
const int ledPin4 = 13;
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin4, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(ledPin1, INPUT);
pinMode(ledPin3, INPUT);
pinMode(ledPin2, INPUT);
pinMode(ledPin4, INPUT);
}
void loop()
{
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
// turn LED on:
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin3, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin3, LOW);
}
if (buttonState2 == HIGH) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin4, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin4, LOW);
}
if (buttonState3 == HIGH)
do {
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin3, HIGH);
}
while (buttonState4 == LOW);
}
if (buttonState4 == HIGH)
do {
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin3, LOW);
while (buttonState4 == HIGH)
;
}
Aucun commentaire:
Enregistrer un commentaire