Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement