Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
For Arduino Esplora. Uses built-in sensors to display room temperature.
#include <Esplora.h>
//Press the Down button on joypad to display current temperature
//The red LED blinks the tens value, the blue blinks the ones value. Green indicates end.
//example: red red red blue blue green is 32 degrees (F)
//the light sensor is used to dim the LEDs in a brightly lit room
//copyleft Jan 01 13 www.gordonmeyer.com
// delay used to blink lights
int flashdelay = 250;
void setup(){
}
void loop() {
if (Esplora.readButton(SWITCH_DOWN) == LOW) {
getTemp();
}
}
void getTemp() {
int theTemp = (Esplora.readTemperature(DEGREES_F));
// Serial.print(theTemp);
int theTens = (theTemp/10);
for (int i = 0; i < theTens; i++) {
flashRed();
}
int theOnes = (theTemp%10);
Serial.print(theOnes);
for (int i = 0; i < theOnes; i++) {
flashBlue();
}
delay (flashdelay);
int brt = (Esplora.readLightSensor()/10);
Esplora.writeGreen(brt);
delay (flashdelay);
Esplora.writeRGB(0,0,0);
}
void flashRed() {
// uses room brightness to set LED level
int brt = (Esplora.readLightSensor()/10);
// Serial.println("bright "); Serial.print(brt);
Esplora.writeRed(brt);
delay (flashdelay);
Esplora.writeRGB(0,0,0);
delay (flashdelay);
}
void flashBlue() {
int brt = (Esplora.readLightSensor()/10);
Esplora.writeBlue(brt);
delay (flashdelay);
Esplora.writeRGB(0,0,0);
delay (flashdelay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment