Simple Traffic Light Arduino Problem?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a simple problem involving C programming for my arduino. The problem consists of programming a traffic light but I am getting the following error in relation to my brackets:
sketch_feb28a.ino:32:1: error: expected unqualified-id before '{' token
Error compiling.
I am fairly new to programming so it may be a simple issue. Thanks for the help. This is my entire code:
int greenlight = 1;
int amberlight = 2;
int redlight = 3;
int greenman = 4;
int waitlight = 5;
int redman = 6;
int pushbutton = 0;
void setup ()
{
pinMode(greenlight, OUTPUT);
pinMode(amberlight, OUTPUT);
pinMode(redlight, OUTPUT);
pinMode(greenman, OUTPUT);
pinMode(waitlight, OUTPUT);
pinMode(redman, OUTPUT);
pinMode(pushbutton, INPUT);
digitalWrite(pushbutton, HIGH);
digitalWrite(greenlight, HIGH);
digitalWrite(redman, HIGH);
}
void loop(){
pushbutton = digitalRead(pushbutton);
if (pushbutton == HIGH);
digitalWrite(greenlight, HIGH);
digitalWrite(redman, HIGH);
}
{
else
{
digitalWrite(greenlight, LOW);
digitalWrite(amberlight HIGH);
digitalWrite(waitlight, HIGH);
delay(3000)
digitalWrite(amberlight, LOW);
digitalWrite(redlight, HIGH);
digitalWrite(greenman, HIGH);
digitalWrite(waitlight, Low);
delay(10000)
digitalWrite(redlight, LOW);
digitalWrite(greenman, LOW);
digitalWrite(redman, HIGH);
digitalWrite(amberlight, HIGH);
delay(3000)
digitalWrite(amberlight, LOW);
digitalWrite(greenlight, HIGH);
}
0 commentaires
Réponses (1)
Abhishek GS
le 2 Mar 2015
Hi Kevin,
The above error is because you are trying to write some code after the void loop (). There is an issue with the flower braces that you have used. The void loop () code should ideally look like :
void loop(){
pushbutton = digitalRead(pushbutton);
if (pushbutton == HIGH)
{
digitalWrite(greenlight, HIGH);
digitalWrite(redman, HIGH);
}
else
{
digitalWrite(greenlight, LOW);
digitalWrite(amberlight HIGH);
digitalWrite(waitlight, HIGH);
delay(3000)
digitalWrite(amberlight, LOW);
digitalWrite(redlight, HIGH);
digitalWrite(greenman, HIGH);
digitalWrite(waitlight, Low);
delay(10000)
digitalWrite(redlight, LOW);
digitalWrite(greenman, LOW);
digitalWrite(redman, HIGH);
digitalWrite(amberlight, HIGH);
delay(3000)
digitalWrite(amberlight, LOW);
digitalWrite(greenlight, HIGH);
}
}
There is also an extra semicolon in your code at the end of 'if' statement which I have removed.
0 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!