Skip to content

Instantly share code, notes, and snippets.

@andrewpatterson3001
Last active December 21, 2016 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewpatterson3001/10b9541341038c7c07e538a5ae189c98 to your computer and use it in GitHub Desktop.
Save andrewpatterson3001/10b9541341038c7c07e538a5ae189c98 to your computer and use it in GitHub Desktop.
const myDeviceId = '*'
const myAccessKey = '*'
const myAccessSecret = '*'
let five = require('johnny-five');
let raspi = require('raspi-io');
let Device = require('losant-mqtt').Device;
let StepperWiringPi = require("stepper-wiringpi");
// Construct Losant device.
let device = new Device({
id: myDeviceId,
key: myAccessKey,
secret: myAccessSecret
});
// Connect the device to Losant.
device.connect();
let board = new five.Board({
io: new raspi()
});
board.on('ready', function() {
// Hook the command event listener.
device.on('command', function(command) {
if(command.name === 'spinMotor') {
let motor = StepperWiringPi.setup(2048, 17, 18, 27, 22);
let steps = command.payload.steps || 10240
motor.setSpeed(15);
motor.step(steps);
motor.stop();
device.sendState({spinsCompleted:(steps/2048)})
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment