Reputation: 379
The code is below
// 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();
}
When i try to compile, it fails and error message is just "Error Compiling" and no reference to which line the error is coming from. But upon debugging i found the error to be in the delay line of the runTraffic() method. When i comment the line, the code compiles but it doesn't otherwise. But the delay works fine on other codes of mine.
What might be wrong with it?
Upvotes: 0
Views: 59
Reputation: 133
There's lot of people have same problems with same IDE (probably that version is unstable). I used the 1.6.4 to compile and no problem appear.
My advice is to unistall your Arduino IDE version (1.6.3) and install the 1.6.4 or something older and more stable.
Here you can download it and try which IDE works for you.
For now, i don't suggest the 1.6.5 (I've never tried it) but it could be a good candidate.
Upvotes: 1