Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CM2306_G46
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lauren Kelly
CM2306_G46
Commits
e88a2d2b
Commit
e88a2d2b
authored
2 years ago
by
Lauren Kelly
Browse files
Options
Downloads
Patches
Plain Diff
Codebase 20230408
parents
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.vscode/arduino.json
+6
-0
6 additions, 0 deletions
.vscode/arduino.json
display_code.ino
+152
-0
152 additions, 0 deletions
display_code.ino
with
158 additions
and
0 deletions
.vscode/arduino.json
0 → 100644
+
6
−
0
View file @
e88a2d2b
{
"sketch"
:
"display_code.ino"
,
"board"
:
"arduino:avr:leonardo"
,
"port"
:
"/dev/tty.usbmodem1101"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
display_code.ino
0 → 100644
+
152
−
0
View file @
e88a2d2b
#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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment