NEED HALP! COUNTDOWN TIMER

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

it says theres an error on
void setFeedingTime() in r=key-48;
I tried erasing that line and i++; j++;

then 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”

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 - (HH*3600))/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;} *

  • }*

  • }*

  • }*

  • }*
    *} *
    On another post someone told me to avoid using strings, is there any other way around it?

You should use code tags when posting code because some characters in the code can be interpreted as display formatting characters

Here, you have the statement:

   r = key-48;

In the original sketch, it has:

  r[i] = key-48;

You should also include the full error message and not your own summary.

oh sorry, the original code already have the code tags you mentioned, must have removed it while i was copying onto this thread,

btw this is the full error message

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: “Arduino Uno”

sketch_may26a.ino: In function ‘void setFeedingTime()’:
sketch_may26a:69: error: ambiguous overload for ‘operator=’ in 'r = (((int)key) + -0x000000030)’
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/WString.h:86: note: candidates are: String& String::operator=(const String&)
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/WString.h:87: note: String& String::operator=(const char*)
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/WString.h:88: note: String& String::operator=(const __FlashStringHelper*)

Start by reading this. http://forum.arduino.cc/index.php/topic,148850.0.html especially section 7 on code tags. The code you have pasted in displays as corrupted and some array subscripts are missing.

Anyway, try changing this statement:

  r[i] = key-48;

to:

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

DUDE ! IT FRIGGIN' WORKS!!! THANKS A BUNCH MAN! DON'T KNOW HOW TO REPAY YOU :cry:

and apologies about the code tags, I'm new to this, Thanks a lot on that tooo

OK. Don't mention it.

Interestingly, the compiler appears to have done a rather unusual breakdown of:

r [ i ] = key-48; // r is String, key = char

and confused itself.

That statement does not appear to be ambiguous because '-' is not a String operator, but the statement has been decomposed to:

(((int)key) + -0x000000030)

and now it appears that it cannot distinguish between the String concatenation operator '+' and the numerical addition operator '+'

from what i understand string is a declaration that saves input from keypad into board? is there like any other alternative besides string? from what i've heard its quite troublesome.

oh and I realised one more problem.

In the beginning LCD supposed to display "Arduino Timer"
pushing the push button, there's supposed to be a statement that says "Set Feeding Time"
Then only it displays "HH:MM:SS", but the statement "Set Feeding Time" does not display.

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Set feeding Time");
  lcd.clear();
  lcd.print("HH:MM:SS");
  lcd.setCursor(0,1);

the statement "set feeding time" does not appear before the input on timer.

it directly goes to "HH:MM:SS"