Skip to content

Instantly share code, notes, and snippets.

@motiooon
Created January 4, 2015 00:59
Show Gist options
  • Save motiooon/eb5be4823d3e3a133c50 to your computer and use it in GitHub Desktop.
Save motiooon/eb5be4823d3e3a133c50 to your computer and use it in GitHub Desktop.
robot
var raspi = require('raspi-io');
var board = new raspi();
// Read a pin value
console.log(board.pins[board.normalize('P1-7')].value);
// 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';
// Motor 1
board.pinMode(Motor1A, board.MODES.OUTPUT);
board.pinMode(Motor1B, board.MODES.OUTPUT);
board.pinMode(Motor1E, board.MODES.OUTPUT);
// Motor 2
board.pinMode(Motor2A, board.MODES.OUTPUT);
board.pinMode(Motor2B, board.MODES.OUTPUT);
board.pinMode(Motor2E, board.MODES.OUTPUT);
// Normalize and store in vars
var p16 = board.normalize(Motor1A);
var p18 = board.normalize(Motor1B);
var p22 = board.normalize(Motor1E);
var p23 = board.normalize(Motor2A);
var p21 = board.normalize(Motor2B);
var p19 = board.normalize(Motor2E);
// Set pin 7's output to logic high
board.pins[p16].value = board.HIGH;
board.pins[p18].value = board.LOW;
board.pins[p22].value = board.HIGH;
setTimeout(function(){
board.pins[p22].value = board.LOW;
return;
},2000)
// Read a pin value
// console.log(board.pins[board.normalize('P1-7')].value); // outputs "1"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment