First you must install the library for the LCD screen as explained in my
Grove starter kit for arduino --- RGB LCD project:
In order to use the Grove LCD you'll need to download a library here, and move it to your Arduino>Libraries folder:
And for hardware connections, plug the LCD screen into any of the I2C ports, the button into D2, and the touch sensor into D3, and the temperature sensor into A1:
You must also connect pin 1 of the TMP 36 to 5v, pin 2 to A0, and pin 3 to GND. The pins are as follows:
Then just stick the TMP 36 out the window, and mount the rest however you want.
Code:I won't explain the code in full because the code is heavily commented, but I will talk about 2 functions.
In the void loop, this while loop sets the background to the correct color, then sets the background color, decreases the value of the count var, delays 20 milliseconds, and reduces the count var by 1. Then it repeats, this will happen 50x since the count var = 50.
while (count > 0) {
if (background == 1) { //if the background int is 1:
R = 255; //set the variables for the background
G = 0;
B = 0;
}
else if (background == 2) { //else if the background int is 2:
R = 0; //set the variables for the background
G = 255;
B = 0;
}
else if (background == 3) { //else if the background int is 3:
R = 0; //set the variables for the background
G = 0;
B = 255;
}
else if (background == 4) { //else if the background int is 5:
R = 255; //set the variables for the background
G = 255;
B = 255;
}
lcd.setRGB(R, G, B);//set the background color of the lcd screen
count--;
delay(20);//delay 20 milliseconds
}
Moving on to the functions, the functions for finding the temperature are directly from the data sheets, and the others are as follows:
The checkButtons function creates a variable called b that is assigned the value of the button. Then if b is 1, which means the button is pressed, it will change to the next background unless it's on the last one (4) in which case it will start over at 1.
int checkButtons(int b1, int bc) {
int b = digitalRead(b1);//make the variable b what is read on b1
if (b == 1) { //if b (the reading of b1) is 1 (pressed)
if (background < 4) {
background++;
}
else if (background == 4) {
background = 1;
}
}
b = digitalRead(bc);
if (b == 1) {
if (cf == 0) {
cf = 1;
}
else if (cf == 1) {
cf = 0;
}
}
return background;// return the background int
return cf;//return the celsius/fahrenheit int
}
Controls:To change between C and F press the touch sensor, and to change the background color press the button.
Product:Once you have downloaded the code your project should look something like this:
Comments