Literate CoffeeScript version of raspi_button example

This commit is contained in:
Andrew Stewart 2013-11-27 16:12:59 -08:00
parent b72638de53
commit 28a1a807d1
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
# Raspberry Pi - Button
For this example, we're going to toggle a LED every time a button is pressed.
Both of these devices will be hooked up to a Raspberry Pi.
Before you get started, make sure you have the `cylon-raspi` module installed.
First, let's import Cylon:
Cylon = require '../..'
With Cylon imported, we can now start defining our robot.
Cylon.robot
Our robot has one connection, to the Raspberry Pi the hardware will be running
on. For hardware, we're keeping it simple. A LED on pin 11, and a button on pin
7.
connection: { name: 'raspi', adaptor: 'raspi' }
devices: [
{name: 'led', driver: 'led', pin: 11},
{name: 'button', driver: 'button', pin: 7}
]
With the hardware defined, we can get to the work our robot will perform. And as
you can see, it's enormously complex:
work: (my) ->
my.button.on 'push', -> my.led.toggle()
Essentially, when the robot's button emits the 'push' event (when it's pressed),
the LED will be told to toggle.
And voila! We now have a basic light switch. All we need to do now is tell the
robot to start:
.start()