ambiguous overload for 'operator=' in 'r[i]=((int)key)+0x....)'

Greetings,

I’m a beginner in arduino, I got this coding off the internet on how to make a countdowntimer ;

Components used:
16x2 LCD
4x4keypad
potentiometer
push button
2 220ohm resistor
1 10kohm resistor
1 LED
1 Buzzer

I tried running the code, the display is as I wanted but when i input the value on LCD it doesnt count down but it says “Countdown begins” and redisplay “HH:MM:SS”

it says theres an error on
void setFeedingTime() in r*=key-48;*
I will really appreciate any sort of explanation and help
All credits to the original coder: Arduino Countdown Timer.
#include <LiquidCrystal.h>
#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
long int set1;
long int set2;
long int set3;
long int set4;
long int j;
String hours;
String minutes;
String seconds;
// Define the Keymap
char keys[ROWS][COLS] = {

  • {‘1’,‘2’,‘3’,‘A’},*
  • {‘4’,‘5’,‘6’,‘B’},*
  • {‘7’,‘8’,‘9’,‘C’},*
    _ {’*’,‘0’,’#’,‘D’}_
    };
    byte rowPins[ROWS] = { 6, 7, 8, 9 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins
    byte colPins[COLS] = { 10, 11, 12, 13 };// Connect keypad COL0, COL1 and COL2 to t
    Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    LiquidCrystal lcd(A0, A1, 5, 4, 3, 2); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
    int t1, t2, t3, t4, t5, t6;
    int r1, r2, r3;

boolean feed = true; // condition for alarm
char key;
String r[8];
void setFeedingTime()
{

  • feed = true;*

  • int i=0;*

  • lcd.clear();*

  • lcd.setCursor(0,0);*

  • lcd.print(“Set feeding Time”);*

  • lcd.clear();*

  • lcd.print(“HH:MM:SS”);*

  • lcd.setCursor(0,1);*

  • while(1){*

  • key = kpd.getKey();*

  • char j;*

  • if(key!=NO_KEY){*

  • lcd.setCursor(j,1);*

  • lcd.print(key);*

_ r = key-48;_
* i++;*
* j++;*
* if (j==2 || j == 5)*
* {*
* lcd.print(":"); j++;*
* }*
* delay(500);*
* }*
* if (key == ‘D’)*
* {key=0; break; }*
* }*
lcd.clear();
}

void setup()
{
* lcd.begin(16,2);*
* Serial.begin(9600);*
* pinMode(A0, OUTPUT);*
* pinMode(A1, OUTPUT);*
* pinMode(A3, INPUT);*
* pinMode(A4, OUTPUT);*
}

void loop()
{
* lcd.setCursor(0,0);*
* lcd.print(“Arduino Timer”);*
* //Serial.println(A3);*
* if (digitalRead(A3)==1) //*
* {*
* lcd.clear();*
* setFeedingTime();*
* for(int i = 0; i < 6; i++) // this for loop is used to get the value of the feeding time and print it serially*
* {*
_ Serial.print(r*);
Serial.println();
}*_

* hours = String (r[0]) + String (r[1]) ; //combining two separate int values of r[0] and r[1] into one string and save it to “hours”*
* minutes = String (r[2]) + String (r[3]) ; //combining two separate int values of r[2] and r[3] into one string and save it to “minutes”*
* seconds = String (r[4]) + String (r[5]) ; //combining two separate int values of r[4] and r[5] into one string and save it to “seconds”*

_ set1 = (hours.toInt()3600); //converting hours into seconds_
_ set2 = (minutes.toInt() * 60); //converting minutes into seconds_
_ set3 = seconds.toInt();
set4 = (hours.toInt() * 3600)+ (minutes.toInt() * 60) + seconds.toInt(); //adding set1, set2 and set3 together in set4_

_ Serial.print(“set4”);
Serial.print(set4);
Serial.println();
lcd.setCursor(0,0);
lcd.print(“Countdown begins”);
delay(1000);
lcd.clear();*_

* for(long int j = set4; j >= 0; j–) // this for loopis used to decrease the total time in seconds*
* {*
* Serial.println(j);*

* lcd.setCursor(0,0);*
* lcd.print(“HH:MM:SS”);*

* long int HH = j / 3600; // converting the remaining time into remaining hours*
* lcd.setCursor(0,1);*
* Serial.println(HH);*
* if (HH < 10) { lcd.print(‘0’); }*
* lcd.print(HH);*
* lcd.print(":");*

_ long int MM = (j - (HH3600))/60 ; //converting the remaining time into remaining minutes_
_ lcd.setCursor(3,1);
Serial.println(MM);
if (MM < 10) { lcd.print(‘0’); }
lcd.print(MM);
lcd.print(":");*_

_ long int SS = j - ((HH3600)+(MM60)); //converting the remaining time into remaining seconds_
* lcd.setCursor(6,1);*
* Serial.println(SS);*
* if (SS < 10) { lcd.print(‘0’); }*
* lcd.print(SS);*
* delay(1000);*
* if (digitalRead(A3)==1){break;}*
* if (j == 0)*

* {*
* lcd.clear();*
* lcd.setCursor(0,0);*
* lcd.print(“Timer Stop”);*
* lcd.setCursor(2,1);*
* lcd.print("-Ring-Ring-");*

* for(int k =0; k<= 100; k++) //this for loop is used for the buzzer to beep 100 time as the timer reaches zero*
* {*
* digitalWrite(A4,HIGH);*
* delay(300);*
* digitalWrite(A4,LOW); *
* delay(300);*
* if (digitalRead(A3)==1){break;} *
* }*
* }*
* }*
* }*
*} *
//I’ve also attached the code below
sketch_may25a.ino (3.97 KB)

You are misusing Strings. You also aren’t using code tags when you post code, see the how to use this forum post at the top every section.

First off, String class is evil. You should use it as little as possible, preferably not at all. When working with strings, use cstrings (null terminated character arrays), and avoid the heinous String class; the dynamic memory allocation it involves can cause hard to debug memory issues on devices with such small amounts of memory, and the popular ways of using it tend to make that worse

It looks like you’re taking an int value, trying to stuff it directly into a variable of String type… but then you read the values out of that array of strings (helpfully named “r” - name your variables in a way that helps to communicate their purpose) and convert them to strings. Why convert to a string if it already is one?

It looks to me like you meant to have r be an int datatype (which would be better programming practice), or maybe an array of chars…

Thanks for your reply, I'll look into it.
Btw when you say see how to use this forum post, is this what you meant?

when you say see how to use this forum post, is this what you meant?

No, the third sticky post at the top of the page helpfully named "How to use this forum - please read."

http://forum.arduino.cc/index.php?topic=149014.0

I see, Thanks !
Sorry for the inconvenience I'm new :cold_sweat:

Just an update on the problem above,
It turns out that the line

r[i] = key-48;

should be

r[i] = String (key-48);

Thanks guys for your help!