- Set up your microcontroller according to the instructions at Johnny-Five
- Hook up your servo to pin 9 on the microcontroller
- Install all dependencies with
npm install
- Change the
numberOfPresses
,pressTime
, andreleaseTime
variables inindex.js
- Run
npm run start
to begin pressing your button! You'll probably have to adjust the servo horn and whatever you're holding the servo with.
Last active
October 7, 2018 01:56
-
-
Save j0hnm4r5/7f33ffed551d4e1e3ee13d2c17b86cfd to your computer and use it in GitHub Desktop.
Button Presser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const five = require("johnny-five"); | |
const numberOfPresses = 100; | |
const pressTime = 1250; // ms | |
const releaseTime = 750; // ms | |
let servo; | |
const board = new five.Board({ | |
repl: false | |
}); | |
board.on("ready", function() { | |
servo = new five.Servo({ | |
pin: 9, | |
range: [90, 180] | |
}); | |
cycler(numberOfPresses); | |
}); | |
function cycler(times) { | |
console.log(times); | |
if (times === 0) return Promise.resolve(); | |
return cycle().then(() => { | |
return cycler(times - 1); | |
}); | |
} | |
function cycle() { | |
let action = new Promise(resolve => { | |
servo.max(); | |
console.log("PRESS"); | |
setTimeout(() => { | |
servo.min(); | |
console.log("RELEASE"); | |
setTimeout(() => { | |
resolve(); | |
}, releaseTime); | |
}, pressTime); | |
}); | |
return action; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "buttonpresser", | |
"version": "0.0.1", | |
"main": "index.js", | |
"scripts": { | |
"start": "nodemon index.js" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"johnny-five": "^1.0.0", | |
"nodemon": "^1.18.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment