diff --git a/CrabbyHome-comp/CrabbyHome-master/platformio.ini b/CrabbyHome-comp/CrabbyHome-master/platformio.ini index 67e8cb2..524f15e 100644 --- a/CrabbyHome-comp/CrabbyHome-master/platformio.ini +++ b/CrabbyHome-comp/CrabbyHome-master/platformio.ini @@ -12,3 +12,7 @@ platform = atmelavr board = megaatmega2560 framework = arduino + +lib_deps = + https://github.com/adafruit/Adafruit_Sensor.git + https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library \ No newline at end of file diff --git a/CrabbyHome-comp/CrabbyHome-master/src/main.cpp b/CrabbyHome-comp/CrabbyHome-master/src/main.cpp index 58b344c..14b5a71 100644 --- a/CrabbyHome-comp/CrabbyHome-master/src/main.cpp +++ b/CrabbyHome-comp/CrabbyHome-master/src/main.cpp @@ -1,9 +1,13 @@ #include +#include +#include void setup() { - // put your setup code here, to run once: + Serial.begin(9600); + temperature::init(); + screen::init(); } void loop() { - // put your main code here, to run repeatedly: + } \ No newline at end of file diff --git a/CrabbyHome-comp/CrabbyHome-master/src/screen.h b/CrabbyHome-comp/CrabbyHome-master/src/screen.h new file mode 100644 index 0000000..8d46f12 --- /dev/null +++ b/CrabbyHome-comp/CrabbyHome-master/src/screen.h @@ -0,0 +1,38 @@ +#include +#include + +LiquidCrystal_I2C lcd(0x3f, 16, 2); + +namespace screen{ + void init(); + void display(char* title, char* text); +} + +void screen::init(){ + lcd.begin(); + // Print a message to the LCD. + lcd.backlight(); + lcd.setCursor(3,0); + lcd.print("CrabbyHome"); + lcd.setCursor(3,1); + lcd.print("Activated!"); +} + +void screen::display(char* title, char* text){ + int titleSize = strlen(title); + int textSize = strlen(text); + lcd.clear(); + + // check if text fits in screen + if(titleSize <= 16){ + int offset = (16 - titleSize) / 2; + lcd.setCursor(offset, 0); + } + lcd.print(title); + + if(textSize <= 16){ + int offset = (16 - textSize) / 2; + lcd.setCursor(offset, 1); + } + lcd.print(text); +} \ No newline at end of file diff --git a/CrabbyHome-comp/CrabbyHome-master/src/temperature.h b/CrabbyHome-comp/CrabbyHome-master/src/temperature.h new file mode 100644 index 0000000..5c01af2 --- /dev/null +++ b/CrabbyHome-comp/CrabbyHome-master/src/temperature.h @@ -0,0 +1,29 @@ +#include + +#define DHT_SENSOR_PIN 7 // Define DHT Connected Data Pin +#define DHT_TYPE DHT11 // Define DHT Sensor Type +DHT dht_sensor(DHT_SENSOR_PIN, DHT_TYPE); // Set info for dht + +// create namespace +namespace temperature{ + void init(); + float readTemp(); + float readHum(); +} + +void temperature::init(){ + dht_sensor.begin(); + Serial.println("temp sensor init"); +} + +float temperature::readTemp(){ + float temp = dht_sensor.readTemperature(); // read temp + + return temp; +} + +float temperature::readHum(){ + float hum = dht_sensor.readHumidity(); // read temp + + return hum; +} \ No newline at end of file