display flashing and no "controls"

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)

In printTime():

 sprintf(time, "%02i:%02i:%02i:%02i:%02i:%02i:%02i:%02i"

I count 23 characters, plus a terminating null makes 24.

char time[17];

Oops.

hi,
thanks.
That solved one problem at least its not flashing anymore.
But now the backlight is constantly turned off and what is displayed still makes no sense to me :confused:
could anyone tell me if the code is even properly done? it feels kinda... whack..

Thanks again

Flo

Post code and detailed description and/or photos.

Hi,
code is in the first post, all that ive changed now is that 17 to a 24 for the char time at the very bottom of the code.

This is what the display looks like, i can change most of the "00" in the bottom row with the arrow keys but it still makes no sense what it actually changes.
SD card is just there to block the power LEDs light.

Thanks again

Flo

P.S. if the code is garbage, please just tell me

The LCD doesn't show up in your wiring diagram up there in the OP.

I'm confused about these variables:

#define HOURS 1
#define HOURS1 2
#define HOURS2 3
#define HOURS3 4
#define MINUTES 5
#define MINUTES1 6
#define MINUTES2 7
#define MINUTES3 8

First you use them as time points here:

 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");
    }

and that's what you're actually using to time your relays. But later you're using them as case labels somehow to set some other set of variables that you display but don't use here to time the relays.

Delta_G:
The LCD doesn't show up in your wiring diagram up there in the OP.

like i wrote in my OP, the LCD keypad shield is "plugged in " the usual way so i think its connected to A0 and D4-D10 if im not mistaken

regarding the variables, i didnt write the code, like i said.
I had someone write it for me and its not working as its supposed to be working and im trying to figure out if the mistake is on my side or his.

Crustcheese:
I had someone write it for me and its not working as its supposed to be working and im trying to figure out if the mistake is on my side or his.

You should talk to the person who wrote the code. It's crap.

thanks very much, that helped me a lot already.
I contacted the person and send him a link to this thread if he wants to take position on the case and explain himself or his code.
Thanks again, been really helpful :slight_smile:
appreciate it

You should talk to the person who wrote the code. It's crap.

Thanks for saying what I was thinking!