Getting Started With Espruino

Written by Ben Wendt

I was excited yesterday to see that my Espruino, which I backed on Kick Starter, had arrived in the mail. Espruino is micro controller that is controlled via JavaScript. I’ve long wanted to experiment with micro controllers, having visions of working with arduinos or a raspberry pi, but the JavaScript control combined with the reasonable price tipped the scale in favour of Espruino.

my new Espruino

There is an excellent Quick Start Guide on the Espruino site that got me started in a flash. You can control the LED lights on the board by calling things like digitalWrite(LED1, 1).

There are three LED variables, so I decided to write an interval to loop through them:

var state = 0,
    interval = setInterval(function() {
      state = (state + 1) %3;
      digitalWrite(LED1, 0);
      digitalWrite(LED2, 0);
      digitalWrite(LED3, 0);
      switch (state) {
        case 0:
          digitalWrite(LED1, 1);
          break;
        case 1:
          digitalWrite(LED2, 1);
          break;
        case 2:
          digitalWrite(LED3, 1);
          break;
      }
    }, 50);

And here it is in action:

And here is code to turn on and off LED1 when BTN1 is pressed:

var on = false;
setWatch(function(e) {
  on = !on;

  digitalWrite(LED1, on);
}, A1, { repeat: true, edge: "falling" });