// include onoff to interact with the GPIO
var Gpio = require('onoff').Gpio;
// the relays have io numbers 16,17,22,23 when connected via the 2x20 header
// if you wire manually via the 8-pin header then these numbers can be different
var Rel1 = new Gpio(16, 'out');
var Rel2 = new Gpio(17, 'out');
var Rel1 = new Gpio(22, 'out');
var Rel1 = new Gpio(23, 'out');
// simplistic sleep method for demo purposes only
function sleep(ms) {
const date = Date.now();
let currentDate = null;
do { currentDate = Date.now(); }
while (currentDate - date < ms);
}
// turn each relay on/off for a second, repeating 10 times
for (let a=0; a<10; a++) {
Rel1.writeSync(1);
sleep(1000);
Rel1.writeSync(0);
Rel2.writeSync(1);
sleep(1000);
Rel2.writeSync(0);
Rel3.writeSync(1);
sleep(1000)
Rel3.writeSync(0);
Rel4.writeSync(1);
sleep(1000);
Rel4.writeSync(0);
}