An archive of community.esquilo.io as of Saturday January 26, 2019.

Trouble running the blink example

andywander

I have cut and pasted the 'native Squirrel" exampll to blink the LED, and when I run the code, it gives me a "%Runtime error [the index 'LED_BUILTIN' does not exist]".

The code i am trying is:

//
// Squirrel nut to blink an LED (native API)
//
led <- GPIO(LED_BUILTIN); // LED built into board
count <- 0; // blink counter
serial <- UART(0); // initialize the serial port

led.output(); // sets the digital pin as output

while (true)
{
led.high(); // sets the LED on
delay(1000); // waits for a second
led.low(); // sets the LED off
delay(1000); // waits for a second
serial.writestr(count+"\r\n");// print the counter
count++; // advance the counter
}

If I replace "LED_BUILTIN" with "46", it works.

I did some searching through the docs, and cant really find where or how LED_BUILTIN needs to be defined.....

Also, if I add the line :LED_BUILTIN <- 46" right above the "led <- GPIO(LED_BUILTIN); " line, then it works-is the example in error, or is there a set of definitions including "LED_BUILTIN" that I should be using/loading/accessing somehow?

patrick

LED_BUILTIN is a globally defined constant in Arduino, so we define it when the Arduino library is enabled in the system menu.

The way you did it is correct. Another, slightly more efficient, way is to define is as a constant, like so:

const LED_BUILTIN = 46;
andywander

I'm having trouble finding the system menu....... question

Ahh! Found it-I never expected a pulldown menu over on the right side.....

patrick

Glad you found it. One more thing: if you aren't planning to use the Arduino library for other things, it's best to leave it disabled, as each lib uses some RAM. If you only want the define, doing it yourself is the way to go.

redxeth

Just to point out that as of EOS 0.3 these are now under the Squirrel menu (also under the 'hamburger' menu to the right). You can also programmatically load libraries using require().