我是新的Arduino,我正在尝试构建交互式交通信号灯。此代码未能编译。请帮忙。Arduino上的交互式交通灯
int rPin = 12;
int yPin = 11;
int gPin = 10;
int r1Pin = 9;
int g2Pin = 8;
int button = 2;
int crossTime = 5000;
unsigned long changeTime;
void setup()
{
pinMode (rPin, OUTPUT);
pinMode (yPin, OUTPUT);
pinMode (gPin, OUTPUT);
pinMode (r1Pin , OUTPUT);
pinMode (g2Pin, OUTPUT);
pinMode (button , INPUT);
digitalWrite (gPin ,HIGH) ;
digitalWrite (r1Pin , HIGH);
}
void loop()
{
int state = digitalRead (button);
if (state == HIGH && (millis() - changetime) > 5000))
{
changeLights();
}
}
void chngeLight()
{
digitalWrite (gPin , LOW);
digitalWrite (yPin, HIGH);
delay (2000);
digitalWrite (yPin, LOW);
digitalWrite (rPin , HIGH);
delay(crossTime) ;
for (int x=0; x<10 , x++);
{
digitalWrite (g2Pin , HIGH);
delay (250);
digitalWrite (g2Pin , LOW);
delay (250);
}
digitalWrite (g2Pin , HIGH);
delay (500) ;
digitalWrite (yPin , HIGH);
digitalWrite (rPin , LOW);
delay (2000);
digitalWrite (yPin , LOW);
digitalWrite (gPin , HIGH);
changeTime = millis();
}
我唯一的问题是在void循环中。作为函数,Arduino编译器不接受changeLights。所以我创建了一个新的unsigned long,叫做“changeLights”,但它仍然不起作用。
Here is the link to screenshot of the image。
'所以我创建了一个新的无符号长整型称为“changeLights” - 为什么要这样做?看起来你想调用chngeLight(),而是调用不存在的函数changeLights()来代替。不要猜测;如果你在编程中不理解某些东西,那就逻辑地理解它。 –