Arduino Sketch compiling error, I can't find the error?

Thread Starter

SamR

Joined Mar 19, 2019
1,294
I have been working on this bit of coding example for a couple of days and it has me stumped. I can't find the error. The strange thing is it actually loads and runs!?!? I'm using UNO clone board with ATMEGA328P dip chip and the standard, fully updated Arduino IDE. Genuino UNO board is recognized by the IDE.

Sketch code:
//Digital Traffic Signal

int stop=6;
int yield=2;
int go=6;

void setup() {
Serial.begin(9600);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}

void loop() {
stoplight(stop);
golight(go);
yieldlight(yield);
}

void stoplight(int time) {
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
Serial.println("Light mode: Stop");
delay(time * 100);
}

void yieldlight(int time) {
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
Serial.println("Light mode: Yield");
delay(time * 2);
}

void golight(int time) {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
Serial.println("Light mode: Go");
delay(time * 100);
}


Compiling Errors: (edited to remove user name and whitespace)
24H14.1:4:5: error: 'int yield' redeclared as different kind of symbol
int yield=2;
^~~~~
In file included from C:\Users\AppData\Local\Temp\arduino_build_183363\sketch\24H14.1.ino.cpp:1:0:
C:\Users\SDocuments\ArduinoData\packages\arduino\hardware\avr\1.8.1\cores\arduino/Arduino.h:38:6: note: previous declaration 'void yield()'
void yield(void);
^~~~~
C:\Users\Documents\Arduino\ArduinoPrgrammingIn24Hrs\24H14.1\24H14.1.ino: In function 'void loop()':
C:\Users\Documents\Arduino\ArduinoPrgrammingIn24Hrs\24H14.1\24H14.1.ino:20:19: warning: invalid conversion from 'void (*)()' to 'int' [-fpermissive]
yieldlight(yield);
^
C:\Users\Documents\Arduino\ArduinoPrgrammingIn24Hrs\24H14.1\24H14.1.ino:31:6: note: initializing argument 1 of 'void yieldlight(int)'
void yieldlight(int time) {
^~~~~~~~~~
exit status 1
'int yield' redeclared as different kind of symbol
 

Thread Starter

SamR

Joined Mar 19, 2019
1,294
This is because yield is a built in function. Uae a different name.
I suspected that but when I went to the Arduino Reference site I couldn't find yield? How is it used? A link would be appreciated. Thx for the heads-up Albert!

Bingo! Capitalized it and no error!
 

Thread Starter

SamR

Joined Mar 19, 2019
1,294
Ooops I'm blind... Hmmm... That's strange. It's used in a library that I haven't called? OK, got it and stored in my faulty memory hopefully for future use.
 
Top