Now I know that the LCD board works (except for the half lit LED haha) , I can move on to test whether the actual LCD screen itself works and displays messages the way I want. Using the arduino software along with my Arduino UNO, I began to write my first piece of wiring language, here goes nothing!
I knew exactly what I needed to do because of my switch menu algorithm, this actually came in handy even tho I moaned a lot about it haha! Id start off with my Welcome Message, then onto my Temperature value, humidity value, and light value all being displayed on screen one after another by the press of the mode select button on the actual board.
Arduino Code
// include the library code:
#include <LiquidCrystal.h>
#include <math.h>
LiquidCrystal lcd(12,11,5,4,3,2);
// *** Variable decalarations ***
const int switchPin = 8;
int sw_state = 0; //new value of the mode switch
int no_of_switch_presses =0; //number of presses of the mode switch
int val;// store val of mode switch
int old_val=0; //store the previous value of valof the mode switch
int FAN=6;//declaring fan pin
int ledon=13;//declarin led pin
float TC;//making TC a global variable so it can be read from the function
float LuxVal;//making the Lux Value a global variable so it can be read from the function
void setup()
{
pinMode(switchPin,INPUT); // Set as input for the mode switch
pinMode(ledon,HIGH);//putting the LED on the LCD board constantly on
lcd.begin(8,2);//setting the cursor for the LCD screen
}
void loop(){
// **** Mode Select ****
val = digitalRead(switchPin); // Read the mode switch
if ((val == LOW) && (old_val ==HIGH)) {
no_of_switch_presses = no_of_switch_presses +1;
//Update the number of switch presses and inplement soft switch debounce
delay(50); // 50ms debounce delay
}
old_val = val; //val is now old so store it
digitalWrite(ledon,HIGH);
// Display whichever dipslay mode has been selected
switch (no_of_switch_presses) {
case 0:
// *** Welcome Message ***
lcd.setCursor(0,0);//first half of the screen
lcd.print(“Damien’s”);
lcd.setCursor(0,1);//second half of the screen
lcd.print(“Project”);
// ** TEMPERATURE MODE **
TEMP();
lcd.setCursor(0,0);//first half of the screen
lcd.print(“Temp = “);
lcd.setCursor(0,1);//second half of the screen
delay(200);
lcd.print(TC);//printing the degree celsius value which is going to be called TC.
lcd.setCursor(5,1);//starting after the 5th position on the second half of the screen
lcd.print(“oC “); //degrees celsius
break; // end temperature case
// ** HUMIDITY MODE **
lcd.setCursor(0,0);//first half of the screen
lcd.print(“Humid Val”);
lcd.setCursor(0,1);//second half of the screen
lcd.print(” “);
// print the current humidity value:
break;// end humidity case
LIGHT();
// ** Light Level MODE **
lcd.setCursor(0,0);//first half of the screen
lcd.print(“Lux Val “);
lcd.setCursor(0,1);//second half of the screen
lcd.print(LuxVal);//printing the Lux value from the LIGHT function
delay(200);
break; // end light level case