Created
May 7, 2020 06:20
-
-
Save Sleavely/49ed057ce97fda69a5a88ad6d62ab448 to your computer and use it in GitHub Desktop.
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 Gpio = require('onoff').Gpio; | |
const sleep = require('./sleep') | |
const motor = new Gpio(17, 'out') | |
// Run the motor connected to GPIO17 every 1000ms | |
let beltIsShuttingDown = false | |
const runBelt = async () => { | |
if (beltIsShuttingDown) return | |
// Dansa | |
await motor.write(1) | |
await sleep(500) | |
// Pausa | |
await motor.write(0) | |
await sleep (1000) | |
runBelt() | |
} | |
runBelt() | |
// Gracefully shut down motor after 15 seconds | |
setTimeout(async () => { | |
beltIsShuttingDown = true | |
await motor.write(0) | |
motor.unexport() | |
process.exit(0) | |
}, 15000) |
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
module.exports = exports = async (sleepTime = 1000, resolveWith = undefined) => { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(resolveWith) | |
}, sleepTime) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment