I wanted to make a coundtdown using lcd and Ir receiver, when i press 1 on the remote countdown starts from 0.60 to 0.00, and button 0 is for lcd.clear, but whenever i press 0 , after i have pressed 1 and coundown has started, it wont stop the countdown nor will it clear it, can someone help me to spot where i have made a mistake?
CODE:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
int receiver_pin = 2;
float i;
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x20, 16, 2);
IRrecv receiver(receiver_pin);
decode_results output;
#define code1 41565 // To start 1 minute countdown
#define clear0 39015 // to clear lcd
unsigned int value;
void setup()
{
// initialize the LCD
lcd.begin();
Serial.begin(9600);
receiver.enableIRIn();
// Turn on the blacklight
lcd.backlight();
}
void loop()
{
if (receiver.decode(&output)) {
value = output.value;
switch (value) {
case clear0:// clear lcd
lcd.clear();
break;
case code1:// prints 1 minute
lcd.clear();
oneminute();
break;
}
Serial.println(value);
receiver.resume();
}
}
int oneminute() { //1 minute function
for (i = 0.60; i > 0.00; i -= 0.01) { //reduces 0.01 from 0.60 everysecond
lcd.setCursor(0, 0);
lcd.print(i);
delay(1000);
}
}