IR Counter Incrementation

Hi,

Been working on a little counter for a IR remote button push to an LCD 16x2, the general principle of the program works and the display is outputting in the correct format, only issue is that it looks like the counter is immediately going to the clock speed of the board.

I only want it to increment once per press. You will see i have tried to implement state change detection, but I think I'm doing it wrong as this has not helped.

Advice welcome...

#include <LiquidCrystal.h>
#include <IRremote.h>

const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int long WibbLevel = 0;
int LastStatusSensor = 1;

//IR Reciever setup
const int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("Initialising...");
  delay(2000);
  lcd.clear();

  irrecv.enableIRIn();
  irrecv.blink13(true);
}

void loop() {
  Title();
  WibbCount();
}

void Title() {
  lcd.setCursor(0, 0);
  lcd.print("Wibble-O-Meter:");
}

void WibbCount() {
  lcd.setCursor(0, 1);
  lcd.print(WibbLevel);
  lcd.print(" MW/H");


  int StatusSensor = digitalRead(RECV_PIN);
  if (StatusSensor != LastStatusSensor) {
    if (irrecv.decode(&results)){
  
          if (results.value == 0XFFFFFFFF)
            results.value = WibbLevel;
          
          switch(results.value){
            case 0xFFA857:
            WibbLevel--;
            Serial.println(WibbLevel);
            break;
            case 0xFF629D:
            WibbLevel++;
            Serial.println(WibbLevel);
            break;
          }
          WibbLevel = results.value;
          irrecv.resume();
    }
    LastStatusSensor = StatusSensor;
  }
}

So close. Try moving this

LastStatusSensor = StatusSensor;

outside the if construct.

Post reinstated to maintain continuity.

Tried that change, no luck, I had moved it to be...

           WibbLevel++;
            Serial.println(WibbLevel);
            break;
          }
          WibbLevel = results.value;
          irrecv.resume();
    }
  }
 LastStatusSensor = StatusSensor;
}

Still no luck though...

Bit of a head scratcher for me.

I advise you to read the library's documentation.

You have to read the repetition flag, if it indicates repetition you ignore the reading and do not add or subtract anything from the counter.

What's the purpose of reading the IR pin directly? You'll get many pulses as long as a button is pressed on the IR remote. At least it's a bad (wrong) attempt of state change detection.

See if this code is what you need.

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