Initial commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
#define ONE_WIRE_BUS 2
|
||||
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
int red_light_pin = 5;
|
||||
int green_light_pin = 4;
|
||||
int blue_light_pin = 0;
|
||||
|
||||
unsigned long previousMillis = 0;
|
||||
const long interval = 60000;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
sensors.begin();
|
||||
pinMode(red_light_pin, OUTPUT);
|
||||
pinMode(green_light_pin, OUTPUT);
|
||||
pinMode(blue_light_pin, OUTPUT);
|
||||
showTempWithLED(meassureTemp());
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
showTempWithLED(meassureTemp());
|
||||
}
|
||||
}
|
||||
|
||||
float meassureTemp() {
|
||||
sensors.requestTemperatures();
|
||||
float tempC = sensors.getTempCByIndex(0);
|
||||
|
||||
if (tempC != DEVICE_DISCONNECTED_C) {
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(tempC);
|
||||
} else {
|
||||
Serial.println("Error: Could not read temperature data");
|
||||
}
|
||||
return tempC;
|
||||
}
|
||||
|
||||
// Had to invert colors because of LED type
|
||||
void showTempWithLED(float tempC) {
|
||||
if (tempC <= 21) {
|
||||
RGB_color(255, 255, 0);
|
||||
}
|
||||
else if(tempC >= 24) {
|
||||
RGB_color(0, 255, 255);
|
||||
}
|
||||
else {
|
||||
RGB_color(255, 0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void RGB_color(int red_light_value, int green_light_value, int blue_light_value) {
|
||||
analogWrite(red_light_pin, red_light_value);
|
||||
analogWrite(green_light_pin, green_light_value);
|
||||
analogWrite(blue_light_pin, blue_light_value);
|
||||
}
|
||||
Reference in New Issue
Block a user