Skip to content
Snippets Groups Projects
Commit e88a2d2b authored by Lauren Kelly's avatar Lauren Kelly :airplane:
Browse files

Codebase 20230408

parents
No related branches found
No related tags found
No related merge requests found
{
"sketch": "display_code.ino",
"board": "arduino:avr:leonardo",
"port": "/dev/tty.usbmodem1101"
}
\ No newline at end of file
#include <SoftwareSerial.h>
#include <Time.h>
#include <TimeLib.h>
#include "Arduino.h"
#include <Wire.h>
#include "rgb_lcd.h"
#include "DHT.h"
// Defines
#if defined(ARDUINO_ARCH_AVR)
#define debug Serial
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#define debug SerialUSB
#else
#define debug Serial
#endif
// Temperature and Humidity Sensor
#define DHTTYPE DHT20
DHT dht(DHTTYPE);
// RGB LCD controller
rgb_lcd lcd;
// Current temperature
float temp = 0;
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//pinMode(6,OUTPUT);
// initialize the serial communications:
Serial.begin(9600);
// For debug purposes -- set the time
setTime(17,43,0,8,5,23);
debug.begin(115200);
debug.println("DHTxx test!");
Wire.begin();
time_t t = now();
dht.begin();
float initialTemp[2] = {0};
dht.readTempAndHumidity(initialTemp);
temp = initialTemp[1];
}
void loop(){
int joyStick1 = analogRead(A0); // Reads in the joyStick state
float newTemp[2] = {0};
dht.readTempAndHumidity(newTemp);
float currentTemp = newTemp[1]; //Takes in the current room temperature
if(currentTemp > (temp + 3)){
int joyStick3 = analogRead(A0);
if(joyStick3 != 1022){
highTemp(); //Alerts the user if the room temperature is too hot. "10*C over the initial room temperature is being considered as too hot"
Serial.println(currentTemp);
}
}
if (joyStick1 == 1022){ //Joystick has been pushed down
for(int count = 0; count < 100; count++){ //Timer to keep the display on
int joyStick2 = analogRead(A0); //Takes in the joystick reading in again
if(joyStick2 == 1022 ) { //If Joystick has been clicked again, the Temperature and Humidity will be displayed
lcd.display(); //Turns on the display
printDHT(); // Temperature and Humidity is displayed
delay(3000);
lcd.clear(); //Clears the screen
} else {
lcd.display();
digitalClockDisplay();//Date and time printed
delay(1000);
lcd.clear(); //Clears the screen
}
}
}else{
lcd.noDisplay();
}
}
void digitalClockDisplay()
{
// Displays the Date and time
lcd.print(hour());
printDigits(minute());
printDigits(second());
lcd.print(" ");
lcd.setCursor(0, 1); //Moves the cursor down, so the date is on the second line
lcd.print(day());
lcd.print(" ");
lcd.print(month());
lcd.print(" ");
lcd.print(year());
}
void printDigits(int digits)
{
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}
void printDHT(){
float temp_hum_val[2] = {0};
if (!dht.readTempAndHumidity(temp_hum_val)) { //reads in the Temperature and Humidity of the room
lcd.print("Humidity: ");
lcd.print(temp_hum_val[0]);
lcd.print(" %\t");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temp_hum_val[1]);
lcd.print("C");
} else {
debug.println("Failed to get temprature and humidity value.");
}
delay(1500);
}
void highTemp(){
lcd.clear();
lcd.display();
lcd.setRGB(255,0,0); //Sets the colour of the LCD screen to be red
lcd.print("ROOM TOO HOT!!!");
digitalWrite(6,HIGH); // Sets the buzzer off
delay(3000);
digitalWrite(6,LOW);
delay(3000);
delay(7000);
lcd.setRGB(255,255,255); //Sets the colour of the LCD screen to be white
lcd.clear();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment