My code is having some problems

hi,
i am dealing with some problems with my arduino code can you please help me?

this is the code:

#include <IRremote.hpp>
#define IR_RECEIVE_PIN 2

void setup()
{

  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
}

void loop() {
  if (IrReceiver.decode()) {
      Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); // Print "old" raw data
      IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line
      IrReceiver.printIRSendUsage(&Serial);   // Print the statement required to send this data
      
      IrReceiver.resume(); // Enable receiving of the next value
  }
 switch(Serial.print)
 {
 

case 0xFFE21D: Serial.println(" ch "); break;
case 0xFF22DD: Serial.println(" LEFT"); break;
case 0xFF02FD: Serial.println(" -OK-"); break;
case 0xFFC23D: Serial.println(" RIGHT"); break;
case 0xFFA857: Serial.println(" REVERSE"); break;
case 0xFF6897: Serial.println(" 1"); break;
case 0xFF9867: Serial.println(" 2"); break;
case 0xFFB04F: Serial.println(" 3"); break;
case 0xFF30CF: Serial.println(" 4"); break;
case 0xFF18E7: Serial.println(" 5"); break;
case 0xFF7A85: Serial.println(" 6"); break;
case 0xFF10EF: Serial.println(" 7"); break;
case 0xFF38C7: Serial.println(" 8"); break;
case 0xFF5AA5: Serial.println(" 9"); break;
case 0xFF42BD: Serial.println(" *"); break;
case 0xFF4AB5: Serial.println(" 0"); break;
case 0xFF52AD: Serial.println(" #"); break;
case 0xFFFFFFFF: Serial.println(" REPEAT");break;

default:
Serial.println(" other button ");




}// End Case

delay(500); // Do not get immediate repeat

} //END translateIR

and that is the error messeage:


can you please help me?

Welcome to the forum

 switch(Serial.print)

Exactly what are you trying to do here ?

The value used in the switch() command must be an integer. It rould seem that here it should be the value read from the IR receiver

  • Probably.

  • Elaborate some.

  • What’s this all about ?
    switch(Serial.print)

  • Always show us a good schematic of your proposed circuit.
    Show us good images of your ‘actual’ wiring.
    Give links to components.

it still doesnt work though i dont know

yes its for the switch(Serial.print)

the wiring is just 3 cables so i think that it doent matter

Hi @takis12456 ,

Welcome to the forum..

You know, there's no serial begin in setup??
quite a few mistakes..

here look this over..

#include <IRremote.hpp>
#define IR_RECEIVE_PIN 2

void setup()
{
  Serial.begin(115200);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
}

void loop() {

  int codeRecvd = -1;
  if (IrReceiver.decode()) {
    codeRecvd = IrReceiver.decodedIRData.command;
    Serial.print("Command:"); Serial.println(codeRecvd);

    IrReceiver.resume(); // Enable receiving of the next value
  }

  if (codeRecvd > 0) {
    switch (codeRecvd)
    {


      case 0xFFE21D: Serial.println(" ch "); break;
      case 0xFF22DD: Serial.println(" LEFT"); break;
      case 0xFF02FD: Serial.println(" -OK-"); break;
      case 0xFFC23D: Serial.println(" RIGHT"); break;
      case 0xFFA857: Serial.println(" REVERSE"); break;
      case 0xFF6897: Serial.println(" 1"); break;
      case 0xFF9867: Serial.println(" 2"); break;
      case 0xFFB04F: Serial.println(" 3"); break;
      case 0xFF30CF: Serial.println(" 4"); break;
      case 0xFF18E7: Serial.println(" 5"); break;
      case 0xFF7A85: Serial.println(" 6"); break;
      case 0xFF10EF: Serial.println(" 7"); break;
      case 0xFF38C7: Serial.println(" 8"); break;
      case 0xFF5AA5: Serial.println(" 9"); break;
      case 0xFF42BD: Serial.println(" *"); break;
      case 0xFF4AB5: Serial.println(" 0"); break;
      case 0xFF52AD: Serial.println(" #"); break;
      case 0xFFFFFFFF: Serial.println(" REPEAT"); break;

      default:
        Serial.println(" other button ");




    }// End Case
  }

  delay(500); // Do not get immediate repeat

} //END translateIR

just need to press buttons and fix values in case statement..

good luck.. ~q

  • This is a nonsense statement, it does nothing.

  • What you should be doing is getting the receive data into a variable.
    Then you would do your switch( . . . )

switch (rxVariable)
{
. . .
}
1 Like

Did you changed anything? Please show your revised code.

now thats ok thank you so much for helping me

thank you so much you solved my problem

1 Like

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