Arduino IDE "'lt' was not declared in this scope" Error

Oct 08, 2015

 

Be aware of a small encoding issue and the resulting "lt/gt was not declared in this scope" error when pasting into the excellent Arduino IDE for Mac.

 

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:

arudino-ide-mac-encloding-error.jpg

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
}

 

Good Learning Opportunity

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.



Tags: Arduino

Related Content

Arduino Project – LED Skull 5: Adding Subroutines/Functions

This code was a great opportunity to introduce the idea of subroutines and returning values from subroutines (functions) with an Arduino Uno.

Fire Breathing Arduino Pumpkin With IR Remote Control

A small change to another fire-breathing Arduino pumpkin replaces a proximity sensor with an small IR remote control.

Arduino Project – LED Skull 4: Add HC-SR04 Ultrasonic Module

The next step in creating a spookier skull was to add an HC-SR04 ultrasonic module that would fire the LEDs based on proximity to a viewer.

Arduino Project – LED Skull Eyes 3: Adding a Second Eye

The next step involves adding a second "eye" (LED), independent of the first, to maintain the wink effect.

Arduino Project – LED Skull Eyes 2: Wink Effect

More variables and the addition of a "wink" effect to make the LED skull eyes seem more animated.

Arduino Project – LED Skull Eyes 1

The first part of this project (adding LED "eyes" to a skull, driven by an Arduino UNO) was about teaching code optimization, abstraction and commenting.

Category List


Tag List


Tag Cloud



Archive