LCD Wont respond to IR Receiver signals

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

}

No specific mistake spotted. But your oneminute() function will take, um, one minute, during which time you aren't able to check an react to any input button pressing.

You need to look at "blink without delay", look in the example IDE sketches or google

blink without delay arduino

to see how to get rid of delay() as a means to keep time like this.

In this exact case, you could simply watch the button you interested in within the one minute loop that oneminute() uses.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.