Skip to content

Instantly share code, notes, and snippets.

@j0hnm4r5 j0hnm4r5/README.md
Last active Oct 7, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.