I have created a clock using a arduino and LCD display. The clock itself works just fine but i wanted to have a way to change the time without changing the numbers in the code itself. I ended up with this:
void change() {
buttonh=digitalRead(A0, INPUT);
if (buttonh=HIGH); {
++hour;
}
(I haven't created the minute yet because i wanted to troubleshot this first)
When i run it it just changes the hour at the same rate as the seconds, i tried putting the ++hour; into else aswell but i still dont get any response from the button.
I tested the cabling (or whatever you call it) with this code:
int buttonh;
void setup() {
pinMode(A0, INPUT);
pinMode(A1, OUTPUT);
}
void loop() {
buttonh=digitalRead(A0);
digitalWrite(A1, buttonh);
}
With this code a LED connected to A1 lights up whenever i press the button.
I would really appretiate any help as ive been trying to fix this by myself for a long time without any results.
Here is the entire code:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int sec2 = 0;
int sec = 0;
int minute = 0;
int hour = 10;
int plush;
int plusm;
int buttonh;
int buttonm;
void setup() {
lcd.begin(16,2);
pinMode(A0, INPUT);
}
void loop() {
change();
lcd.clear();
if (sec2 >5) {
sec2 = 0;
}
if (sec < 59) {
++sec;
}
else {
sec = 0;
++minute;
}
if (minute < 59) {
}
else {
minute = 0;
++hour;
}
if (hour < 23) {
}
else {
hour = 0;
}
lcd.setCursor(0,1);
lcd.print(hour);
lcd.setCursor(2,1);
lcd.print(":");
lcd.setCursor(3,1);
lcd.print(minute);
lcd.setCursor(5,1);
lcd.print(":");
lcd.setCursor(6,1);
lcd.print(sec);
change();
if (hour >5) {
if (sec2 >2) {
lcd.setCursor(0,0);
lcd.print("Good morning!");
delay(500);
}
else {
lcd.setCursor(0,0);
lcd.print("Have a nice day!");
delay(500);
}
}
if (hour <6) {
if (sec2 >2) {
lcd.setCursor(0,0);
lcd.print("Go to sleep!");
delay(500);
}
else {
lcd.setCursor(0,0);
lcd.print("I mean it!");
delay(500);
}
}
if (hour >11) {
if (sec2 > 2) {
lcd.setCursor(0,0);
lcd.print("Good morning!");
delay(500);
}
else {
lcd.setCursor(0,0);
lcd.print("Have a nice day!");
delay(500);
}
}
if (hour >13) {
if (sec2 > 2) {
lcd.setCursor(0,0);
lcd.print("Good afternoon!");
delay(500);
}
else {
delay(500);
}
}
if (hour >18) {
if (sec2 > 2) {
lcd.setCursor(0,0);
lcd.print("Good evening!");
delay(500);
}
else {
lcd.setCursor(0,0);
lcd.print("");
delay(500);
}
}
if (hour >23) {
if (sec2 >2) {
lcd.setCursor(0,0);
lcd.print("Good night!");
delay(500);
}
else {
lcd.setCursor(0,0);
lcd.print("");
delay(500);
}
}
delay(500);
++sec2;
buttonh = 0;
}
void change() {
buttonh=digitalRead(A0, INPUT);
if (buttonh=HIGH); {
++hour
}
}
}