HI all,
I’m new at Makeblock and I have already tried “TestInfraredReceiver” example in my Starter Kit 2. It works fine, since all remote control buttons are understood by the sketch and are shown correclty in the Monitor Serial. However, I have faced a couple of issues/doubts:
- Three different reads are needed to get the expected result
By adding “Serial.println(“Not recognized.”);” code in the “default” line of the switch statement, I have realized that 3 different reads are shown in the Monitor Serial (“Not recognized.”, “Not recognized.” and “Press Plus.”) whenever a button is pressed in the remote control (for example plus button). Only the third result is the expected one (Press Plus = 0x40) Could anybody explain to me why is that? What sequence does the IR decoder send to PORT_6? I expected only one read result and got 3 instead.
- “TestInfraredReceiver” example doesn’t work as expected when saving read value
I tried to save the read value in a variable called “code” and then to print and evaluate it by the switch statement. In other words I changed the following code from the example:
switch(infraredReceiverDecode.read())
By:
code = infraredReceiverDecode.read();
Serial.println(code, HEX);
switch(code)
However, this time the Serial Monitor doesn’t recognize the pressed button and shows 3 “Not recognized” results (0, FF, D0) when pressing plus button in the remote control.
Thank you very much in advance. Find my code below.
Cheers
#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
int code = 0;
MeInfraredReceiver infraredReceiverDecode(PORT_6);
void setup()
{
infraredReceiverDecode.begin();
Serial.begin(9600);
Serial.println("InfraredReceiverDecode Start!");
}
void loop()
{
if(infraredReceiverDecode.available())
{
code = infraredReceiverDecode.read();
Serial.println(code, HEX);
switch(code)
{
case IR_BUTTON_POWER: Serial.println("Press Power.");break;
case IR_BUTTON_MENU: Serial.println("Press Menu.");break;
case IR_BUTTON_TEST: Serial.println("Press Test.");break;
case IR_BUTTON_PLUS: Serial.println("Press Plus.");break;
case IR_BUTTON_RETURN: Serial.println("Press Return.");break;
case IR_BUTTON_PREVIOUS: Serial.println("Press Previous.");break;
case IR_BUTTON_PLAY: Serial.println("Press Play.");break;
case IR_BUTTON_NEXT: Serial.println("Press Next.");break;
case IR_BUTTON_MINUS: Serial.println("Press Minus.");break;
case IR_BUTTON_CLR: Serial.println("Press Clr.");break;
case IR_BUTTON_0: Serial.println("Press 0.");break;
case IR_BUTTON_1: Serial.println("Press 1.");break;
case IR_BUTTON_2: Serial.println("Press 2.");break;
case IR_BUTTON_3: Serial.println("Press 3.");break;
case IR_BUTTON_4: Serial.println("Press 4.");break;
case IR_BUTTON_5: Serial.println("Press 5.");break;
case IR_BUTTON_6: Serial.println("Press 6.");break;
case IR_BUTTON_7: Serial.println("Press 7.");break;
case IR_BUTTON_8: Serial.println("Press 8.");break;
case IR_BUTTON_9: Serial.println("Press 9.");break;
default:Serial.println("Not recognized");break;
}
}
}