Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var raspi = require('raspi-io');
var five = require('johnny-five');
var board = new five.Board({
io: new raspi()
});
// Initialize the board
board.on('ready', function () {
var Motor1A = 'P1-16';
var Motor1B = 'P1-18';
var Motor1E = 'P1-22';
var Motor2A = 'P1-23';
var Motor2B = 'P1-21';
var Motor2E = 'P1-19';
// Normalize and store in vars
var p16 = new five.Pin(Motor1A);
var p18 = new five.Pin(Motor1B);
var p22 = new five.Pin(Motor1E);
var p23 = new five.Pin(Motor2A);
var p21 = new five.Pin(Motor2B);
var p19 = new five.Pin(Motor2E);
// Set pin outputs
p16.high();
p18.low();
p22.high();
setTimeout(function(){
p22.low();
return;
},2000)
// Read a pin value
// console.log(board.pins[board.normalize('P1-7')].value); // outputs "1"
});
1420337323024 Device(s) RaspberryPi-IO
1420337323184 Connected RaspberryPi-IO
1420337323189 Repl Initialized
>>
/home/pi/projects/robot/node_modules/raspi-io/lib/index.js:284
throw new Error('Cannot digitalRead from pin "' + pin + '" unless it is
^
Error: Cannot digitalRead from pin "4" unless it is in INPUT mode
at Raspi.Object.defineProperty.value [as digitalRead] (/home/pi/projects/robot/node_modules/raspi-io/lib/index.js:284:13)
at new Pin (/home/pi/projects/robot/node_modules/johnny-five/lib/pin.js:122:25)
at Board.<anonymous> (/home/pi/projects/robot/start.js:20:13)
at Board.emit (events.js:95:17)
at Board.broadcast (/home/pi/projects/robot/node_modules/johnny-five/lib/board.js:423:8)
at Board.<anonymous> (/home/pi/projects/robot/node_modules/johnny-five/lib/board.js:325:21)
at Raspi.g (events.js:180:16)
at Raspi.emit (events.js:92:17)
at /home/pi/projects/robot/node_modules/raspi-io/lib/index.js:205:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.