LED Traffic Adviser Code Issue

I am working on making a LED traffic adviser. When I try to compile the below code it gives me the following error messages. I got the code from Electronics!: Arduino Traffic Adviser. Any help would be appreciated.

Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"

arduino_traffic__aviser.ino: In function 'void setup()':
arduino_traffic__aviser:22: error: 'F' was not declared in this scope
arduino_traffic__aviser.ino: In function 'void loop()':
arduino_traffic__aviser:67: error: 'F' was not declared in this scope
arduino_traffic__aviser:93: error: 'F' was not declared in this scope
arduino_traffic__aviser:118: error: 'F' was not declared in this scope
arduino_traffic__aviser:143: error: 'F' was not declared in this scope
arduino_traffic__aviser:164: error: 'F' was not declared in this scope
arduino_traffic__aviser:205: error: 'F' was not declared in this scope
'F' was not declared in this scope

#define A 1     //LED1
#define B 2     //LED2
#define C 3     //LED3
#define D 4     //LED4
#define E 5     //LED5
#define F 6     //LED6
#define G 7     //LED7
#define H 8     //LED8
#define I 9     //LED9
#define J 10    //LED10
int button = 12;//button
int val;        //button read status
int state;      //hold
int presses = 0;//# of presses on button
int mode = 0;   //current mode
void setup(){
  pinMode(A,OUTPUT);
  pinMode(B,OUTPUT);
  pinMode(C,OUTPUT);
  pinMode(D,OUTPUT);
  pinMode(E,OUTPUT);
  pinMode(F,OUTPUT);
  pinMode(G,OUTPUT);
  pinMode(H,OUTPUT);
  pinMode(I,OUTPUT);
  pinMode(J,OUTPUT);
  pinMode(button,INPUT);
state = digitalRead(button);
}
void loop(){ 
val = digitalRead(button);    //sets val to the state of the button press
delay(15);                    //debounce multiple button presses
if (val != state){            //compares button press to current state 
if (val == LOW){ 
if (mode == 0){                    //if mode is zero and button was pressed, set mode to 1
mode = 1; 
} else { 
if (mode == 1){                    //increment mode to 2 
mode = 2;
} else { 
if (mode == 2){                    //increment mode to 3
mode = 3;
} else {
if (mode == 3){                    //increment mode to 4
mode = 4;
} else {
if (mode == 4){                    //increment mode to 5
mode = 5;
} else {
if (mode == 5){                    //increment mode to 0
mode = 0;
}
}
}
}
} 
} 
}
state = val; 
} 
if (mode == 0){                     //ALL OFF//mode 0 turns all LEDs off
digitalWrite(A,LOW); //LED
digitalWrite(B,LOW); //LED
digitalWrite(C,LOW); //LED
digitalWrite(D,LOW); //LED
digitalWrite(E,LOW); //LED
digitalWrite(F,LOW); //LED
digitalWrite(G,LOW); //LED
digitalWrite(H,LOW); //LED
digitalWrite(I,LOW); //LED
digitalWrite(J,LOW); //LED
}
if (mode == 1){                     // |* * * * * |~| * * * * *|R
byte count = 0;                     //set counter
byte number = 0; while (count < 3){ //count loop 1
digitalWrite(A,HIGH);
digitalWrite(C,HIGH);
digitalWrite(E,HIGH);
digitalWrite(G,HIGH);
digitalWrite(I,HIGH);
delay(70);
digitalWrite(A,LOW);
digitalWrite(C,LOW);
digitalWrite(E,LOW);
digitalWrite(G,LOW);
digitalWrite(I,LOW);
delay(70);
count++;
}
while (number < 3){                 //count loop 2
digitalWrite(B,HIGH);
digitalWrite(D,HIGH);
digitalWrite(F,HIGH);
digitalWrite(H,HIGH);
digitalWrite(J,HIGH);
delay(70);
digitalWrite(B,LOW);
digitalWrite(D,LOW);
digitalWrite(F,LOW);
digitalWrite(H,LOW);
digitalWrite(J,LOW);
delay(70);
number++;
}
}
if (mode == 2){                     // |*****     |~|     *****|R
digitalWrite(A,HIGH);
digitalWrite(B,HIGH);
digitalWrite(C,HIGH);
digitalWrite(D,HIGH);
digitalWrite(E,HIGH);
delay(150);
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,LOW);
digitalWrite(F,HIGH);
digitalWrite(G,HIGH);
digitalWrite(H,HIGH);
digitalWrite(I,HIGH);
digitalWrite(J,HIGH);
delay(150);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
digitalWrite(H,LOW);
digitalWrite(I,LOW);
digitalWrite(J,LOW);
}
if (mode == 3){                    // |<--------*|R
digitalWrite(J,HIGH);
delay(150);
digitalWrite(J,LOW);
digitalWrite(I,HIGH);
delay(150);
digitalWrite(I,LOW);
digitalWrite(H,HIGH);
delay(150);
digitalWrite(H,LOW);
digitalWrite(G,HIGH);
delay(150);
digitalWrite(G,LOW);
digitalWrite(F,HIGH);
delay(150);
digitalWrite(F,LOW);
digitalWrite(E,HIGH);
delay(150);
digitalWrite(E,LOW);
digitalWrite(D,HIGH);
delay(150);
digitalWrite(D,LOW);
digitalWrite(C,HIGH);
delay(150);
digitalWrite(C,LOW);
digitalWrite(B,HIGH);
delay(150);
digitalWrite(B,LOW);
digitalWrite(A,HIGH);
delay(150);
digitalWrite(A,LOW);
}
if (mode == 4){                    // |<---**--->|
digitalWrite(E,HIGH);
digitalWrite(F,HIGH);
delay(150);
digitalWrite(E,LOW);
digitalWrite(F,LOW);
digitalWrite(D,HIGH);
digitalWrite(G,HIGH);
delay(150);
digitalWrite(D,LOW);
digitalWrite(G,LOW);
digitalWrite(C,HIGH);
digitalWrite(H,HIGH);
delay(150);
digitalWrite(C,LOW);
digitalWrite(H,LOW);
digitalWrite(B,HIGH);
digitalWrite(I,HIGH);
delay(150);
digitalWrite(B,LOW);
digitalWrite(I,LOW);
digitalWrite(A,HIGH);
digitalWrite(J,HIGH);
delay(150);
digitalWrite(A,LOW);
digitalWrite(J,LOW);
}
if (mode == 5){                    // |*-------->|R
digitalWrite(A,HIGH);
delay(150);
digitalWrite(A,LOW);
digitalWrite(B,HIGH);
delay(150);
digitalWrite(B,LOW);
digitalWrite(C,HIGH);
delay(150);
digitalWrite(C,LOW);
digitalWrite(D,HIGH);
delay(150);
digitalWrite(D,LOW);
digitalWrite(E,HIGH);
delay(150);
digitalWrite(E,LOW);
digitalWrite(F,HIGH);
delay(150);
digitalWrite(F,LOW);
digitalWrite(G,HIGH);
delay(150);
digitalWrite(G,LOW);
digitalWrite(H,HIGH);
delay(150);
digitalWrite(H,LOW);
digitalWrite(I,HIGH);
delay(150);
digitalWrite(I,LOW);
digitalWrite(J,HIGH);
delay(150);
digitalWrite(J,LOW);
}
}

It looks like there's a collision between your definition of macro F and the IDE's definition of macro F in WString.h. If I delete the line

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

from WString.h, the sketch compiles just fine. It also compiles if I substitute something else for F. Finally, if I change the macro definitions to constant declarations, like this
const int A = 1;   //LED1it compiles without error.

That was an experiment. I don't recommend that you modify the IDE, largely because there are other easier ways to get around this problem. It's certainly doable, but I'd think that you'd avoid it if a simple alternative, like using some other symbol, would make it unnecessary. Besides, later, you might wish that you had the IDE's F macro available.

That said, it sure looks like you're doing this the hard way. There's no compelling reason to use a symbol for a pin number that never changes, except to make it easy to change the pin assignments in some later revision to the code. If you don't anticipate changing pin assignments, it might be simpler to simply refer directly to the pin numbers. If the ability to easily change pin numbers is important to you, you might consider generating an array of pin numbers, and referencing pin numbers indirectly. I think that you could collapse this program into a lot fewer lines using an array rather than referencing pin numbers directly. For example, here's a sketch using your scheme, replacing macro definitions with constant declarations, that will light each LED in turn:

const int A = 1;     //LED1
const int B = 2;     //LED2
const int C = 3;     //LED3
const int D = 4;     //LED4
const int E = 5;     //LED5
const int F = 6;     //LED6
const int G = 7;     //LED7
const int H = 8;     //LED8
const int I = 9;     //LED9
const int J = 10;    //LED10

void setup() {
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(H, OUTPUT);
  pinMode(I, OUTPUT);
  pinMode(J, OUTPUT);
}

void loop() {
  digitalWrite(A, HIGH);
  delay(100);
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  delay(100);
  digitalWrite(B, LOW);
  digitalWrite(C, HIGH);
  delay(100);
  digitalWrite(C, LOW);
  digitalWrite(D, HIGH);
  delay(100);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  delay(100);
  digitalWrite(E, LOW);
  digitalWrite(F, HIGH);
  delay(100);
  digitalWrite(F, LOW);
  digitalWrite(G, HIGH);
  delay(100);
  digitalWrite(G, LOW);
  digitalWrite(H, HIGH);
  delay(100);
  digitalWrite(H, LOW);
  digitalWrite(I, HIGH);
  delay(100);
  digitalWrite(I, LOW);
  digitalWrite(J, HIGH);
  delay(100);
  digitalWrite(J, LOW);
}

Code compiles, but it's otherwise untested. Here's a sketch that does the same thing, using an array of pin numbers:

int pinNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int pin;

void setup() {
  for (int i = 0; i < 10; i++) {
    pinMode(pinNumbers[i], OUTPUT);
  }
}

void loop() {
  digitalWrite(pinNumbers[pin], HIGH);
  delay(100);
  digitalWrite(pinNumbers[pin], LOW);
  pin++;
  if (pin >= 10) pin = 0;
}
  • a lot simpler. Again, code compiles, but is otherwise untested. Doing more complicated things with the LEDs will generally be a whole lot easier with arrays, if you're sweeping one way or the other, or otherwise have some symmetry to exploit. If you don't yet know how to manage arrays, you'll certainly want to learn that skill.

Finally, I note that you're using pin 1 for an LED output. Pin 1 is used for serial communication; if you want to be able to print from your sketch, you shouldn't use pin 1 as an output. When you enable Serial with Serial.begin(), the function of pin 1 will be hijacked by the serial port, and you'll get unexpected results. Serial.print()'ing is useful for troubleshooting, so I'd recommend that you design your project so that you can initiate communication with the serial port without having to modify both your code and your hardware.

I appreciate your response. I like the looks of using the array of pins will be easier to you. I try it out thanks.

I made this simple semaphore code, perhaps you will broaden its functions, Greetings

void setup() {
// semaforo 1 y semaforo 2:
pinMode(13,OUTPUT);//1 verde:
pinMode(12,OUTPUT);//1 amarillo:
pinMode(8,OUTPUT);//1 rojo:
pinMode(7,OUTPUT);//2 rojo:
pinMode(4,OUTPUT);//2 amarillo:
pinMode(2,OUTPUT);//2 verde:
}

void loop() {
// secuencia de semaforo de 5 segundos cada uno:
digitalWrite(13,HIGH);//1 verde:
digitalWrite(7,HIGH);//2 rojo:
delay(5000);
digitalWrite(13,LOW);//1 verde:
digitalWrite(12,HIGH);//1 amarillo:
delay(1000);
digitalWrite(12,LOW);//1 amarillo:
digitalWrite(8,HIGH);//1 rojo:
delay(400);
digitalWrite(7,LOW);//2 rojo:
digitalWrite(4,HIGH);//2 amarillo:
delay(1000);
digitalWrite(4,LOW);//2 amarillo:
digitalWrite(2,HIGH);//2 verde:
delay(5000);
digitalWrite(2,LOW);//2 verde:
digitalWrite(4,HIGH);//2 amarillo:
delay(1000);
digitalWrite(4,LOW);//2 amarillo:
digitalWrite(7,HIGH);//1 rojo:
delay(400);
digitalWrite(8,LOW);//2 rojo:
digitalWrite(12,HIGH);//1 amarillo:
delay(1000);
digitalWrite(12,LOW);//1 amarillo:
digitalWrite(13,HIGH);//1 verde:
}

One of the patterns in this is an advisory: