Skip to content

Instantly share code, notes, and snippets.

@j0hnm4r5
Last active October 7, 2018 01:56
Show Gist options
  • Save j0hnm4r5/7f33ffed551d4e1e3ee13d2c17b86cfd to your computer and use it in GitHub Desktop.
Save j0hnm4r5/7f33ffed551d4e1e3ee13d2c17b86cfd to your computer and use it in GitHub Desktop.
Button Presser

Installation

  1. Set up your microcontroller according to the instructions at Johnny-Five
  2. Hook up your servo to pin 9 on the microcontroller
  3. Install all dependencies with npm install
  4. Change the numberOfPresses, pressTime, and releaseTime variables in index.js
  5. 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.
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;
}
{
"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