Simple Traffic Light Arduino Problem?

3 ビュー (過去 30 日間)
Kevin
Kevin 2015 年 3 月 1 日
回答済み: Abhishek GS 2015 年 3 月 2 日
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);
}

回答 (1 件)

Abhishek GS
Abhishek GS 2015 年 3 月 2 日
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.

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by