Hi,
I'm having troubles with my Arduino project/code.
I had someone code this for me and he cant figure out whats wrong.
The problem i encounter is that the LCD keypad shield back light flashes like every second or so and i cant do anything with the buttons.
He says its a hardware compatibility problem but i cant really believe that as the hardware is tested and working just fine.
can anyone who is more experienced than me have a look over the code and tell me if that code is even in working condition?
This is how everything is connected, the LCD shield is "plugged" into the arduino in the usual way.
Thanks very much in advance.
Im feeling kinda helpless right now, i dont want to pay for a not working code, but neither do i want to not pay for a properly done job just because my hardware is nuts.
P.S. the code is supposed to work as a timer for the reali board, so i can turn on/off lights at diffrent times of the day, setup should be done with the 5 button keypad
Thanks again
Flo
#include <DS3231.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>
#define HOURS 1
#define HOURS1 2
#define HOURS2 3
#define HOURS3 4
#define MINUTES 5
#define MINUTES1 6
#define MINUTES2 7
#define MINUTES3 8
#define Relay1 9
#define Relay2 10
DS3231 rtc(SDA, SCL);
Time t;
LCDKeypad lcd;
// Time Model
unsigned int hours = 0;
unsigned int hours1 = 0;
unsigned int hours2 = 0;
unsigned int hours3 = 0;
unsigned int minutes = 0;
unsigned int minutes1 = 0;
unsigned int minutes2 = 0;
unsigned int minutes3 = 0;
unsigned int setting = 0;
unsigned int setting1 = 0;
unsigned int setting2 = 0;
unsigned int setting3 = 0;
void setup() {
Serial.begin(115200);
rtc.begin();
// Set up the LCD's number of columns and rows:
lcd.begin(16,2);
lcd.clear();
// Set the cursor at the begining of the first row
lcd.setCursor(0,0);
// Print a text in the first row
lcd.print("Setting: Hours ");
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
}
void loop() {
t = rtc.getTime();
Serial.print(t.hour);
Serial.print(" hour(s), ");
Serial.print(t.min);
Serial.print(" minute(s)");
Serial.println(" ");
delay (1000);
// Increase the time model by one second
if(t.hour == HOURS && t.min == MINUTES){
digitalWrite(Relay1,HIGH);
Serial.println("LIGHT1 ON");
}
if(t.hour == HOURS1 && t.min == MINUTES1){
digitalWrite(Relay1,LOW);
Serial.println("LIGHT1 OFF");
}
if(t.hour == HOURS2 && t.min == MINUTES2){
digitalWrite(Relay1,HIGH);
Serial.println("LIGHT1 ON");
}
if(t.hour == HOURS3 && t.min == MINUTES3){
digitalWrite(Relay1,LOW);
Serial.println("LIGHT1 OFF");
}
// Increase the time model by one second
incTime();
// Print the time on the LCD
printTime();
// Listen for buttons for 1 second
buttonListen();
}
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:
switch (setting) {
case HOURS:
hours++;
break;
case MINUTES:
minutes++;
break;
}
break;
// Down button was pushed
case KEYPAD_DOWN:
switch (setting) {
case HOURS:
hours--;
if (hours == -1) hours = 23;
break;
case MINUTES:
minutes--;
if (minutes == -1) minutes = 59;
break;
}
}
switch (button) {
// Right button was pushed
case KEYPAD_RIGHT:
setting1++;
break;
// Left button was pushed
case KEYPAD_LEFT:
setting1--;
break;
// Up button was pushed
case KEYPAD_UP:
switch (setting1) {
case HOURS1:
hours1++;
break;
case MINUTES1:
minutes1++;
break;
}
break;
// Down button was pushed
case KEYPAD_DOWN:
switch (setting1) {
case HOURS1:
hours1--;
if (hours1 == -1) hours1 = 23;
break;
case MINUTES1:
minutes1--;
if (minutes1 == -1) minutes1 = 59;
break;
}
}
switch (button) {
// Right button was pushed
case KEYPAD_RIGHT:
setting2++;
break;
// Left button was pushed
case KEYPAD_LEFT:
setting2--;
break;
// Up button was pushed
case KEYPAD_UP:
switch (setting2) {
case HOURS2:
hours2++;
break;
case MINUTES2:
minutes2++;
break;
}
break;
// Down button was pushed
case KEYPAD_DOWN:
switch (setting2) {
case HOURS2:
hours2--;
if (hours2 == -1) hours2 = 23;
break;
case MINUTES2:
minutes2--;
if (minutes2 == -1) minutes2 = 59;
break;
}
}
// Read the buttons value
switch (button) {
// Right button was pushed
case KEYPAD_RIGHT:
setting3++;
break;
// Left button was pushed
case KEYPAD_LEFT:
setting3--;
break;
// Up button was pushed
case KEYPAD_UP:
switch (setting3) {
case HOURS3:
hours3++;
break;
case MINUTES3:
minutes3++;
break;
}
// Down button was pushed
case KEYPAD_DOWN:
switch (setting3) {
case HOURS3:
hours3--;
if (hours3 == -1) hours3 = 23;
break;
case MINUTES3:
minutes3--;
if (minutes3 == -1) minutes3 = 59;
break;
}
}
setting %= 4;
printSetting();
hours %= 24;
minutes %= 60;
printTime();
// Wait one fifth of a second to complete
while(millis() % 200 != 0);
}
}
// Print the current setting
void printSetting() {
lcd.setCursor(9,0);
switch (setting) {
case HOURS:
lcd.print("Hours ");
break;
case MINUTES:
lcd.print("Minutes");
break;
}
switch (setting1) {
case HOURS1:
lcd.print("Hours1 ");
break;
case MINUTES1:
lcd.print("Minutes1");
break;
}
switch (setting2) {
case HOURS2:
lcd.print("Hours2 ");
break;
case MINUTES2:
lcd.print("Minutes2");
break;
}
switch (setting3) {
case HOURS3:
lcd.print("Hours3 ");
break;
case MINUTES3:
lcd.print("Minutes3");
break;
}
}
// Increase the time model by one second
void incTime() {
if (minutes == 60) {
// Reset minutes
minutes = 0;
// Increase hours
hours++;
if (hours == 24) {
// Reset hours
hours = 0;
}
}
if (minutes1 == 60) {
// Reset minutes
minutes1 = 0;
// Increase hours
hours1++;
if (hours1 == 24) {
// Reset hours
hours1 = 0;
}
}
if (minutes2 == 60) {
// Reset minutes
minutes2 = 0;
// Increase hours
hours2++;
if (hours2 == 24) {
// Reset hours
hours2 = 0;
}
}
if (minutes3 == 60) {
// Reset minutes
minutes3 = 0;
// Increase hours
hours3++;
if (hours3 == 24) {
// Reset hours
hours3 = 0;
}
}
}
// Print the time on the LCD
void printTime() {
// Set the cursor at the begining of the second row
lcd.setCursor(0,1);
char time[17];
sprintf(time, "%02i:%02i:%02i:%02i:%02i:%02i:%02i:%02i",hours, minutes, hours1,minutes1,hours2,minutes2,hours3,minutes3);
lcd.print(time);
}
Timer_Relay.ino (6.82 KB)