2022-11-27 00:45:18 +00:00
|
|
|
var gpio = require('rpi-gpio');
|
2022-11-27 00:49:07 +00:00
|
|
|
gpio.setup(7, gpio.DIR_OUT, cycleAuger);
|
2022-11-27 00:33:33 +00:00
|
|
|
|
2022-11-27 00:44:31 +00:00
|
|
|
function augerOn(err) {
|
|
|
|
if (err) throw err;
|
|
|
|
gpio.write(7, true, function(err) {
|
|
|
|
if (err) throw err;
|
|
|
|
console.log('Auger turned on.');
|
|
|
|
});
|
2022-11-27 00:33:33 +00:00
|
|
|
}
|
|
|
|
|
2022-11-27 00:44:31 +00:00
|
|
|
function augerOff(err) {
|
|
|
|
if (err) throw err;
|
|
|
|
gpio.write(7, false, function(err) {
|
|
|
|
if (err) throw err;
|
|
|
|
console.log('Auger turned off.');
|
|
|
|
});
|
2022-11-27 00:33:33 +00:00
|
|
|
}
|
2022-11-27 00:44:31 +00:00
|
|
|
|
|
|
|
// Identical functions as above for debugging without gpio
|
|
|
|
// function augerOff() {
|
|
|
|
// console.log('Auger turned off.');
|
|
|
|
// }
|
|
|
|
|
|
|
|
// function augerOn() {
|
|
|
|
// console.log('Auger turned on.');
|
|
|
|
// }
|
2022-11-27 00:33:33 +00:00
|
|
|
|
|
|
|
function sleep(ms) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(resolve, ms);
|
2022-11-27 00:41:39 +00:00
|
|
|
console.log(`Slept for ${ms}ms`);
|
2022-11-27 00:33:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-27 00:49:07 +00:00
|
|
|
async function cycleAuger(err) {
|
|
|
|
if (err) throw err;
|
2022-11-27 01:31:54 +00:00
|
|
|
const offTime = 1200; //ms
|
2022-11-27 00:42:34 +00:00
|
|
|
const onTime = 500; //ms
|
2022-11-27 00:33:33 +00:00
|
|
|
augerOn();
|
2022-11-27 00:43:12 +00:00
|
|
|
await sleep(onTime);
|
2022-11-27 00:33:33 +00:00
|
|
|
augerOff();
|
2022-11-27 00:43:12 +00:00
|
|
|
await sleep(offTime);
|
2022-11-27 00:39:33 +00:00
|
|
|
cycleAuger();
|
2022-11-27 00:49:07 +00:00
|
|
|
}
|