CLASSWORK:
LCD Print to Screen
#include <LiquidCrystal.h>
int time = 0;
int k;
LiquidCrystal lcd (8,9,4,5,6,7); //Initialize an LCD object, takes pin #'s as arguments
void setup() {
lcd.begin(16, 2); //Tell the arduino we have a 16n2 (COL, ROW) display
lcd.setCursor(0,1); //Tell the cursor where to be, (0,0)=ORIGIN top left
lcd.print("Prof Mason"); //Tell the LCD what to print out at the given location
}
void loop() {
lcd.setCursor(0,0);
lcd.print("DoomsDayIn T-");
for (k=time; k<=10; k++) {
lcd.setCursor(13,0);
lcd.print(k);
delay(1000);
}
}
LCD with Progress Bar
//LCD with Progress Bar
//Include the library code:
#include <LiquidCrystal.h>
//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//Create the progress bar characters
byte p20[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
};
byte p40[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
};
byte p60[8] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
};
byte p80[8] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
};
byte p100[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
void setup()
{
//Set up the LCDs number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("ENGR6 Display");
//Make progress characters
lcd.createChar(0, p20);
lcd.createChar(1, p40);
lcd.createChar(2, p60);
lcd.createChar(3, p80);
lcd.createChar(4, p100);
}
void loop()
{
//Move cursor to second line
lcd.setCursor(0,1);
//Clear the line each time it reaches the end
//with 16 " " (spaces)
lcd.print(" ");
//Iterate through each character on the second line
for (int i = 0; i<16; i++)
{
//Iterate through each progress value for each character
for (int j=0; j<5; j++)
{
lcd.setCursor(i, 1); //Move the cursor to this location
lcd.write(j); //Update progress bar
delay(100); //Wait
}
}
}
HOMEWORK:
LCD Temperature Radar (FAIL)
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int waitTime = 200;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("ENRG6 Display");
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
int tempValue = analogRead(A1);
// print out the value you read:
Serial.print(sensorValue);
Serial.print(" ");
Serial.println(tempValue);
delay(1); // delay in between reads
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
/*double Celsius=0.01, Rankine;
/* Computes the temperature in Rankine scale. */
/*Rankine = (Celsius + 273.15)*1.8;*/
switch (sensorValue) {
case 0: //RIGHT
lcd.print("CELSIUS");
delay(waitTime);
break;
case 720: //SELECT
lcd.print("DEGREES");
delay(waitTime);
break;
default:
lcd.print("DEFAULT!");
delay(waitTime);
}
}
No comments:
Post a Comment