Skip to content

Instantly share code, notes, and snippets.

@vicatcu
Last active May 12, 2016 14:49
Show Gist options
  • Save vicatcu/e761d43e2c18b1e947afafb5cd0c40cb to your computer and use it in GitHub Desktop.
Save vicatcu/e761d43e2c18b1e947afafb5cd0c40cb to your computer and use it in GitHub Desktop.
setInterval(() => {
new Promise((resolve, reject) => {
...
resolve(value);
...
}).then((value) => { ... });
}, 100);
let digitalReadPromise = (pin) => {
let thePin = pin;
return new Promise( (resolve, reject) => {
setTimeout(() => { resolve(); }, 10); // wait 10 milliseconds
}).then(() => {
return new Promise((resolve, reject) => {
gBoard.digitalRead(thePin, function(value){
resolve(value);
});
});
});
};
setInterval(() => {
if(statusObj['status'] == "ready") {
// check for the start button being pressed
digitalReadPromise(START_BUTTON_PIN).then((value) => {
if (value == 0) {
return digitalReadPromise(CALIBRATE_FANS_BUTTON_PIN);
}
else {
return -1;
}
}).then((value) => {
if(value != -1) {
if (value == 0) {
// execute code for case 1
}
else if(do_fan_calibration == 1){ // fan calibration button is NOT pressed
// execute code for case 2
}
}
});
}
}, 100); // check every 100 milliseconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment