Skip to content

Commit a826ca8

Browse files
committed
Change Readme + package.json and clean up
1 parent 0d9da69 commit a826ca8

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
Servo Control
2-
========
1+
# Servo Control
2+
***
33

4-
It's just an experiment, the code is ugly!
5-
For informations:
6-
[It's here](http://www.pixelslip.be/lab/arduino)
4+
It's just an experiment.
5+
6+
## Getting Started
7+
Plug your Arduino with a servo motor connect and open a terminal
8+
9+
`node app.js`
10+
11+
Use your phone and type the ip address of your server in the app. Move your phone and enjoy.
12+
13+
## TODO
14+
15+
- [ ] Create graphical interface for mobile client
16+
- [ ] Add tests
17+
18+
For more informations:
19+
[Read my blog](http://www.pixelslip.be/lab/arduino)

app.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
var five = require("johnny-five")
22
, express = require("express")
33
, app = express()
4-
, board, servo, led
5-
, serie = "/dev/tty.usbmodemfa121"
6-
, port = 3000;
4+
, serie = "/dev/tty.usbmodemfa121";
75

6+
io, board, led, port, servo;
87

98
app.set('views', __dirname + '/tpl');
109
app.set('view engine', "jade");
@@ -14,15 +13,15 @@ app.get("/", function(req, res){
1413
res.render("page");
1514
});
1615

17-
var io = require('socket.io').listen(app.listen(port));
16+
io = require('socket.io').listen( app.listen(port) );
1817
console.log("Listening on port " + port);
1918

2019
io.sockets.on('connection', function(socket){
21-
20+
2221
led.on();
23-
socket.emit('message', { message: 'welcome' });
22+
socket.emit('message', { message: 'Welcome' });
2423
socket.on('send', function (data) {
25-
24+
2625
data.message /= 10;
2726
data.message = 90 + (90 * data.message);
2827
data.message = parseInt(data.message);
@@ -32,11 +31,12 @@ io.sockets.on('connection', function(socket){
3231
} else if(data.message >= 180) {
3332
data.message = 180;
3433
}
35-
34+
3635
servo.move(data.message);
3736
io.sockets.emit('message', data);
3837

3938
});
39+
4040
socket.on('disconnect', function(){
4141
led.off();
4242
});

package.json

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
{
2-
"name": "Accelerometre-Arduino",
3-
"version": "0.0.0",
4-
"description": "Control acceleromtre with smartphone",
5-
"dependencies": {
6-
"socket.io": "latest",
7-
"express": "latest",
8-
"johnny-five": "latest",
9-
"jade": "latest"
10-
},
11-
"author": "pixelslip"
12-
}
2+
"name": "Accelerometre-Arduino",
3+
"version": "0.1.0",
4+
"description": "Control servo-motor with your smartphone's accelerometre",
5+
"homepage": "https://github.com/pixelslip/ServoControl",
6+
"dependencies": {
7+
"socket.io": "1.2.0",
8+
"express": "*",
9+
"johnny-five": "0.8.20",
10+
"jade": "1.7.0"
11+
},
12+
"author": "Pixelslip <pixelslip@gmail.com> (http://pixelslip.be)",
13+
"main": "app.js",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/pixelslip/ServoControl.git"
17+
},
18+
"keywords": [
19+
"arduino",
20+
"johnny-five",
21+
"nodejs",
22+
"accelerometre"
23+
],
24+
"license": "MIT",
25+
"bugs": {
26+
"url": "https://github.com/pixelslip/ServoControl/issues"
27+
}
28+
}

public/accelero.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
window.onload = function() {
2-
3-
var socket = io.connect('http://192.168.1.24:3000');
2+
3+
var socket = io.connect('http://192.168.1.24:3000');
44
var x = y = z = 0;
55
if (window.DeviceMotionEvent != undefined) {
66
window.ondevicemotion = function(e) {
77
x = e.acceleration.x;
8-
//y = e.accelerationIncludingGravity.y;
9-
//z = e.accelerationIncludingGravity.z;
108
}
119

1210
setInterval(function(){
1311
socket.emit('send', { message: x });
1412
}, 25);
1513
} else {
16-
socket.emit('send', { message : " -- PROBLEME --"});
14+
socket.emit('send', { message : " -- ERROR --"});
1715
}
1816

1917
}

0 commit comments

Comments
 (0)