You are on page 1of 17

Chapter 6: Lab Activity 3 (Group 3)

1. Modify Example 1 so that the text "TIP" is moving back and forth.

Circuit:

Source Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd( 12, 11, 5, 4, 3, 2);

const int timer=500;


int ctr;

void setup()
{
// set up the LCD's number of columns and rows:
ctr=0;
lcd.begin(16, 2);
}

void loop()
{
if (ctr==0)
{
for (int col=15;col>=0;col--)
{
lcd.clear();
Chapter 6: Lab Activity 3 (Group 3)

lcd.setCursor(col,0);
lcd.print("TIP");
delay(timer);
}
ctr++;
}
if (ctr==1 || ctr==5)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IP");
delay(timer);
ctr++;
}
if (ctr==2 || ctr==4)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("P");
delay(timer);
ctr++;
}

if (ctr==6)
{
for (int col2=0;col2<=15;col2++)
{
lcd.clear();
lcd.setCursor(col2,0);
lcd.print("TIP");
delay(timer);
}
ctr++;
}
if (ctr==3 || ctr==7)
{
lcd.clear();
delay(timer);
ctr++;
}
if (ctr==8)
{
ctr=0;
}
Chapter 6: Lab Activity 3 (Group 3)

}
Chapter 6: Lab Activity 3 (Group 3)

2. Modify Example 2 so that the text "TIP" is moving back and forth using 2
Pushbuttons.

Circuit:

Source Code:
#include <LiquidCrystal.h>

//(rs, en, d4, d5, d6, d7)


LiquidCrystal lcd( 12, 11, 5, 4, 3, 2);

const int timer=500;


int ctr;
int ctr2;
int col;
int forward;
int backward;

void setup()
{
// set up the LCD's number of columns and rows:
ctr=0;
col=0;
lcd.begin(16, 2);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
}

void loop()
Chapter 6: Lab Activity 3 (Group 3)

{
forward=digitalRead(A0);
backward=digitalRead(A1);

if (forward==1)
{
ctr++;
}
if (backward==1)
{
ctr--;
}

if (forward==1 && ctr>=3 && ctr<=18)


{
lcd.clear();
lcd.setCursor(col,0);
lcd.print("TIP");
delay(timer);
col++;
}
if ((forward==1 || backward==1) && ctr==1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("P");
delay(timer);
}
if ((forward==1 || backward==1) && (ctr==0 || ctr==19))
{
lcd.clear();
delay(timer);
ctr=0;
col=0;
}
if ((forward==1 || backward==1) && ctr==2)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IP");
delay(timer);
}
if (backward==1 && ctr>=3 && ctr<=18)
{
Chapter 6: Lab Activity 3 (Group 3)

col--;
lcd.clear();
lcd.setCursor(col,0);
lcd.print("TIP");
delay(timer);
}
if (ctr==3 && col==1 && backward==1)
{
ctr=3;
col=0;
}
if (backward==1 && ctr<0)
{
col=15;
lcd.clear();
lcd.setCursor(col,0);
lcd.print("TIP");
delay(timer);
ctr=18;
}
if (ctr==18 && col==14 && forward==1)
{
ctr=17;
col=14;
}
}
Chapter 6: Lab Activity 3 (Group 3)

3. Display the lines of text below, one after the other. First, show each line of text in
the bottom line, and then move it up to the top line of the LCD. This should give a
scrolling effect to your message. Leave every bit of text 2 seconds on the bottom
line and 2 seconds on the top line. While one line of text moves to the top line,
the next one fills up the bottom line. Text: “There are only”, ”10 kinds”,” of
people !”, “Those who”, “understand”, “BINARY”, “and those who”, “DON’T….”.
Put it all in an infinite loop.

Circuit:

Source Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
lcd.begin(16, 2);
}

void loop()
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("There are only");
Chapter 6: Lab Activity 3 (Group 3)

delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("There are only");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("10 kinds");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("10 kinds");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("of people !");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("of people !");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Those who");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("Those who");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("understand");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
Chapter 6: Lab Activity 3 (Group 3)

lcd.setCursor(0,0);
lcd.print("understand");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("BINARY");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("BINARY");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("and those who");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("and those who");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("DON'T....");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("DON'T....");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
delay(2000);

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
Chapter 6: Lab Activity 3 (Group 3)

lcd.setCursor(0,1);
lcd.print(" ");
delay(2000);
}
Chapter 6: Lab Activity 3 (Group 3)

4. Day of the week program. This simulation picks a certain day using the Next and
Previous Push Buttons to be displayed on the LCD.

Circuit:

Source Code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define pressed 0
#define STR 2
#define SUN 3
#define MON 4
#define TUE 5
#define WED 6
#define THU 7
#define FRI 8
#define SAT 9

int nextButton;
int prevButton;
int counter = 2;
Chapter 6: Lab Activity 3 (Group 3)

void setup()
{
lcd.begin(16, 2);

lcd.setCursor(0,0);
lcd.print("Day of the Week:");

pinMode(A1,INPUT);
pinMode(A2,INPUT);
}

void loop()
{
nextButton=digitalRead(A1);
prevButton=digitalRead(A2);

if (nextButton==pressed)
{
counter = counter + 1;
}

if (prevButton==pressed)
{
counter = counter - 1;
}

if (counter==10)
{
counter = 2;
}

if (counter==1)
{
counter = 9;
}

if ((nextButton==pressed || prevButton==pressed) &&


counter==2)
{
lcd.setCursor(0,1);
lcd.print(" ");
delay(500);
}
Chapter 6: Lab Activity 3 (Group 3)

if ((nextButton==pressed || prevButton==pressed) &&


counter==3)
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Sunday");
delay(500);
}

if ((nextButton==pressed || prevButton==pressed) &&


counter==4)
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Monday");
delay(500);
}

if ((nextButton==pressed || prevButton==pressed) &&


counter==5)
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Tuesday");
delay(500);
}

if ((nextButton==pressed || prevButton==pressed) &&


counter==6)
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Wednesday");
delay(500);
}

if ((nextButton==pressed || prevButton==pressed) &&


counter==7)
{
lcd.setCursor(0,1);
Chapter 6: Lab Activity 3 (Group 3)

lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Thursday");
delay(500);
}

if ((nextButton==pressed || prevButton==pressed) &&


counter==8)
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Friday");
delay(500);
}

if ((nextButton==pressed || prevButton==pressed) &&


counter==9)
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Saturday");
delay(500);
}
}

5. Simple Motor Simulation Indicator with Power (ON/OFF), Forward and Reverse
Buttons.
Chapter 6: Lab Activity 3 (Group 3)

Circuit:

Source Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define LED1 6
#define LED2 7
#define LED3 8
#define pressed 0
#define ON 1
#define OFF 0

int P1;
int P2;
int P3;
int P4;
int pStatus;

void setup()
{
lcd.begin(16,2);

lcd.setCursor(0,0);
lcd.print("POWER:OFF");
Chapter 6: Lab Activity 3 (Group 3)

lcd.setCursor(0,1);
lcd.print("MOTOR:OFF");

pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);

pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
}

void loop()
{
P4=digitalRead(A1);
P3=digitalRead(A2);
P2=digitalRead(A3);
P1=digitalRead(A4);

if (P1==pressed)
{
pStatus = 1;
}

if (P2==pressed)
{
pStatus = 0;
}

if (P1==pressed)
{
lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(6,0);
lcd.print("ON");
digitalWrite(LED1,ON);
}

if (P2==pressed)
{
lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(6,0);
Chapter 6: Lab Activity 3 (Group 3)

lcd.print("OFF");
digitalWrite(LED1,OFF);

lcd.setCursor(6,1);
lcd.print(" ");
lcd.setCursor(6,1);
lcd.print("OFF");
digitalWrite(LED2,OFF);
digitalWrite(LED3,OFF);
}

if (P3==pressed && pStatus==1)


{
lcd.setCursor(6,1);
lcd.print(" ");
lcd.setCursor(6,1);
lcd.print("FORWARD");
digitalWrite(LED2,ON);
digitalWrite(LED3,OFF);
}

if (P4==pressed && pStatus==1)


{
lcd.setCursor(6,1);
lcd.print(" ");
lcd.setCursor(6,1);
lcd.print("REVERSED");
digitalWrite(LED2,OFF);
digitalWrite(LED3,ON);
}
}

You might also like