Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JoyStick library #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,53 @@ Increment position from 0 to 180.

Instruct the servo to immediately go to a position from 0 to 180.

##joystick

There are 4 events to handle ups/downs on X and Y axis.

````javascript
var joystick = new arduino.JoyStick({
board: board
});

joystick.on('y-up',function(amount,real_volts){
console.log('Y Increasing, amount:',amount,real_volts);
});

joystick.on('y-down',function(amount,real_volts){
console.log('Y Decreasing , amount:',amount,real_volts);
});

joystick.on('x-up',function(amount,real_volts){
console.log('X Increasing , amount:',amount,real_volts);
});

joystick.on('x-down',function(amount,real_volts){
console.log('X Decreasing , amount:',amount,real_volts);
});

````
VRYPin is by default A0, VRXPin is by default A1, but they can be specified in the options:

````javascript
var joystick = new arduino.JoyStick({
board: board,
vrypin: 'A0',
vrxpin: 'A1'
});

````
Each event returns 2 parameters: "amount" that is a percentage and "real_voltage":

````javascript

joystick.on('x-down',function(amount,real_volts){
console.log('X Decreasing , amount:',amount,real_volts);
});

````


##motor

##potentiometer
Expand Down
286 changes: 286 additions & 0 deletions examples/7seg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
var arduino = require('../');
var board = new arduino.Board({
debug: true
});



// segment in led display
var sA = new arduino.Led({
board: board,
pin: 8
});

var sB = new arduino.Led({
board: board,
pin: 9
});
var sC = new arduino.Led({
board: board,
pin: 2
});
var sD = new arduino.Led({
board: board,
pin: 3
});
var sE = new arduino.Led({
board: board,
pin: 4
});
var dot = new arduino.Led({
board: board,
pin: 5
});
var sG = new arduino.Led({
board: board,
pin: 6
});

var sF = new arduino.Led({
board: board,
pin: 7
});

function shownumber(number){
switch(number){
case 0:
sA.on(); // -
sB.on(); // |
sG.on(); // |
sF.off(); // -
sE.on(); // |
sC.on(); // |
sD.on(); // -
dot.off();// .
break;
case 1:
sA.off(); // -
sB.on(); // |
sG.off(); // |
sF.off(); // -
sE.off(); // |
sC.on(); // |
sD.off(); // -
dot.off();// .
break;
case 2:
sA.on(); // -
sB.on(); // |
sG.off(); // |
sF.on(); // -
sE.on(); // |
sC.off(); // |
sD.on(); // -
dot.off();// .
break;
case 3:
sA.on(); // -
sB.on(); // |
sG.off(); // |
sF.on(); // -
sE.off(); // |
sC.on(); // |
sD.on(); // -
dot.off();// .
break;
case 4:
sA.off(); // -
sB.on(); // |
sG.on(); // |
sF.on(); // -
sE.off(); // |
sC.on(); // |
sD.off(); // -
dot.off();// .
break;
case 5:
sA.on(); // -
sB.off(); // |
sG.on(); // |
sF.on(); // -
sE.off(); // |
sC.on(); // |
sD.on(); // -
dot.off();// .
break;
case 6:
sA.off(); // -
sB.off(); // |
sG.on(); // |
sF.on(); // -
sE.on(); // |
sC.on(); // |
sD.on(); // -
dot.off();// .
break;
case 7:
sA.on(); // -
sB.on(); // |
sG.off(); // |
sF.off(); // -
sE.off(); // |
sC.on(); // |
sD.off(); // -
dot.off();// .
break;
case 8:
sA.on(); // -
sB.on(); // |
sG.on(); // |
sF.on(); // -
sE.on(); // |
sC.on(); // |
sD.on(); // -
dot.off();// .
break;
case 9:
sA.on(); // -
sB.on(); // |
sG.on(); // |
sF.on(); // -
sE.off(); // |
sC.on(); // |
sD.off(); // -
dot.off();// .
break;
}
}

function hello(step){
switch(step){
case 0:
sA.off(); // -
sB.on(); // |
sG.on(); // |
sF.on(); // -
sE.on(); // |
sC.on(); // |
sD.off(); // -
dot.off();// .
break;
case 1:
sA.on(); // -
sB.off(); // |
sG.on(); // |
sF.on(); // -
sE.on(); // |
sC.off(); // |
sD.on(); // -
dot.off();// .
break;
case 2:
sA.off(); // -
sB.off(); // |
sG.on(); // |
sF.off(); // -
sE.on(); // |
sC.off(); // |
sD.on(); // -
dot.off();// .
break;
case 3:
sA.off(); // -
sB.off(); // |
sG.on(); // |
sF.off(); // -
sE.on(); // |
sC.off(); // |
sD.on(); // -
dot.off();// .
break;
case 4:
sA.on(); // -
sB.on(); // |
sG.on(); // |
sF.off(); // -
sE.on(); // |
sC.on(); // |
sD.on(); // -
dot.off();// .
break;
}

}

function snake(step){

switch(step){
case 0:
sG.off();
sD.off(); // -
sA.on(); // -
break;
case 1:
sA.off();
sB.on(); // |

break;
case 2:
sB.off(); // |
sF.on(); // -

break;
case 3:
sF.off(); // -
sE.on(); // |
break;
case 4:
sE.off(); // |
sD.on(); // -
break;
case 5:
sD.off(); // |
sC.on();
break;
case 6:
sC.off(); // |
sF.on();
break;
case 7:
sF.off(); // |
sG.on();
break;

}
}

board.on('ready', function(){


var number = 0;
var showtime = function() {
if (number <= 7){
snake(number);
number++
} else {
number = 0;
}
};


// var showtime = function() {
// if (number <= 4){
// hello(number);
// number++
// } else {
// number = 0;
// }
// };



// var showtime = function() {
// if (number <= 9){
// shownumber(number);
// number++
// } else {
// number = 0;
// }

// }


setInterval( showtime, 100 );
});


30 changes: 30 additions & 0 deletions examples/joystick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var arduino = require('../');

var board = new arduino.Board();

board.on('ready', function(){

var joystick = new arduino.JoyStick({ board: board });

joystick.on('y-up',function(amount,real_volts){
console.log('Y Increasing, amount:',amount,real_volts);

});

joystick.on('y-down',function(amount,real_volts){
console.log('Y Decreasing , amount:',amount,real_volts);
});

joystick.on('x-up',function(amount,real_volts){
console.log('X Increasing , amount:',amount,real_volts);
});

joystick.on('x-down',function(amount,real_volts){
console.log('X Decreasing , amount:',amount,real_volts);
});

});




3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
Servo: require('./lib/servo'),
Sensor: require('./lib/sensor'),
Ping: require('./lib/ping'),
PIR: require('./lib/pir')
PIR: require('./lib/pir'),
JoyStick: require('./lib/joystick')
};
2 changes: 1 addition & 1 deletion lib/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ util.inherits(Board, events.EventEmitter);
* This should really message the device and wait for a correct response
*/
Board.prototype.detect = function (callback) {
this.log('info', 'attempting to find Arduino board');
this.log('info', 'attempting to find Arduino board FORKED');
var self = this;
child.exec('ls /dev | grep usb', function(err, stdout, stderr){
var usb = stdout.slice(0, -1).split('\n'),
Expand Down
Loading