beriberikix / micro_five

µFive - a microcontroller port of Johnny-Five written in C
Apache License 2.0
2 stars 0 forks source link

Reverse-implement LED demo #1

Open beriberikix opened 9 years ago

beriberikix commented 9 years ago

The hello world of hardware is blinking an LED. In johnny-five, that equates to:

// Blink an LED
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var led = new five.Led(13);
  led.blink();
});

Instead of boiling the ocean implementing every API, I should start with an analogous main.c and reverse-implement the supporting libraries. Besides being pragmatic, it allows me to focus on the devexp of the end user without dwelling on the implementation details. My first take:

#include "micro-five.h"

int main()
{
  Micro-Five five;
  Board board;

  Board_Init(&five, &board); //feels clunky

  while(1) {
    //todo event handler, LED init, LED blink
  }

  return 0; // never reached
}
beriberikix commented 9 years ago

The demo needs to achieve a series of steps: