Skip to content

Instantly share code, notes, and snippets.

@vicatcu
Last active May 12, 2016 15:53
Show Gist options
  • Save vicatcu/1ca26d17b3e062ab40df4c8f422fbbbe to your computer and use it in GitHub Desktop.
Save vicatcu/1ca26d17b3e062ab40df4c8f422fbbbe to your computer and use it in GitHub Desktop.
let delay = (ms) => {
return new Promise( (resolve, reject) => {
setTimeout(() => { resolve(); }, ms);
});
};
let digitalRead = (thePin) => {
return new Promise((resolve, reject) => {
gBoard.digitalRead(thePin, function(value){
resolve(value);
});
});
};
let digitalReadPromise = (pin) => {
return delay(10).then(digitalRead.bind(null, pin));
};
setInterval(() => {
digitalReadPromise(START_BUTTON).then((start_button_value) => {
if(start_button_value == 0){
return digitalReadPromise(CALIBRATE_FANS_BUTTON_PIN);
}
else{
return -1;
}
}).then((calibrate_button_value) => {
if(calibrate_button_value == 0){
// do the calibrate function
}
else if(calibrate_button_value == 1){
// do the normal functino
}
});
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment