Skip to content

Instantly share code, notes, and snippets.

@wrboyce
Last active August 29, 2015 14:16
Show Gist options
  • Save wrboyce/f4587729daf6ea505557 to your computer and use it in GitHub Desktop.
Save wrboyce/f4587729daf6ea505557 to your computer and use it in GitHub Desktop.
const int TEMP_PIN = 0;
const int RED = 12;
const int GREEN = 13;
const int BLUE = 11;
void setup() {
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
Serial.println("-----BEGIN-----");
}
void loop() {
float voltage, temp;
for (;;) {
voltage = getVoltage(TEMP_PIN);
temp = (voltage - 0.5) * 100;
Serial.print("Temperaure: "); Serial.print(temp); Serial.println("C");
if (temp < 25)
lightUp(BLUE);
else if (temp > 30)
lightUp(RED);
else
lightUp(GREEN);
delay(500);
}
}
float getVoltage(int pin) {
return analogRead(pin) * 0.004882814;
}
void lightUp(int pin) {
for (int i = 11; i <= 13; i++)
digitalWrite(i, i==pin?HIGH:LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment