Last active
May 12, 2016 15:53
-
-
Save vicatcu/1ca26d17b3e062ab40df4c8f422fbbbe to your computer and use it in GitHub Desktop.
This file contains 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 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