delay() 行不允许我的 Arduino 代码 运行

delay() line not allowing my Arduino code to run

代码如下

// 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();  
}

当我尝试编译时,它失败了,错误消息只是 "Error Compiling",没有提到错误来自哪一行。但是在调试时我发现错误在 runTraffic() 方法的延迟线上。当我注释该行时,代码会编译,但不会编译。但是延迟在我的其他代码上运行良好。

它可能有什么问题?

有很多人遇到同样的问题IDE(可能那个版本不稳定)。 我用1.6.4编译没出现问题

我的建议是卸载您的 Arduino IDE 版本 (1.6.3) 并安装 1.6.4 或更旧且更稳定的版本。

Here 你可以下载它并试试哪个 IDE 适合你。

目前,我不建议 1.6.5(我从未尝试过),但它可能是一个不错的选择。