Last active
August 29, 2015 14:10
-
-
Save mrded/01881bf320814308cfc3 to your computer and use it in GitHub Desktop.
The LightBlue Bean: temperature sensor to make beer.
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
static int8_t t = 0; | |
void setup() { | |
// Initialize serial communication at 57600 bits per second: | |
Serial.begin(57600); | |
Bean.setLed(0, 0, 0); | |
} | |
void setLed(int8_t t, int fadeValue) { | |
if (t > 22) { // If greater than 22C, set LED to Red. | |
Bean.setLed(fadeValue, 0, 0); | |
} | |
else if (t > 18) { // If between 15C and 30C, set LED to Green. | |
Bean.setLed(0, fadeValue, 0); | |
} | |
else { // If colder than 18C, set LED to Blue. | |
Bean.setLed(0, 0, fadeValue); | |
} | |
} | |
void loop() { | |
int8_t t = Bean.getTemperature(); | |
// Fade in from min to max in increments of 4 points: | |
for (int fadeValue = 0; fadeValue <= 128; fadeValue += 4) { | |
setLed(t, fadeValue); | |
delay(30); | |
} | |
// Fade out from max to min in increments of 4 points: | |
for (int fadeValue = 128; fadeValue >= 0; fadeValue -= 4) { | |
setLed(t, fadeValue); | |
delay(30); | |
} | |
Bean.sleep(15000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment