Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active August 29, 2015 14:10
Show Gist options
  • Save mrded/01881bf320814308cfc3 to your computer and use it in GitHub Desktop.
Save mrded/01881bf320814308cfc3 to your computer and use it in GitHub Desktop.
The LightBlue Bean: temperature sensor to make beer.
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