created lcd and temp functionality

This commit is contained in:
Ryan Bakkes 2021-04-13 14:05:23 +02:00
parent 23f8aa652d
commit d4df7d650b
4 changed files with 77 additions and 2 deletions

View File

@ -12,3 +12,7 @@
platform = atmelavr platform = atmelavr
board = megaatmega2560 board = megaatmega2560
framework = arduino framework = arduino
lib_deps =
https://github.com/adafruit/Adafruit_Sensor.git
https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

View File

@ -1,9 +1,13 @@
#include <Arduino.h> #include <Arduino.h>
#include <temperature.h>
#include <screen.h>
void setup() { void setup() {
// put your setup code here, to run once: Serial.begin(9600);
temperature::init();
screen::init();
} }
void loop() { void loop() {
// put your main code here, to run repeatedly:
} }

View File

@ -0,0 +1,38 @@
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
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);
}

View File

@ -0,0 +1,29 @@
#include <DHT.h>
#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;
}