我是新的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()來代替。不要猜測;如果你在編程中不理解某些東西,那就邏輯地理解它。 –