/*
Display_Counter.ino - Example for displaying large numbers on LCD displays using the HD44780 driver.
Displays the number of seconds since last boot on the display.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD V0 pin to digital pin 9
* LCD backlight Anode pin to digital pin 10
Copyright (C) 2014 Sean Auffinger
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
const int lcdD7Pin = 7; // LCD D7 pin
const int lcdD6Pin = 6; // LCD D6 pin
const int lcdD5Pin = 5; // LCD D5 pin
const int lcdD4Pin = 4; // LCD D4 pin
const int lcdEPin = 9; // LCD E Pin
const int lcdRSPin = 8; // LCD RS pin
LiquidCrystal lcd(lcdRSPin, lcdEPin, lcdD4Pin, lcdD5Pin, lcdD6Pin, lcdD7Pin); // construct LCD object
BigNumbers bigNum(&lcd); // construct BigNumbers object, passing to it the name of our LCD object
void setup()
{
/*
The following 2 lines change the PWM frequency of digital pins 9 and 10.
On Arduino Uno, these pins are controlled by Timer1.
On Arduino MEGA2560, these pins are controlled by Timer2.
Use the line that you need and comment out the other.
See for more details.
*/
TCCR1B = TCCR1B & 0b11111000 | 0x01; // use for Arduino Uno
// TCCR2B = TCCR1B & 0b11111000 | 0x01; // use for Arduino Mega2560
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
analogWrite(9,50); // set LCD contrast with PWM - change this value if hard to read display
analogWrite(10,127); // set LCD backlight with PWM
lcd.begin(16,2); // setup LCD rows and columns
bigNum.begin(); // set up BigNumbers
lcd.clear(); // clear display
}
void loop()
{
lcd.setCursor(0,1);
lcd.print("Press Key:");
int x;
x = analogRead (0);
lcd.setCursor(10,1);
if (x < 60) {
lcd.print ("Right ");
delay(1000);
printdate();
}
else if (x < 200) {
lcd.print ("Up ");
delay(1000);
printtime();
}
else if (x < 400){
lcd.print ("Down ");
delay(1000);
printtemp();
}
else if (x < 600){
lcd.print ("Left ");
delay(1000);
printhumi();
}
else if (x < 800){
lcd.print ("Select");
delay(1000);
printpres();
}
}
void printdate() {
// DATE
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("MON");
for (int a = 0; a <= 12; a++) {
for (int b = 0; b <= 31; b++) {
bigNum.displayLargeInt(b, 3, 2, true);
bigNum.displayLargeInt(a, 10, 2, true);
delay(50);
}
}
delay(5000);
lcd.clear();
}
void printtime() {
// TIME
lcd.clear();
for (int a = 0; a <= 11; a++) {
for (int b = 0; b <= 59; b++) {
bigNum.displayLargeInt(a, 0, 2, false);
bigNum.displayLargeInt(b, 7, 2, true);
lcd.setCursor(6, 1);
lcd.print(".");
lcd.setCursor(6, 0);
lcd.print(".");
lcd.setCursor(14, 0);
lcd.print("Am");
lcd.setCursor(14, 1);
lcd.print("Pm");
}
}
delay(5000);
lcd.clear();
}
void printtemp() {
// TEMP
lcd.clear();
lcd.setCursor(14, 1);
lcd.print("\337C"); // Try \377 \337 \262 depending on your LCD chip
for (int a = 0; a <= 1000; a++) {
int currentTime = millis() / 100; // assigns the current time since boot in tenths of a second to currentTime
byte lastDigit = currentTime % 10;
currentTime = currentTime / 10;
bigNum.displayLargeInt(currentTime, 0, 3, false);
// print out the decimal point and the digit after it
lcd.setCursor(9, 1);
lcd.print(".");
lcd.print(lastDigit);
}
delay(5000);
lcd.clear();
}
void printhumi() {
// HUMIDITY
lcd.clear();
lcd.setCursor(14, 1);
lcd.print("%");
for (int a = 0; a <= 1000; a++) {
int currentTime = millis() / 100; // assigns the current time since boot in tenths of a second to currentTime
byte lastDigit = currentTime % 10;
currentTime = currentTime / 10;
bigNum.displayLargeInt(currentTime, 0, 3, false);
// print out the decimal point and the digit after it
lcd.setCursor(9, 1);
lcd.print(".");
lcd.print(lastDigit);
}
delay(5000);
lcd.clear();
}
void printpres() {
// PRESSURE
lcd.clear();
lcd.setCursor(13, 1);
lcd.print("hPa");
for (int a = 0; a <= 1000; a++) {
int currentTime = millis(); // assigns the current time since boot in tenths of a second to currentTime
bigNum.displayLargeInt(currentTime, 0, 4, false);
}
delay(5000);
lcd.clear();
}