-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
103 lines (70 loc) · 1.87 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Author: Shan Liyanage
Titan Rover - Linear Actuator controller
Description:
Controlling a linear actuator with a joystick.
Potentiometer values will be displayed graphically on a
separate web page in real time
*/
var pubnub = require('pubnub');
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
// Initializing linear actuator pins
var in8 = new five.Pin(10);
var in7 = new five.Pin(11);
// Initializing joystick pin Range ( 0 - 1023)
var pin = new five.Pin(2);
// The joystick is in the neutral position ~ between 500 - 530
var lBound = 500;
var uBound = 530;
// PubNub Stuff
var potentiometer;
var channel = 'arduino_output';
var pub = new pubnub({
publish_key: 'pub-c-a72e78c9-93be-4e27-bf0c-f451ae2e4bf6',
subscribe_key: 'sub-c-e1e6b59e-7495-11e6-80e7-02ee2ddab7fe'
});
/* Limits for pot on actuator
Low: ~50
High: ~990
*/
/*
Reading values from the joystick
If the joystick is position up, send signal to expand.
If down, send signal to contract
if neutral, stop actuator.
*/
this.analogRead(2, function(voltage){
if(voltage > uBound){
in7.low();
in8.high();
console.log("Y Value: " + voltage);
}
else if(voltage < lBound){
in7.high();
in8.low();
console.log("Y Value: " + voltage);
}
else {
in7.low();
in8.low()
}
})
// Reading values from the actuators potentiometer
this.analogRead(4, function(vol){
potentiometer = vol;
console.log("Pot voltage:" + vol);
})
// Sending voltage to pubnub server
// setInterval(publish, 3000);
// function publish() {
// var data = {
// 'voltage': potentiometer,
// };
// pub.publish({
// channel: channel,
// message: data,
// });
// }
});