//Title: Activity #4.1.2 - LCD with Slide Switch
//Description: Display a message on the LCD when the switch is activated
//Created by: Soliat Adeboye
//Date started: 10/12/2021
//Date completed: 10/12/2021
//#include is used to import a header library to access a specific component.
#include <LiquidCrystal_I2C.h>
//Assigning and identifying the component being accessed through the library.
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Creating an array of integer data type and assigning specific values
int numarray[] = {1,2,3,4,5};
int SwitchWorking = 2;
void setup()
{
// put your setup code here, to run once:
//Calls two procedures that will initialize variables and the liquid crystal display.
LCD_Setup();
LCD_Display();
SwitchSetup();
}
void loop()
{
// put your main code here, to run repeatedly:
//Calls the procedure, PrintNum() to display the numbers on the liquid crystal display.
SwitchOn();
//PrintNum();
}
void SwitchSetup()
{
pinMode(SwitchWorking, INPUT_PULLUP);
}
void SwitchOn()
{
if (digitalRead(SwitchWorking) == HIGH)
{
PrintNum();
}
else
{
lcd.clear();
delay(200);
}
}
void LCD_Setup()
{
//Activates the liquid crystal display for use and turns on the screen light for the information to be seen.
lcd.init();
lcd.backlight();
}
void LCD_Display()
{
//Sets the cursor, starting point, to a specific location to start printing the information.
lcd.setCursor(0,0);
}
void PrintNum()
{
//A while loop is used to retrieve and print specific values
//that are stored in an array. The loop will terminate when the condition, i < 5 becomes false.
//exit(0), stops the program completely once all conditions have been met.
//int i = 0;
//while(i < 5)
//{
//lcd.print(numarray[i]);
//i = i +1;
//}
for (int i = 0; i <=4; i++)
lcd.print(numarray[i]);
delay(800);
lcd.clear();
//exit(0);
}