Last active
May 12, 2016 14:49
-
-
Save vicatcu/e761d43e2c18b1e947afafb5cd0c40cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
setInterval(() => { | |
new Promise((resolve, reject) => { | |
... | |
resolve(value); | |
... | |
}).then((value) => { ... }); | |
}, 100); |
This file contains hidden or 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
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