Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. const int TEMP_PIN = 0;
  2.  
  3. const int RED = 12;
  4. const int GREEN = 13;
  5. const int BLUE = 11;
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. pinMode(RED, OUTPUT);
  10. pinMode(GREEN, OUTPUT);
  11. pinMode(BLUE, OUTPUT);
  12. Serial.println("-----BEGIN-----");
  13. }
  14.  
  15. void loop() {
  16. float voltage, temp;
  17. for (;;) {
  18. voltage = getVoltage(TEMP_PIN);
  19. temp = (voltage - 0.5) * 100;
  20. Serial.print("Temperaure: "); Serial.print(temp); Serial.println("C");
  21. if (temp < 25)
  22. lightUp(BLUE);
  23. else if (temp > 30)
  24. lightUp(RED);
  25. else
  26. lightUp(GREEN);
  27. delay(500);
  28. }
  29. }
  30.  
  31. float getVoltage(int pin) {
  32. return analogRead(pin) * 0.004882814;
  33. }
  34.  
  35. void lightUp(int pin) {
  36. for (int i = 11; i <= 13; i++)
  37. digitalWrite(i, i==pin?HIGH:LOW);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement