Remove Firmata examples

They live in hybridgroup/cylon-firmata now.
This commit is contained in:
Andrew Stewart 2014-03-06 11:51:31 -08:00
parent f3135bfd2c
commit 6d843f7097
24 changed files with 0 additions and 664 deletions

View File

@ -1,23 +0,0 @@
Cylon = require '../..'
Cylon.robot
connection:
name: 'arduino'
adaptor: 'firmata'
port: '/dev/ttyACM0'
device:
name: 'sensor'
driver: 'analogSensor'
pin: 0
upperLimit: 900
lowerLimit: 100
work: (my) ->
my.sensor.on 'upperLimit', (val) ->
console.log "Upper limit reached ===> #{val}"
my.sensor.on 'lowerLimit', (val) ->
console.log "Lower limit reached ===> #{val}"
.start()

View File

@ -1,28 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'arduino',
adaptor: 'firmata',
port: '/dev/ttyACM0'
},
device: {
name: 'sensor',
driver: 'analogSensor',
pin: 0,
upperLimit: 900,
lowerLimit: 100
},
work: function(my) {
my.sensor.on('upperLimit', function(val) {
console.log("Upper limit reached ===> " + val);
});
my.sensor.on('lowerLimit', function(val) {
console.log("Lower limit reached ===> " + val);
});
}
}).start();

View File

@ -1,47 +0,0 @@
# Analog Sensor
A quick example of using an Arduino's analog sensor with Cylon. The program will
log to the console when the sensor has hit it's upper and lower limits.
Before you run this program, make sure you have the `cylon-firmata` module
installed.
First, let's load up Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connection to our Arduino:
connection:
name: "arduino"
adaptor: "firmata"
port: "/dev/ttyACM0"
Now we can define the analog sensor we're going to use, along with it's upper
and lower limits:
device:
name: 'sensor'
driver: 'analogSensor'
pin: 0
upperLimit: 900
lowerLimit: 100
Now that Cylon knows about the necessary hardware we're going to be using, we'll
tell it what work we want to do:
work: (my) ->
my.sensor.on 'upperLimit', (val) ->
console.log "Upper limit reached: #{val}"
my.sensor.on 'lowerLimit', (val) ->
console.log "Lower limit reached: #{val}"
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -1,12 +0,0 @@
Cylon = require '../..'
# Initialize the robot
Cylon.robot
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
device: { name: 'led', driver: 'led', pin: 13 }
work: (my) ->
every 1.second(), -> my.led.toggle()
.start()

View File

@ -1,10 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: {name: 'led', driver: 'led', pin: 13},
work: function(my) {
every((1).seconds(), function() {my.led.toggle()});
}
}).start();

View File

@ -1,31 +0,0 @@
# Blink
For this very basic Cylon example, we're just going to hook up to an Arduino and
blink an LED on it with a one-second interval.
To get started, let's load up Cylon:
Cylon = require '../..'
With Cylon loaded, we can now define our basic robot.
Cylon.robot
Our robot has one connection, to an Arduino using the `cylon-firmata` adaptor:
connection: { name: "arduino", adaptor: "firmata", port: "/dev/ttyACM0" }
Our robot also only has one device (or at least only one we're concerned about),
an LED on pin 13.
device: { name: 'led', driver: 'led', pin: 13 }
Next, we'll define the robot's work, which will be toggling the LED every
second:
work: (my) ->
every 1.second(), -> my.led.toggle()
And that's all the parts of our robot. All that's left is to start it.
.start()

View File

@ -1,30 +0,0 @@
Cylon = require '../..'
Cylon.robot
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
device:
name: 'blinkm', driver: 'blinkm'
work: (my) ->
my.blinkm.on 'start', ->
my.blinkm.stopScript()
my.blinkm.getFirmware((version) ->
Logger.info "Started BlinkM version #{version}"
)
my.blinkm.goToRGB(0,0,0)
my.blinkm.getRGBColor((data) ->
console.log("Starting Color: #{ data }")
)
every 2.second(), () ->
my.blinkm.getRGBColor((data) ->
console.log("Current Color: #{ data }")
)
my.blinkm.fadeToRandomRGB(128, 128, 128)
.start()

View File

@ -1,30 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: { name: 'blinkm', driver: 'blinkm' },
work: function(my) {
my.blinkm.on('start', function() {
my.blinkm.stopScript();
my.blinkm.getFirmware(function(version) {
Logger.info("Started BlinkM version " + version);
});
my.blinkm.goToRGB(0,0,0);
my.blinkm.getRGBColor(function(data){
console.log("Starting Color: ", data)
});
every((2).second(), function() {
my.blinkm.getRGBColor(function(data){
console.log("Current Color: ", data);
});
my.blinkm.fadeToRandomRGB(128, 128, 128);
});
});
}
}).start();

View File

@ -1,64 +0,0 @@
# BlinkM
For this example, we're going to use the `cylon-firmata` module to blink a light
using BlinkM.
Before we start, make sure you've got the `cylon-firmata` module installed.
First, let's import Cylon:
Cylon = require '../..'
With Cylon imported, we can start defining our robot.
Cylon.robot
Our robot will be using an Arduino, and communicating over the Firmata protocol
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
And we'll have one device, a BlinkM led.
device:
name: 'blinkm', driver: 'blinkm'
We'll now set up our robot's work.
work: (my) ->
When the BlinkM sends the 'start' event, we'll set up our events
my.blinkm.on 'start', ->
We stop the default BlinkM's light script
my.blinkm.stopScript()
We'll request the BlinkM's version, and print that to the console
my.blinkm.getFirmware((version) ->
Logger.info "Started BlinkM version #{version}"
)
By default, we'll turn the LED off
my.blinkm.goToRGB(0,0,0)
We print the default starting color (in this case 0,0,0 since we turned the led off)
my.blinkm.getRGBColor((data) ->
console.log("Starting Color: #{ data }")
)
Now, every 2 seconds, we'll change the LED color to a random value:
every 2.second(), ->
my.blinkm.getRGBColor((data) ->
console.log("Current Color: #{ data }")
)
my.blinkm.fadeToRandomRGB(128, 128, 128)
Now that our robot knows what to do, let's get started:
.start()

View File

@ -1,15 +0,0 @@
Cylon = require('../..')
Cylon.robot
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
devices: [
{ name: 'led', driver: 'led', pin: 13 },
{ name: 'button', driver: 'button', pin: 2 }
]
work: (my) ->
my.button.on 'push', -> my.led.toggle()
.start()

View File

@ -1,16 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
devices: [
{ name: 'led', driver: 'led', pin: 13 },
{ name: 'button', driver: 'button', pin: 2 }
],
work: function(my) {
my.button.on('push', function() {
my.led.toggle();
});
}
}).start();

View File

@ -1,37 +0,0 @@
# Button
For this example, we're going to be connecting to an Arduino, and when a putton
on it's pressed, an LED will be toggled.
Before you start this example, make sure you've got the `cylon-firmata` module
installed.
We'll get started by importing the Cylon module:
Cylon = require '../..'
Now that we have Cylon imported, let's start making our robot:
Cylon.robot
Our robot will have a connection to an Arduino, and communicate with it via the
Firmata protocol:
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
This time, our robot will have two devices, an LED and a button:
devices: [
{ name: 'led', driver: 'led', pin: 13 },
{ name: 'button', driver: 'button', pin: 2 }
]
Our robot has very simple work, it will just toggle the LED whenever the button
sends the 'push' event:
work: (my) ->
my.button.on 'push', -> my.led.toggle()
And with all that done, we can start our robot:
.start()

View File

@ -1,16 +0,0 @@
Cylon = require '../..'
Cylon.robot
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
device: { name: 'led', driver: 'led', pin: 3 }
work: (my) ->
brightness = 0
fade = 5
every 0.05.seconds(), ->
brightness += fade
my.led.brightness(brightness)
fade = -fade if (brightness is 0) or (brightness is 255)
.start()

View File

@ -1,19 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: { name: 'led', driver: 'led', pin: 3 },
work: function(my) {
var brightness = 0;
var fade = 5;
every(0.05.seconds(), function() {
brightness += fade;
my.led.brightness(brightness);
if ((brightness === 0) || (brightness === 255)) {
fade = -fade;
}
});
}
}).start();

View File

@ -1,43 +0,0 @@
# LED Brightness
For this example, we'll be using an LED on an Arduino board, and modifying it's
brightness to make it fade in and out. Before we start, make sure you've got the
`cylon-arduino` module installed.
Let's start by importing Cylon:
Cylon = require '../..'
Once we've got that, we can start defining our robot:
Cylon.robot
We'll be using an Arduino, and communicating over the Firmata protocol. As well,
we'll let our robot know about the LED we'll be modifying, on pin #3 of the
Arduino.
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
device: { name: 'led', driver: 'led', pin: 3 }
Next up, we'll define our robot's work:
work: (my) ->
We'll set some variables here: brightness will represent the LED's brightness,
from 1-255, and 'fade' will be the brightness change on each tick.
brightness = 0
fade = 5
Every 50 milliseconds, we'll be incrementing the brightness by `fade`'s value,
setting the LED to that brightness, and reversing `fade`'s value if brightness
hits 0 or 255.
every 0.05.seconds(), ->
brightness += fade
my.led.brightness(brightness)
fade = -fade if (brightness is 0) or (brightness is 255)
And with that done, we can now start our robot.
.start()

View File

@ -1,17 +0,0 @@
Cylon = require '../..'
Cylon.robot
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
device: { name: 'motor', driver: 'motor', pin: 3 }
work: (my) ->
speed = 0
increment = 5
every 0.05.seconds(), ->
speed += increment
my.motor.speed(speed)
console.log "Current Speed: #{my.motor.currentSpeed() }"
increment = -increment if (speed is 0) or (speed is 255)
.start()

View File

@ -1,20 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: { name: 'motor', driver: 'motor', pin: 3 },
work: function(my) {
var speed = 0;
var increment = 5;
every(0.05.seconds(), function() {
speed += increment;
my.motor.speed(speed);
console.log("Current Speed: " + (my.motor.currentSpeed()));
if ((speed === 0) || (speed === 255)) { increment = -increment; }
});
}
}).start();

View File

@ -1,46 +0,0 @@
# Motor
For this example, similar in structure to the led_brightness example, we're
going to take an Arduino, and modify the speed of an attached motor such that it
continually speeds up and slows down.
Before we get started, make sure to have the `cylon-arduino` module installed.
First, let's require Cylon:
Cylon = require '../..'
Now we can start defining our robot:
Cylon.robot
We'll be connecting to an Ardunio, using the Firmata protocol, and a motor
attached to the Arduino on pin 3.
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
device: { name: 'motor', driver: 'motor', pin: 3 }
We'll start defining the work for our robot next:
work: (my) ->
We'll define variables to hold our motor's speed, and the rate at which that
speed will change:
speed = 0
increment = 5
Every fifty milliseconds, we'll increment the `speed`, set the motor to run at
that speed, and log the speed we're running at to the console. We'll also make
sure to change the increment if the speed is at the upper/lower bounds of the
values supported:
every 0.05.seconds(), ->
speed += increment
my.motor.speed(speed)
console.log "Current Speed: #{my.motor.currentSpeed() }"
increment = -increment if (speed is 0) or (speed is 255)
And with all that done, we can now start our robot:
.start()

View File

@ -1,16 +0,0 @@
Cylon = require '../..'
Cylon.robot
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
device:
name: 'mpl115a2', driver: 'mpl115a2'
work: (my) ->
my.mpl115a2.on 'start', ->
my.mpl115a2.getTemperature((data) ->
Logger.info "temperature #{data['temperature']}, pressure #{data['pressure']}"
)
.start()

View File

@ -1,15 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: { name: 'mpl115a2', driver: 'mpl115a2' },
work: function(my) {
my.mpl115a2.on('start', function() {
my.mpl115a2.getTemperature(function(data) {
Logger.info("temperature " + data['temperature'] + " pressure " + data['pressure']);
});
});
}
}).start();

View File

@ -1,31 +0,0 @@
# MPL115A2
First, let's import Cylon:
Cylon = require '../..'
Now that we have Cylon imported, we can start defining our robot
Cylon.robot
Let's define the connections and devices:
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
device:
name: 'mpl115a2', driver: 'mpl115a2'
Now that Cylon knows about the necessary hardware we're going to be using, we'll
tell it what work we want to do:
work: (my) ->
my.mpl115a2.on 'start', ->
my.mpl115a2.getTemperature((data) ->
Logger.info "temperature #{data['temperature']}, pressure #{data['pressure']}"
)
Now that our robot knows what work to do, and the work it will be doing that
hardware with, we can start it:
.start()

View File

@ -1,26 +0,0 @@
Cylon = require '../..'
Cylon.robot
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
# when declaring the servo driver you can add an optional range param
# (defaults to min: 30 max 150). This param sets limits for the angle,
# so sot he servo can't be damaged if it cannot move in the full 0-180
# range, most servos are not capable of this.
device:
name: 'servo', driver: 'servo', pin: 3, range: { min: 30, max: 150}
work: (my) ->
angle = 30
increment = 40
every 1.seconds(), ->
angle += increment
my.servo.angle angle
console.log "Current Angle: #{my.servo.currentAngle()}"
increment = -increment if (angle is 30) or (angle is 150)
.start()

View File

@ -1,20 +0,0 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: { name: 'servo', driver: 'servo', pin: 3, range: { min: 30, max: 150 } },
work: function(my) {
var angle = 30;
var increment = 40;
every(1..seconds(), function() {
angle += increment;
my.servo.angle(angle);
console.log("Current Angle: " + (my.servo.currentAngle()));
if ((angle === 30) || (angle === 150)) { increment = -increment; }
});
}
}).start();

View File

@ -1,52 +0,0 @@
# Servo
For this example, similar in structure to the led_brightness example, we're
going to take an Arduino, and modify the angle of an attached servo such that
it's continually turning back and forth.
Before we get started, make sure to have the `cylon-arduino` module installed.
First, let's require Cylon:
Cylon = require '../..'
Now we can start defining our robot:
Cylon.robot
We'll be connecting to an Ardunio, using the Firmata protocol, and a servo
attached to the Arduino on pin 3. We have the option to pass an extra 'range'
param to the device, this param sets the min and max angle values. By default
this is set to min: 30, max: 150 to prevent damaging the servo when giving it
an angle outside the range it can cover.
connection:
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
device:
name: 'servo', driver: 'servo', pin: 3, range: { min: 30, max: 150}
We'll start defining the work for our robot next:
work: (my) ->
We'll define variables to hold our servo's angle, and the rate at which that
angle will change:
angle = 30
increment = 40
Every second, we'll increment the `angle`, set the servo to run at that angle,
and log the angle we're running at to the console. We'll also make sure to
change the increment if the angle is at the upper/lower bounds of the values
supported:
every 1.seconds(), ->
angle += increment
my.servo.angle(angle)
console.log "Current angle: #{my.servo.currentAngle() }"
increment = -increment if (angle is 30) or (angle is 150)
And with all that done, we can now start our robot:
.start()