I recently started my kids on Arduino development. Nothing fancy, the idea for now is to take an old decorative halloween skull and put LEDs into the eye sockets.
Arduino was new to all of us, so we started small, using one of the basic example files included in the Arduino IDE 1.6.6 called "Blink". It worked great. It was actually a pleasant surprise seeing just how polished this all was, and it was good to have the big hurdle out of the way – we had a working development environment in place, and were able to upload files to a working Arduino Uno.
Next we tried a file that was a little closer to the fade-in/fade-out effect we wanted to achieve with the skull. Here we copied the code from the Sunfounder website and pasted it into a new sketch in the Arduino IDE.
This one would not verify or upload, returning this error:
'lt' was not declared in this scope
regarding this line:
for (int a=0; a<=255;a++) //loop from 0 to 255
It looked like this:
Comparing that line to the original code copied from the Sunfounder site quickly revealed the problem. The Sunfounder code looked like this...
for (int a=0; a<=255;a++) //loop from 0 to 255
But when pasted into the Arduino IDE for Mac it looked more like this...
for (int a=0; a&/lt;=255;a++) //loop from 0 to 255
During the copy/paste the less than character was replaced with
for (int a=255; a>=0;a--) //loop from 255 down to 0
Became something more like this...
for (int a=255; a&/gt;=0;a--) //loop from 255 down to 0
In both cases I said "something like" because the relevant section of the code appears here in the color red to make it stand out, and because the CMS for this website won't allow for the exact character strings that showed in the Arduino IDE.
As a result the IDE was seeing "lt" and "gt" as new variables that had not been declared (hence the error message 'lt' was not declared in this scope)
Fortunately the solution is simple – replacing the modified code with standard greater than/less than characters made the code work perfectly.
It also seems that you can copy the code here, from this site, and paste it directly into the Arduino IDE for Mac and it will work with no encoding issues:
const int ledPin = 9; // the pin that the LED is attached to
void setup ()
{
pinMode(ledPin, OUTPUT); // declare pin 9 to be an output:
}
void loop()
{
for (int a=0; a<=255;a++) //loop from 0 to 255
{
analogWrite(ledPin, a); // set the brightness of pin 9:
delay(8); //wait for 8 microseconds
}
for (int a=255; a>=0;a--) //loop from 255 down to 0
{
analogWrite(ledPin, a); // set the brightness of pin 9:
delay(8); //wait for 8 microseconds
}
delay(800); //wait for 800 microseconds
}
This was actually a great opportunity to teach the boys a little about debugging code. We knew that we had an Arduino board and IDE that worked, we had seen it with the first (and more basic) Blink program.
That meant there was something wrong with the code for our program. We tried another, more basic, program from Sunfounder that did work, so we could assume that their code was generally good.
The next step was to look at the line flagged as an error in the Arduino IDE and compare it very carefully to the original code on the Sunfounder site, revealing the problem and the solution.