Errors in my program.

Hello everyone, i'm currently doing a program that will allow a remote control to well....control a Robot with different inputs.

However i'm faced with differents errors, could you help me resolve them?

Here is the code (the text is in french):

#include "IRemote.h"
IRsend emission_ir; //Crée une instance.

//*********************************************** Attribution des valeurs héxadécimales pour les boutons.
const uint16_t BUTTON_POWER = 0x10EFD827;
const uint16_t BUTTON_A = 0x10EFF807;
const uint16_t BUTTON_B = 0x10EF7887;
const uint16_t BUTTON_C = 0x10EF58A7;
const uint16_t BUTTON_UP = 0x10EFA05F;
const uint16_t BUTTON_DOWN = 0x10EF00FF;

//*********************************************** Définition de l'oscillation, cadence, fréquence, alimentation et du récepteur.
#define LED1 8 // Oscillation.
#define LED2 9 // Cadence.
#define LED3 10 // Fréquence.
#define LED4 11 // Alimentation.
#define RECV_PIN 12 // Récepteur.


void setup()
{
  pinMode(8, OUTPUT); // Ajoute l'alimentation comme sortie.
  pinMode(9, OUTPUT); // Ajoute la cadence comme sortie.
  pinMode(10, OUTPUT); // Ajoute la fréquence comme sortie.
  pinMode(11, OUTPUT); // Ajoute l'alimentation comme sortie.
  pinMode(12, INPUT); // Ajoute le Récepteur comme entrée.
  
  Serial.begin(9600); // Débug.
  IRrecv enableIRIN(); // Allume le récepteur.
}

void loop()
{
  
//********************************************** Bouton d'allumage.  
  if (BUTTON_POWER, HIGH)
  {
    digitalRead (LED4 == 0);
    {
      emission_ir.sendRC5 (BUTTON_POWER >1, 32);
      return;
    }
    
    else digitalRead (LED4 == 1);
    {
      emission_ir.sendRC5 (BUTTON_POWER <1, 32);
      return;
    }
  }

//*********************************************** Oscillation Bouton A.
  if (BUTTON_A, HIGH)
  {
    if (BUTTON_UP, HIGH);
    {
      digitalRead (BUTTON_UP, HIGH); // Augmenter l'oscillation.
      digitalWrite (LED1, HIGH);
      emission_ir.sendRC5 (BUTTON_A >1, 32);
      return;
    }
    
    else
    {
      digitalRead (BUTTON_DOWN, HIGH); // Ralentir l'oscillation.
      digitalWrite (LED1, LOW);
      emission_ir.sendRC5 (BUTTON_A <1, 32);
      return;
    }
  }

//*********************************************** Cadence Bouton B.
  else if (BUTTON_B, HIGH)
  {
    if (BUTTON_UP, HIGH);
    {
      digitalRead (BUTTON_UP, HIGH); // Augmenter la cadence.
      digitalWrite (LED2, HIGH);
      emission_ir.sendRC5 (BUTTON_B >1, 32);
      return;
    }
    
    else
    {
      digitalRead (BUTTON_DOWN, HIGH); // Ralentir la cadence.
      digitalWrite (LED2, LOW);
      emission_ir.sendRC5 (BUTTON_B <1, 32);
      return;
    }
  }
  
//************************************************* Fréquence Bouton C.
  else if (BUTTON_C, HIGH)
  {
    if (BUTTON_UP, HIGH);
    {
      digitalRead (BUTTON_UP, HIGH); // Augmenter la Fréquence.
      digitalWrite (LED3, HIGH);
      emission_ir.sendRC5 (BUTTON_C >1, 32);
      return;
    }
    
    else
    {
      digitalRead (BUTTON_DOWN, HIGH); // Ralentir la fréquence.
      digitalWrite (LED3, LOW);
      emission_ir.sendRC5 (BUTTON_C <1, 32);
      return;
    }
  }
  
  IRrecv resume(); // Reception de la prochaine valeur.
}

I'm also using IRemote.h with this program. :slight_smile:

#ifndef IRremote_h
#define IRremote_h

// The following are compile-time library options.
// If you change them, recompile the library.
// If DEBUG is defined, a lot of debugging output will be printed during decoding.
// TEST must be defined for the IRtest unittests to work.  It will make some
// methods virtual, which will be slightly slower, which is why it is optional.
//#define DEBUG
// #define TEST

// Results returned from the decoder
class decode_results {
public:
  int decode_type; // NEC, SONY, RC5, UNKNOWN
  union { // This is used for decoding Panasonic and Sharp data
    unsigned int panasonicAddress;
    unsigned int sharpAddress;
  };
  unsigned long value; // Decoded value
  int bits; // Number of bits in decoded value
  volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
  int rawlen; // Number of records in rawbuf.
};

// Send types
#define IRsendNEC
#define IRsendSONY
#define IRsendRC5
#define IRsendRC6
#define IRsendDISH
#define IRsendSHARP
#define IRsendPANASONIC
#define IRsendJVC
#define IRsendSANYO
#define IRsendMITSUBISHI
#define IRsendSAMSUNG
#define IRsendRAW

// Values for decode_type
#define NEC 1
#define SONY 2
#define RC5 3
#define RC6 4
#define DISH 5
#define SHARP 6
#define PANASONIC 7
#define JVC 8
#define SANYO 9
#define MITSUBISHI 10
#define SAMSUNG 11
#define LG 12
#define WHYNTER 13
#define AIWA_RC_T501 14
#define UNKNOWN -1

// Decoded value for NEC when a repeat code is received
#define REPEAT 0xffffffff

// main class for receiving IR
class IRrecv
{
public:
  IRrecv(int recvpin);
  void blink13(int blinkflag);
  int decode(decode_results *results);
  void enableIRIn();
  void resume();
private:
  // These are called by decode
  int getRClevel(decode_results *results, int *offset, int *used, int t1);
#ifdef NEC
  long decodeNEC(decode_results *results);
#endif
#ifdef SONY
  long decodeSony(decode_results *results);
#endif
#ifdef SANYO
  long decodeSanyo(decode_results *results);
#endif
#ifdef MITSUBISHI
  long decodeMitsubishi(decode_results *results);
#endif
#ifdef RC5
  long decodeRC5(decode_results *results);
#endif
#ifdef RC6
  long decodeRC6(decode_results *results);
#endif
#ifdef PANASONIC
  long decodePanasonic(decode_results *results);
#endif
#ifdef LG
  long decodeLG(decode_results *results);
#endif
#ifdef JVC
  long decodeJVC(decode_results *results);
#endif
#ifdef SAMSUNG
  long decodeSAMSUNG(decode_results *results);
#endif

#ifdef WHYNTER
  long decodeWhynter(decode_results *results);
#endif

#ifdef AIWA_RC_T501
  long decodeAiwaRCT501(decode_results *results);
#endif

  long decodeHash(decode_results *results);
  int compare(unsigned int oldval, unsigned int newval);

} ;

// Only used for testing; can remove virtual for shorter code
#ifdef TEST
#define VIRTUAL virtual
#else
#define VIRTUAL
#endif

class IRsend
{
public:
  IRsend() {}
  void sendRaw(unsigned int buf[], int len, int hz);
  void sendRC5(unsigned long data, int nbits);
  void sendRC6(unsigned long data, int nbits);

#ifdef WHYNTER
  void sendWhynter(unsigned long data, int nbits);
#endif
#ifdef NEC 
  void sendNEC(unsigned long data, int nbits);
#endif
#ifdef SONY 
  void sendSony(unsigned long data, int nbits);
  // Neither Sanyo nor Mitsubishi send is implemented yet
  //  void sendSanyo(unsigned long data, int nbits);
  //  void sendMitsubishi(unsigned long data, int nbits);
#endif

#ifdef DISH 
  void sendDISH(unsigned long data, int nbits);
#endif
#ifdef SHARP
  void sendSharp(unsigned int address, unsigned int command);
  void sendSharpRaw(unsigned long data, int nbits);
#endif
#ifdef IRsendSHARP
  void sendSharp(unsigned long data, int nbits);
#endif
#ifdef PANASONIC
  void sendPanasonic(unsigned int address, unsigned long data);
#endif
#ifdef JVC
  void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does.
  void sendAiwaRCT501(int code);
  // private:
#endif
#ifdef SAMSUNG 
  void sendSAMSUNG(unsigned long data, int nbits);
#endif
  void enableIROut(int khz);
  VIRTUAL void mark(int usec);
  VIRTUAL void space(int usec);
} ;

// Some useful constants

#define USECPERTICK 50  // microseconds per clock interrupt tick
#define RAWBUF 100 // Length of raw duration buffer

// Marks tend to be 100us too long, and spaces 100us too short
// when received due to sensor lag.
#define MARK_EXCESS 100

#endif

Thanks you in advance. :wink:

However i'm faced with differents errors,

And those errors are?

  if (BUTTON_POWER, HIGH)

This will not do what you think it does. What you probably meant is

  if (BUTTON_POWER == HIGH)
    digitalRead (LED4 == 0);
    {
      emission_ir.sendRC5 (BUTTON_POWER >1, 32);
      return;
    }
    
    else digitalRead (LED4 == 1);
    {
      emission_ir.sendRC5 (BUTTON_POWER <1, 32);
      return;
    }

This is not valid C++. What you probably meant was

    if(digitalRead (LED4) == 0)
    {
      emission_ir.sendRC5 (BUTTON_POWER >1, 32);
      return;
    }
    else if(digitalRead (LED4) == 1)
    {
      emission_ir.sendRC5 (BUTTON_POWER <1, 32);
      return;
    }

Sorry, the errors are:

Debug.ino: In function 'void loop()':
Debug:44: error: expected `}' before 'else'
Debug.ino: At global scope:
Debug:52: error: expected unqualified-id before 'if'

Forgot to note them, i am very tired :frowning:

What you probably meant is

Since BUTTON_POWER is defined as 0x10EFD827, I'm guessing not.

PaulMurrayCbr:
This is not valid C++. What you probably meant was

What i want to do is create a remote control, or at least the program, here is the remote i'm using: https://cdn.sparkfun.com/assets/5/2/5/4/e/524c5cf4757b7fe9068b4568.png

In this program, i tried to attribute the A button to the oscillation of the Robot so that afterwards if you press up or down, it increases or decreases. This is the same thing with B and C buttons, but these represents the frequency and the cadence of the robot.
As for the Power button, i represented it as the LED4. ???

Some general comments:

  • Have a look at this site which explains IR basics very well. http://www.sbprojects.com/knowledge/ir/
  • The remote probably uses the NEC IR protocol. Beware that if you keep the button pressed you will get a special repeat signal after the first, which will not decode as the original number, in IRremote or IRLib.
  • I suggest you work thru all of the examples provided with the library first, so that you get more familiar with it, IR & Arduino code. Then you can adjust them (examples) bit by bit to match your needs.