Spark Core - Blink

For this example, we're going to connect to a Spark Core and make the LED on pin D7 blink on a 1-second interval. Before we start, make sure you've got the cylon-spark module installed.

Additionally, you'll need the Tinker firmware running on your Spark Core. If you've set your Spark Core up with the Tinker app, you should still have Tinker on your Core. Otherwise, load the firmware up via Spark's Build tool, or with the provided cylon spark upload command.

First, let's make sure to load the Cylon module:

var Cylon = require('cylon');

After we've got that done, we can start defining our robot:

Cylon.robot({

We'll have a singular connection to a Spark Core, using the previously-mentioned cylon-spark module. We'll also have one device, the LED on pin D7.

  connections: {
    spark: {
      adaptor: 'spark',
      accessToken: '[YOUR_ACCESS_TOKEN]',
      deviceId: '[YOUR_DEVICE_ID]'
    }
  },

  devices: {
    led: { driver: 'led', pin: 'D7' }
  },

Those are all the components for our robot, so next we'll define the work. All we're going to do for this example is tell the LED to toggle every second.

  work: function(my) {
    every((1).second(), my.led.toggle);
  }

And with all those pieces in place, we can tell the robot to get started:

}).start();