Requirements:
Software:
1.ArduinoIDE download:https://www.arduino.cc/en/Main/Software
2.LiquidCrystal.h library download: https://github.com/arduino/Arduino/tree/master/libraries/LiquidCrystal
3.LCDKeypad.h library download: https://www.dfrobot.com/wiki/index.php/Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)
Hardware:
1.Arduino Uno
2.LCD Keypad
Cirduit Diagrams:
}
break;
case KEYPAD_SELECT:
{
set = 1;
}
}
setting %= 4;
printSetting();
hours%=24;
minutes %= 60;
seconds %= 60;
printTime();
// Wait one fifth of a second to complete
while(millis() % 200 != 0);
}
}
// Print the current setting
void printSetting() {
lcd.setCursor(0,1);
Cirduit Diagrams:
#define HOURS 1
#define MINUTES 2
#define SECONDS 3// The LCD screen
#define MINUTES 2
#define SECONDS 3// The LCD screen
LCDKeypad lcd;
unsigned int hours = 0;
unsigned int minutes = 0;
unsigned int seconds = 0;
unsigned int setting = 0;
unsigned int set = 0;
volatile byte pulseCount;
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16,2);
lcd.setCursor(5,0);
lcd.print("LEETs");
lcd.setCursor(4,1);
lcd.print("academy");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Coundown Timer");
lcd.setCursor(0,1);
lcd.print("Hours =");
pulseCount = 0;
}
void loop() {
if(set == 1)
stepDown();
// Print the time on the LCD
printTime();
// Listen for buttons for 1 second
unsigned int hours = 0;
unsigned int minutes = 0;
unsigned int seconds = 0;
unsigned int setting = 0;
unsigned int set = 0;
volatile byte pulseCount;
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16,2);
lcd.setCursor(5,0);
lcd.print("LEETs");
lcd.setCursor(4,1);
lcd.print("academy");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Coundown Timer");
lcd.setCursor(0,1);
lcd.print("Hours =");
pulseCount = 0;
}
void loop() {
if(set == 1)
stepDown();
// Print the time on the LCD
printTime();
// Listen for buttons for 1 second
buttonListen();
}
//-----------------TIMER METHODS------------
}
//-----------------TIMER METHODS------------
//-----------------BUTTONS-----------------------
void buttonListen() {
// Read the buttons five times in a second
for (int i = 0; i < 5; i++) {
// Read the buttons value
int button = lcd.button();
switch (button) {
// Right button was pushed
case KEYPAD_RIGHT:
setting++;
break;
// Left button was pushed
case KEYPAD_LEFT:
setting--;
break;
// Up button was pushed
case KEYPAD_UP:
{
set = 0;
switch (setting) {
case HOURS:
hours++;
break;
case MINUTES:
minutes++;
break;
case SECONDS:
seconds++;
}
}
break;
// Down button was pushed
case KEYPAD_DOWN:{
set = 0;
switch (setting) {
case HOURS:
hours--;
if (hours == -1) hours = 23;
break;
case MINUTES:
minutes--;
if (minutes == -1) minutes = 59;
break;
case SECONDS:
seconds--;
if (seconds == -1) seconds = 59;
}
void buttonListen() {
// Read the buttons five times in a second
for (int i = 0; i < 5; i++) {
// Read the buttons value
int button = lcd.button();
switch (button) {
// Right button was pushed
case KEYPAD_RIGHT:
setting++;
break;
// Left button was pushed
case KEYPAD_LEFT:
setting--;
break;
// Up button was pushed
case KEYPAD_UP:
{
set = 0;
switch (setting) {
case HOURS:
hours++;
break;
case MINUTES:
minutes++;
break;
case SECONDS:
seconds++;
}
}
break;
// Down button was pushed
case KEYPAD_DOWN:{
set = 0;
switch (setting) {
case HOURS:
hours--;
if (hours == -1) hours = 23;
break;
case MINUTES:
minutes--;
if (minutes == -1) minutes = 59;
break;
case SECONDS:
seconds--;
if (seconds == -1) seconds = 59;
}
}
break;
case KEYPAD_SELECT:
{
set = 1;
}
}
setting %= 4;
printSetting();
hours%=24;
minutes %= 60;
seconds %= 60;
printTime();
// Wait one fifth of a second to complete
while(millis() % 200 != 0);
}
}
// Print the current setting
void printSetting() {
lcd.setCursor(0,1);
switch (setting) {
case HOURS:
lcd.print("Hours ");
break;
case MINUTES:
lcd.print("Minutes");
break;
case SECONDS:
lcd.print("Seconds");
lcd.print("Hours ");
break;
case MINUTES:
lcd.print("Minutes");
break;
case SECONDS:
lcd.print("Seconds");
}
}
//-----------------STEP DOWN------------------
//if (seconds > 0)
void stepDown()
{
if (seconds > 0)
{
seconds -= 1;
}
else if (minutes > 0)
{
seconds = 59;
minutes -= 1;
}
else if (hours > 0)
{
minutes = 59;
hours -= 1;
}
}
// Print the time on the LCD
void printTime() {
// Set the cursor at the begining of the second row
lcd.setCursor(8,1);
char time[17];
sprintf(time, "%02i:%02i:%02i", hours, minutes, seconds);
lcd.print(time);
}
void pulseCounter()
{
pulseCount++;
}
}
//-----------------STEP DOWN------------------
//if (seconds > 0)
void stepDown()
{
if (seconds > 0)
{
seconds -= 1;
}
else if (minutes > 0)
{
seconds = 59;
minutes -= 1;
}
else if (hours > 0)
{
minutes = 59;
hours -= 1;
}
}
// Print the time on the LCD
void printTime() {
// Set the cursor at the begining of the second row
lcd.setCursor(8,1);
char time[17];
sprintf(time, "%02i:%02i:%02i", hours, minutes, seconds);
lcd.print(time);
}
void pulseCounter()
{
pulseCount++;
}
lcd has no member button.
ReplyDeleteDont waste time not working
ReplyDelete