Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Created May 7, 2020 06:20
Show Gist options
  • Save Sleavely/49ed057ce97fda69a5a88ad6d62ab448 to your computer and use it in GitHub Desktop.
Save Sleavely/49ed057ce97fda69a5a88ad6d62ab448 to your computer and use it in GitHub Desktop.
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)
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