I'm working on an application using node.js and arduino.
I'm using the johnny-five framework and have uploaded the StandardFirmata sketch to my arduino, which has an arcade controller connected to it on pins 2, 3, 4 and 5.
this is my implementation:
var five = require('johnny-five');
var board
board = new five.Board();
board.on('ready', function(){
console.log('board is ready');
this.pinMode(2, five.Pin.INPUT);
this.pinMode(3, five.Pin.INPUT);
this.pinMode(4, five.Pin.INPUT);
this.pinMode(5, five.Pin.INPUT);
this.digitalRead(2, function(value) {
if(value === 0)
{
console.log('up');
}
});
this.digitalRead(3, function(value) {
if(value === 0) {
console.log('right');
}
});
this.digitalRead(4, function(value) {
if(value === 0) {
console.log('left');
}
});
this.digitalRead(5, function(value) {
if(value === 0) {
console.log('down');
}
});
});
Now the problem is when I pull my arcade controller down or up it logs 'up' or 'down' multiple times.. it can be 5 times, it can be 10 times. What am I doing wrong?