Create simple library IDE

Hi,

I know it is a basic stuff but I’m trying to create a simple library using the new IDE . I’m following Arduino steps but I’m not able to adapt it to spark.

blinkaled.ino

// This #include statement was automatically added by the Spark IDE.
#include "blink.h"

Blink blinke(13);
void setup() {}
void loop(){
  blinke.parpadeo(); 
}

blink.h

#ifndef blink_h
#define blink_h

#define ARDUINO_H
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>

class Blink{
public:
   Blink(int pin);
   void parpadeo(); 
private:
    int _pin;
}:
#endif

blink.cpp

#define ARDUINO_H
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>


#include "blink.h"
 
Blink::Blink(int pin)
{
   pinMode(pin, OUTPUT);
  _pin = pin;
}
 
void Blink::parpadeo()
{
  digitalWrite(_pin, HIGH);   //enciende
  delay(1000);                   //1s
  digitalWrite(_pin, LOW);    //apaga
  delay(1000);                   //1s
 }

What I am doing wrong?

Hi @clex

Two quick things: blink.h needs to have an

#include "application.h"

to get it to compile using digitalWrite and pinMode. You probably don’t need the other includes if you have this one.

Your sketch uses pin 13 which is A3 on the Spark core–you would be better off to use the defined names D0-D7 and A0-A7, since the numbers are not the same between Spark and Arduino.

Good luck!

@clex

This may be helpful: Updated Spark Core Pinouts by @BDub https://community.spark.io/t/one-awsome-pinout-diagram-for-spark-core-located/3361/12?u=spydrop

And, for Arduino UNO if you don’t have it yet: http://www.pighixxx.com/pgdev/Temp/Arduino-Pinoutv2_2.png

Thanks guys for your answer. I applied the changes you proposed but still doesn’t work. Here is my current code:

blinkaled.ino

// This #include statement was automatically added by the Spark IDE.
#include "blink.h"

Blink blinke(D7);
void setup() {}
void loop(){
  blinke.parpadeo(); 
}

blink.h

#ifndef blink_h
#define blink_h

#define ARDUINO_H
#include "application.h"

class Blink{
public:
   Blink(int pin);
   void parpadeo(); 
private:
    int _pin;
}
#endif

blink.cpp

#define ARDUINO_H
#include "application.h"


#include "blink.h"

Blink::Blink(int pin)
{
   pinMode(pin, OUTPUT);
  _pin = pin;
}

void Blink::parpadeo()
{
  digitalWrite(_pin, HIGH);   //enciende
  delay(1000);                   //1s
  digitalWrite(_pin, LOW);    //apaga
  delay(1000);                   //1s
 }

And I’m getting the next error:

In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:31,
from blink.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
In file included from blink.cpp:5:0:
blink.h:7:1: error: new types may not be defined in a return type
blink.h:7:1: note: (perhaps a semicolon is missing after the definition of 'Blink')
blink.cpp:7:21: error: return type specification for constructor invalid
make: *** [blink.o] Error 1

The error message is right–your class definition in blink.h needs a semi-colon after the last curly-brace:

#ifndef blink_h
#define blink_h

#define ARDUINO_H
#include "application.h"

class Blink{
public:
   Blink(int pin);
   void parpadeo(); 
private:
    int _pin;
};
#endif

Yes!! Now is working! Thanks @bko

How are you issuing commands to your spark core ? Java / API / http / php / curl ?