代码在
之下// initialize lights and sensors and valueHolders
int redN = 13;
int yellowN = 12;
int greenN = 11;
const int sensorN = A0;
int analogValueN = 0;
int redW = 10;
int yellowW = 9;
int greenW = 8;
const int sensorW = A1;
int analogValueW = 0;
int redS = 7;
int yellowS = 6;
int greenS = 5;
const int sensorS = A2;
int analogValueS = 0;
int redE = 4;
int yellowE = 3;
int greenE = 2;
const int sensorE = A3;
int analogValueE = 0;
//set thresholdValue;
const int threshValue = 200;
//initialize booleanSet for sectors
boolean bSet[] = {false, false, false, false};
void setBSet(){
if(analogValueN > threshValue) bSet[0] = false;
if(analogValueN < threshValue) bSet[0] = true;
if(analogValueW > threshValue) bSet[1] = false;
if(analogValueW < threshValue) bSet[1] = true;
if(analogValueS > threshValue) bSet[2] = false;
if(analogValueS < threshValue) bSet[2] = true;
if(analogValueE > threshValue) bSet[3] = false;
if(analogValueE < threshValue) bSet[3] = true;
// if (analogValueN > threshValue){
// bSet[0] = false;
// } else {
// bSet[0] = true;
// }
}
//setup outputs
void start(){
pinMode(redN, OUTPUT);
pinMode(yellowN, OUTPUT);
pinMode(greenN, OUTPUT);
analogValueN = analogRead(sensorN);
pinMode(redW, OUTPUT );
pinMode(yellowW, OUTPUT);
pinMode(greenW, OUTPUT);
analogValueW = analogRead(sensorW);
pinMode(redS, OUTPUT);
pinMode(yellowS, OUTPUT);
pinMode(greenS, OUTPUT);
analogValueS = analogRead(sensorS);
pinMode(redE, OUTPUT );
pinMode(yellowE, OUTPUT);
pinMode(greenE, OUTPUT);
analogValueE = analogRead(sensorE);
}
// set method for active sector
// ROS ==> red of sector
void active(int ROS){
//set sector as go
digitalWrite(ROS, LOW);
digitalWrite(ROS-1, LOW);
digitalWrite(ROS-2, HIGH);
Serial.println('Pin' + (ROS-2) + "Active High");
}
//set method for light action
void action(int ROS){
//set active for sector...
active(ROS);
//...and its complimentary sector
if (ROS>8){
active(ROS - 6);
} else {
active(ROS + 6);
}
}
void runTraffic(){
setBSet();
for(int i=0;i<4;i++){
if (bSet[i]){
action((3*i)+4);
// delay(8000);
}
}
}
void setup() {
// put your setup code here, to run once:
start();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
runTraffic();
}
当我尝试编译时,它失败并且错误消息只是“错误编译”并且没有引用错误来自哪一行。但是在调试时我发现错误在runTraffic()方法的延迟行中。当我评论该行时,代码会编译,但不会。但延迟在我的其他代码上工作正常。
它有什么问题?