首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >延迟()行不允许我的Arduino代码运行

延迟()行不允许我的Arduino代码运行
EN

Stack Overflow用户
提问于 2015-09-18 05:42:02
回答 1查看 50关注 0票数 0

代码如下

代码语言:javascript
复制
// 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()方法的延迟线上。当我注释这一行时,代码会编译,但不会编译。但是,这种延迟对我的其他代码很有效。

它可能有什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-18 13:03:24

很多人对同一个IDE都有同样的问题(可能那个版本是不稳定的)。我使用1.6.4编译,没有出现任何问题。

我的建议是统一所有Arduino IDE版本(1.6.3),并安装1.6.4或更老、更稳定的版本。

这里 --您可以下载它并尝试使用哪个IDE对您工作。

目前,我不建议使用1.6.5 (我从未尝试过),但它可能是一个很好的候选人。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32644623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档