Something simple - Flash the D0 LED

So, can someone walk me through this like I’m 5? I’m trying to compile the flash LED example here. I have two files open: thermostat.ino and application.cpp. thermostat.ino is blank and from what I understand is a needed file. My spark is named “thermostat”. the application.cpp file hes the example code in it:

// Program to blink an LED connected to pin D0
// of the Spark Core.

// We name pin D0 as led
int led = D0;

// This routine runs only once upon reset
void setup()
{
  // Initialize D0 pin as output
  pinMode(led, OUTPUT);
}

// This routine loops forever
void loop()
{
  digitalWrite(led, HIGH);   // Turn ON the LED
  delay(1000);               // Wait for 1000mS = 1 second
  digitalWrite(led, LOW);    // Turn OFF the LED
  delay(1000);               // Wait for 1 second
}

When I try and compile in the cloud I get the errors:

application.cpp:5:11: error: 'D0' was not declared in this scope
int led = D0; 
^
application.cpp: In function 'void setup()':
application.cpp:11:16: error: 'OUTPUT' was not declared in this scope
pinMode(led, OUTPUT); 
^
application.cpp:11:22: error: 'pinMode' was not declared in this scope
pinMode(led, OUTPUT); 
^
application.cpp: In function 'void loop()':
application.cpp:17:21: error: 'HIGH' was not declared in this scope
digitalWrite(led, HIGH); // Turn ON the LED 
^
application.cpp:17:25: error: 'digitalWrite' was not declared in this scope
digitalWrite(led, HIGH); // Turn ON the LED 
^
application.cpp:18:13: error: 'delay' was not declared in this scope
delay(1000); // Wait for 1000mS = 1 second 
^
application.cpp:19:21: error: 'LOW' was not declared in this scope
digitalWrite(led, LOW); // Turn OFF the LED 
^
make: *** [application.o] Error 1

Error: Could not compile. Please review your code.

What am I doing wrong? Thanks in advance for any help.

You need to add

#include "application.h"

to any cpp files or h files that need to access the Wiring language symbols, such as the pins and functions.

The name of this include may change in the future.

Sweet. That worked. I changed the pin to D7 and now I have it blinking the LED on the core itself. On to bigger and better things now.

Thanks bko.

1 Like

Okay, wait, before closing this out. How do I reflash tinker via the WebIDE?

So there are a bunch of ways to get Tinker back on your core. You can do a factory reset but you will have to reenter your credentials. You can also easily reflash it from the command line. But from the web IDE I don’t know of a super easy way.

What I would do is grab the compile-server2 branch of application.cpp from github here:

And cut and paste that into the webIDE.