Last active
December 21, 2016 21:18
-
-
Save andrewpatterson3001/10b9541341038c7c07e538a5ae189c98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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