Here's what the GPIO connector looks like.

Click for fullsize image.
The pins labels can be seen in the silkscreen: GPIO - G3, G2, and G1 from the bottom right. Power - GND and 3.3V at the bottom left.
Note in the code below that there is a special tessel module, included via node (require("tessel")). Thisallows you to interact with the GPIO on the Tessel.
Here I use the GPIO property (tessel.port['GPIO']) to access G1, G2 and G3.
(function(){ "use strict"; var tessel = require("tessel"); var gpio = tessel.port['GPIO']; var Button = require("../tessel/button"); var Led = require("../tessel/led"); var led = Led.create(gpio.pin['G2']); var flasher = Led.createFlasher(led); var leftBtn = Button.create(gpio.pin['G1'], ["down", "up"]); var rightBtn = Button.create(gpio.pin['G3'], ["up", "down"]); leftBtn.onChange = function(evt){ console.log("left button: ", evt.detail); if ("down" === evt.detail) { console.log("Do something with left button..."); } }; leftBtn.listen(); rightBtn.onChange = function(evt){ console.log("right button: ", evt.detail); if ("down" === evt.detail){ flasher.fast(); } else { flasher.slow(); } }; rightBtn.listen(); })();
I built a daughter board to plug into the GPIO connector. The board contains two buttons, one of the buttons has an LED built into it.

Here are the two other modules I that this one includes, just for reference. They are actually the ones that do all the real work.
Look at all that beautiful Javascript, being used to control a microcontroller. All is well with the world! Of course, I'm not sure how long the code will execute before it generates some kind of memory fault!
No comments:
Post a Comment