Please help me solve a problem about using infrared remote control car

In this project, I need to make a remote control car, but I can only use the latest version of IR, and I don't know how to make the car read the code output from my remote control

//c++
#include <Servo.h>
#include <IRremote.h>  // 
When I use the above program, the compiler prompts me with
 In function `main':
46: undefined reference to `loop'
 error: ld returned 1 exit status


 exit status 1





//-------------------------------------------------------------------//
//*******************************************************************//
///
//set moto/
///

// Motor A connections
int enA = 5;
int in1 = 1;
int in2 = 2;
// Motor B connections
int enB = 6;
int in3 = 3;
int in4 = 4;

//-------------------------------------------------------------------//
//*******************************************************************//
///
//IR/
///

const byte IR_RECEIVE_PIN = 7; // 
decode_results results_7;    // 

/* DEFINITIONS */
#define COMMAND_STRING_MAX_LENGTH 15U

#define COMMAND_VALUE_MASK 0xFF0000
#define COMMAND_VALUE_OFFSET 16U
#define ADDRESS_VALUE_MASK 0xFFFF

#define LINE_FEED_VALUE 10U
#define CARRIAGE_RETURN_VALUE 13U

#define IR_SEND_PIN 13U


/* VARIABLES */
static char commandString[COMMAND_STRING_MAX_LENGTH];
static uint8_t commandStringLength;

/* PRIVATE FUNCTIONS */
static void ResetCommandString(void)
{
    memset(commandString, 0, sizeof(commandString[0]) * COMMAND_STRING_MAX_LENGTH);
    commandStringLength = 0;
}





//-------------------------------------------------------------------------//

void setup()
{
    Serial.begin(9600); //9600
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);   // 
     // Set all the motor control pins to outputs
    pinMode(enA, OUTPUT);
    pinMode(enB, OUTPUT);
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
    pinMode(in3, OUTPUT);
    pinMode(in4, OUTPUT);

    // Turn off motors - Initial state
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, LOW);
}


void directionControl() {
    // Set motors to maximum speed
    // For PWM maximum possible values are 0 to 255
    analogWrite(enA, 255);
    analogWrite(enB, 255);
    // Turn on motor A & B
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
    delay(2000);
}
void speedControl() {
    // Turn on motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);

    // Accelerate from zero to maximum speed
    for (int i = 0; i < 256; i++) {
        analogWrite(enA, i);
        analogWrite(enB, i);
        delay(20);
    }

    // Decelerate from maximum speed to zero
    for (int i = 255; i >= 0; --i)
    {
        analogWrite(enA, i);
        analogWrite(enB, i);
        delay(20);
    }

    // Now turn off motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, LOW);
}
/* Remote Control  Button Code */
#define BUTTON_CODE_1               0xEF10BF00  // Numbers can be used to select radio presets
#define BUTTON_CODE_2               0xEE11BF00
#define BUTTON_CODE_3               0xED12BF00
#define BUTTON_CODE_4               0xEB14BF00
#define BUTTON_CODE_5               0xEA15BF00
#define BUTTON_CODE_6               0xE916BF00
#define BUTTON_CODE_7               0xE718BF00
#define BUTTON_CODE_8               0xE619BF00
#define BUTTON_CODE_9               0xE51ABF00
#define BUTTON_CODE_0               0xF30CBF00     

static void sendNecCommand(uint32_t buttonCode, uint8_t repeats)
{
    uint16_t address = (buttonCode & ADDRESS_VALUE_MASK);
    uint8_t command = (buttonCode & COMMAND_VALUE_MASK) >> COMMAND_VALUE_OFFSET;

    IrSender.sendNEC(address, command, repeats);
    Serial.println("Command sent");
}
static void processCommandString(const char* command)
{
    if (strcmp(command, "BUTTON_CODE_2") == 0)
    {
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
        digitalWrite(in3, HIGH);
        digitalWrite(in4, LOW);
        delay(2000);
    }
}

You seem to have forgotten void loop() that the Arduino IDE requires.

1 Like

Your code is actually two functions called by the arduino. First it calls setup() so you can set the environment as you desire, then it calls loop() which is your main code. Both setup() and loop() are defined in the arduino main() code as function calls. If you miss one as you did you get that error you are asking about. loop() can be simply loop() {} where your porgram will stop and not do anything, there are examples of this type of programing in some of the libraries where it simply demonstrates part of the library.

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