@@ -29,53 +29,52 @@ node eg/esc-dualshock.js
29
29
30
30
31
31
``` javascript
32
- var five = require (" ../lib/ johnny-five.js " );
33
- var dualShock = require (" dualshock-controller" );
32
+ const { Board , ESC , Fn } = require (' johnny-five' );
33
+ const dualShock = require (' dualshock-controller' );
34
34
35
- var board = new five. Board ();
36
- var controller = dualShock ({
37
- config: " dualShock3" ,
38
- analogStickSmoothing: false
35
+ const board = new Board ();
36
+ const controller = dualShock ({
37
+ config: ' dualShock3' ,
38
+ analogStickSmoothing: false ,
39
39
});
40
40
41
- board .on (" ready" , function () {
41
+ board .on (' ready' , () => {
42
+ const esc = new ESC (9 );
43
+ let speed = 0 ;
44
+ let last = null ;
42
45
43
- var esc = new five.ESC (9 );
44
- var speed = 0 ;
45
- var last = null ;
46
-
47
- controller .on (" connected" , function () {
46
+ controller .on (' connected' , () => {
48
47
controller .isConnected = true ;
49
48
});
50
49
51
- controller .on (" dpadUp:press" , function () {
52
- if (last !== " up " ) {
50
+ controller .on (' dpadUp:press' , () => {
51
+ if (last !== ' up ' ) {
53
52
speed = 0 ;
54
53
} else {
55
54
speed += 1 ;
56
55
}
57
56
esc .throttle (esc .neutral + speed);
58
- last = " up "
57
+ last = ' up ' ;
59
58
});
60
59
61
- controller .on (" dpadDown:press" , function () {
62
- if (last !== " down" ) {
60
+ controller .on (' dpadDown:press' , () => {
61
+ if (last !== ' down' ) {
63
62
speed = 0 ;
64
63
} else {
65
64
speed += 1 ;
66
65
}
67
66
esc .throttle (esc .neutral - speed);
68
- last = " down"
67
+ last = ' down' ;
69
68
});
70
69
71
- controller .on (" circle:press" , function () {
70
+ controller .on (' circle:press' , () => {
72
71
last = null ;
73
72
speed = 0 ;
74
73
esc .brake ();
75
74
});
76
75
77
- controller .on (" right:move" , function ( position ) {
78
- var y = five . Fn .scale (position .y , 255 , 0 , 0 , 180 ) | 0 ;
76
+ controller .on (' right:move' , position => {
77
+ const y = Fn .scale (position .y , 255 , 0 , 0 , 180 ) | 0 ;
79
78
80
79
if (y > 100 ) {
81
80
// from the deadzone and up
@@ -86,7 +85,6 @@ board.on("ready", function() {
86
85
controller .connect ();
87
86
});
88
87
89
-
90
88
// Brushless motor breadboard diagram originally published here:
91
89
// http://robotic-controls.com/learn/projects/dji-esc-and-brushless-motor
92
90
0 commit comments