_GUI_Control_Car code not working

I would like to fix this .... thank you in advance for your help.

#include <Adafruit_ZeroDMA.h>

#include <Adafruit_NeoMatrix_ZeroDMA.h>
#include <gamma.h>

#include <Adafruit_NeoMatrix_ZeroDMA.h>
#include <gamma.h>

#include <configureBT.h>

/**********************************************************************
Filename : APP Control UnoCar-B.ino
Auther : www.adeept.com
Modification: 2023/08/28
**********************************************************************/

#include "Adeept_Car_For_Arduino.h"
#include <Servo.h>

#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

float distance;
float midDist;
float leftDist;
float rightDist;
#define motor_speed 40
#define avoid_Dist 35 // cm
#define minDist 15 // cm
int Track_value = -2;

int value_angle;

SSD1306AsciiWire display;

int value;
int threshold = 40;
int value_Init;

#define Speed 50 // value:0-100
#define wheel_Steering 30
#define steering_Speed 50 // value:0-100
#define Ultra_wheel_Steering_L 13
#define Ultra_wheel_Steering_H 21
#define Ultra_steering_Speed 40
#define servo_Init 106
int deviation = 0;
int IR_mark = 0;
int control_num = 0;
int servo_Angle2 = 90;
int ws2812_flag= 0;
int Function_Stop_flag = 0;

const String Move_UP = "forward";
const String Move_Down = "backward";
const String Move_UD_Stop = "DS";
const String Move_Left = "turn_left";
const String Move_LR_Stop = "TS";
const String Move_Right = "turn_right";

const String Head_UP = "up";
const String Head_Down = "down";
const String Head_Left = "lookleft";
const String Head_Right = "lookright";
const String Head_Stop = "stop";

const String Ultrasonic_ON = "Ultra_Start";
const String Ultrasonic_OFF = "Ultra_Stop";

const String Line_Tracking_ON = "Tracking_Start";
const String Line_Tracking_OFF = "Tracking_Stop";

const String Light_Tracking_ON = "Light_Tracking";
const String Light_Tracking_OFF = "LightTrackingStop";

const String Follow_ON = "UltraFollow";
const String Follow_OFF = "UltraFollowStop";

String comdata = "";
// String text = "";
int judge;

void setup()
{
Serial.begin(115200); // set up a wifi serial communication baud rate 115200
RGB_Setup(); //RGB LED initialization
RGB_brightness(2); // value 0-10
All_RGB(250,0,0);// Set RGB LED color value.
Servo_Setup(); //Servo initialization
PCA9685_Servo_Setup(); //PCA9685 Servo initialization
Motor_Setup(); //Motor initialization
AllMotorStop();
Buzzer_Setup(); //Buzzer initialization
WS2812_Setup(); //WS2812 LED initialization
WS2812_Brightness(5); // value 0-10
Ultrasonic_Setup(); //Ultrasonic initialization
Photosensitive_Setup(); //Light line initialization
Tracking_Setup(); //Tracking Line initialization
// OLED_Setup(); //OLED initialization
Matrix_Setup();
Matrix_Clear();

Serial.println("AT+CWMODE=3\r\n");//set to softAP+station mode
delay(3000); //delay 4s
Serial.println("AT+CWSAP="MY_ESP8266_5","12345678",8,2\r\n"); //TCP Protocol, server IP addr, port
delay(1000); //delay 4s
Serial.println("AT+RST\r\n"); //reset wifi
delay(1000); //delay 4s
Serial.println("AT+CIPMUX=1\r\n");//set to multi-connection mode
delay(1000);
// Serial.println("AT+CIPSERVER=1,333\r\n");//set as server
Serial.println("AT+CIPSERVER=1,4000\r\n");//set as server
delay(1000);
Serial.println("AT+CIPSTO=7000\r\n");//keep the wifi connecting 7000 seconds
delay(1000);

WS2812ColorAll(255, 255,0); // Green
Servo_Angle(1, servo_Init);
Servo_Angle(2, servo_Angle2);
PCA9685_Servo_Angle(6, 0, 90);
PCA9685_Servo_Angle(7, 0, 90);
Buzzer_Silence();
// OLED_clear();
delay(1000);
All_RGB(0,0,0);// Set RGB LED color value.
WS2812ColorAll(0,0,0);

display.begin(&Adafruit128x64, 0x3C);
display.setFont(Adafruit5x7);

}

void loop()
{
while(Serial.available()>0)
{
comdata += char(Serial.read());
delay(1);
}
judgement();
control(judge);
}

void judgement(){
if (comdata.length() > 0){
if(comdata.endsWith(Move_UP)){//forward
judge=1;
Serial.println(comdata); //print received data.
}
else if(comdata.endsWith(Move_Down)){//backward
judge=2;
Serial.println(comdata);
}
else if(comdata.endsWith(Move_Left)){//left
judge=3;
Serial.println(comdata);
}
else if(comdata.endsWith(Move_Right)){//right.
judge=4;
Serial.println(comdata);
}
else if(comdata.endsWith(Move_UD_Stop)||comdata.endsWith(Move_LR_Stop)){//stop
judge=5;
Serial.println(comdata);
}
else if(comdata.endsWith(Head_Left)){//trun left
judge=6;
Serial.println(comdata);
}
else if(comdata.endsWith(Head_Right)){//trun right
judge=7;
Serial.println(comdata);
}
else if(comdata.endsWith(Head_Stop)){//stop servo rotation.
judge=8;
Serial.println(comdata);
}

    else if(comdata.endsWith(Ultrasonic_ON)){//avoid obstacles function.
      judge=9;
    Serial.println(comdata);
    }
    else if(comdata.endsWith(Ultrasonic_OFF)){//avoid obstacles function. bstart.
      judge=10;
    Serial.println(comdata);
    }

    else if(comdata.endsWith(Line_Tracking_ON)){//line tracking function.
      judge=11;
    Serial.println(comdata);
    }
    else if(comdata.endsWith(Line_Tracking_OFF)){//light tracking function. dstart
      judge=12;
    Serial.println(comdata);
    }
    else if(comdata.endsWith(Light_Tracking_ON)){//light tracking function.
      judge=13;
    Serial.println(comdata);
    }
    else if(comdata.endsWith(Light_Tracking_OFF)){//light tracking function. dstart
      judge=14;
    Serial.println(comdata);
    }
    else if(comdata.endsWith(Follow_ON)){//follow function.
      judge=15;
    Serial.println(comdata);
    }
    else if(comdata.endsWith(Follow_OFF)){//light tracking function. dstart
      judge=16;
    Serial.println(comdata);
    }
    

    comdata = "";
    delay(10);
}

}

void control(int value){
switch (value) {
case 1: // forward
Servo_Angle(1, servo_Init + deviation);
Motor(1, 1, motor_speed); //Motor1 forward
Motor(2, 1, motor_speed); //Motor2 forward
// control_num = 12;
All_RGB(0,255,0);
Matrix_up();
break;

case 2:  // Down, 
  Servo_Angle(1, servo_Init + deviation);
  Motor(1, -1, motor_speed); //Motor1 backward
  Motor(2, -1, motor_speed); //Motor2 backward
  // control_num = 13;
  All_RGB(255,0,0);
  Matrix_down();
  break;

case 3:  // left 
  Servo_Angle(1, servo_Init + deviation + wheel_Steering);  // left
  Motor(1, 1, motor_speed); 
  Motor(2, 1, motor_speed); 
  // control_num = 14;
  color(1, 0,255,0);
  Matrix_left();
  break;
  
case 4:  // right 
  Servo_Angle(1, servo_Init + deviation - wheel_Steering); // right
  Motor(1, 1, motor_speed); 
  Motor(2, 1, motor_speed); 
  // control_num = 15;
  color(2, 0,255,0);
  Matrix_right();
  break;

case 5: // stop
  Servo_Angle(1, servo_Init + deviation);
  Motor(1, 1, 0);
  Motor(2, 1, 0);
  // control_num = -1;
  All_RGB(0,0,0);
  Matrix_Clear();
  break; 

case 6:  // trun left 
  servo_Angle2 = servo_Angle2 + 1;
  if (servo_Angle2 >180){
    servo_Angle2 = 180;
  }
  Servo_Angle(2, servo_Angle2);
  // control_num = 15;
  delay(10);
  break;
case 7:  // trun right
  servo_Angle2 = servo_Angle2 - 1;
  if (servo_Angle2 < 0){
    servo_Angle2 = 0;
  }
  Servo_Angle(2, servo_Angle2);
  // control_num = 15;
  delay(10);
  break;

case 8:  // stop servo rotation.
  break;
  
case 9:
  Function_Stop_flag = 0;
  Avoid_Obstacles(); // Avoid Obstacles function
  break;

case 11:
  Function_Stop_flag = 0;
  Line_Tracking();  // Line Tracking function
  break;
case 13:
  Function_Stop_flag = 0;
  Light_Tracking();  // Light Tracking function
  break;
case 15:
  Function_Stop_flag = 0;
  Keep_Distance();  // Follow function
  break;

case 10:
  Servo_Angle(1, servo_Init + deviation);
  Motor(1, 1, 0);
  Motor(2, 1, 0);
  break;
case 12:
  Servo_Angle(1, servo_Init + deviation);
  Motor(1, 1, 0);
  Motor(2, 1, 0);
  break;
case 14:
  Servo_Angle(1, servo_Init + deviation);
  Motor(1, 1, 0);
  Motor(2, 1, 0);
  break;
case 16:
  Servo_Angle(1, servo_Init + deviation);
  Motor(1, 1, 0);
  Motor(2, 1, 0);
  break;

default:
    break;

}
}

int StopFunction(){
while(Serial.available()>0){
comdata += char(Serial.read());
delay(1);
}
if (comdata.length() > 0){
if(comdata.endsWith(Ultrasonic_OFF)){// Stop Avoid Obstacles function.
Function_Stop_flag = 1;
judge=10;
}
else if(comdata.endsWith(Line_Tracking_OFF)){ // Stop Line Tracking function.
Function_Stop_flag = 2;
judge=12;
}
else if(comdata.endsWith(Light_Tracking_OFF)){ // Stop Light Tracking function.
Function_Stop_flag = 3;
judge=14;
}
else if(comdata.endsWith(Follow_OFF)){ // Stop Follow function.
Function_Stop_flag = 4;
judge=16;
}
comdata = "";
delay(10);
}
}

void Avoid_Obstacles(){
while (1){
StopFunction();
if (Function_Stop_flag == 1){ // Press OK, stop function.
break;
}

Servo_Angle(2, servo_Init + deviation);
delay(80);
int a = GetDistance();
int b = GetDistance();
int c = GetDistance();
midDist = (a+b+c)/3;
Serial.print("Mid:");
Serial.println(midDist);
Motor(1,1,0); //Stop the car
Motor(2,1,0);

if (midDist > avoid_Dist){
    Servo_Angle(1, servo_Init + deviation);    // front wheel
    Motor(1,1,Speed); //forward
    Motor(2,1,Speed);
}
else if (midDist <= avoid_Dist){
    Servo_Angle(1, servo_Init + deviation);    // front wheel
    Motor(1,1,0); //Stop the car
    Motor(2,1,0);
    Servo_Angle(2, servo_Init + deviation - 60);    // left distance.
    delay(400);
    int a = GetDistance();
    int b = GetDistance();
    int c = GetDistance();
    leftDist = (a+b+c)/3;
    Serial.print("Left:");
    Serial.println(leftDist);
    Servo_Angle(2, servo_Init + deviation + 60);    // right distance.
    delay(400);
    a = GetDistance();
    b = GetDistance();
    c = GetDistance();
    rightDist = (a+b+c)/3;
    Serial.print("Right:");
    Serial.println(rightDist);
    Servo_Angle(2, servo_Init + deviation);    // back to mid.

  if ((leftDist < avoid_Dist)&&(rightDist < avoid_Dist)){ // Judgment left and right.
      if (leftDist >= rightDist){
        // There are obstacles on the right backward to the left. 
        // Servo_1_Angle(servo_Init + wheel_Steering + deviation); //turn left backward
        Servo_Angle(1, servo_Init + deviation + wheel_Steering);    // turn left backward
        Motor(1,-1,Speed); //backward
        Motor(2,-1,Speed);
        delay(500);
      }
      else{ //There are obstacles on the left.
        // Servo_1_Angle(servo_Init - wheel_Steering + deviation); //turn right backward
        Servo_Angle(1, servo_Init + deviation - wheel_Steering);    // turn right backward
        Motor(1,-1,Speed); //backward
        Motor(2,-1,Speed);
        delay(500);
      }
  }
  else if ((leftDist > avoid_Dist)&&(rightDist <= avoid_Dist)){
      if (midDist < minDist){ // Obstacle ahead
        // Servo_1_Angle(servo_Init+ deviation); // backward
        Servo_Angle(1, servo_Init + deviation);    // backward
        Motor(1,-1,Speed); 
        Motor(2,-1,Speed);
        delay(400);
      }
      // Servo_1_Angle(servo_Init + wheel_Steering + deviation); // turn left backward
      Servo_Angle(1, servo_Init + deviation + wheel_Steering);    // turn left backward
      Motor(1,-1,Speed); 
      Motor(2,-1,Speed);
      delay(500);
  }
  else if ((leftDist <= avoid_Dist) &&(rightDist > avoid_Dist)){ // There are obstacles on the left.
      if (midDist < minDist){ // Obstacle ahead
          // Servo_1_Angle(servo_Init + deviation); // backward
          Servo_Angle(1, servo_Init + deviation);    // backward
          Motor(1,-1,Speed); 
          Motor(2,-1,Speed);
          delay(500);
      }
      // Servo_1_Angle(servo_Init - wheel_Steering + deviation); //turn right backward
      Servo_Angle(1, servo_Init + deviation - wheel_Steering);    // turn right backward
      Motor(1,-1,Speed); //backward
      Motor(2,-1,Speed);
      delay(400);
  }
  else if ((leftDist >= avoid_Dist) &&( rightDist >= avoid_Dist)){
      if (leftDist > rightDist){ // The distance to the right is greater than the left
          if (midDist < minDist){
              // Servo_1_Angle(servo_Init+ deviation); // backward
              Servo_Angle(1, servo_Init + deviation);    // backward
              Motor(1,-1,Speed); 
              Motor(2,-1,Speed);
              delay(500);
          }
          // Servo_1_Angle(servo_Init + wheel_Steering + deviation); // turn left backward
          Servo_Angle(1, servo_Init + deviation + wheel_Steering);    // turn left backward
          Motor(1,-1,Speed); 
          Motor(2,-1,Speed);
          delay(400);
      }
      else{
          if (midDist < minDist){
              // Servo_1_Angle(servo_Init+ deviation); // backward
              Servo_Angle(1, servo_Init + deviation);    // backward
              Motor(1,-1,Speed); 
              Motor(2,-1,Speed);
              delay(500);
          }
          // Servo_1_Angle(servo_Init + wheel_Steering + deviation); // turn left backward
          Servo_Angle(1, servo_Init + deviation + wheel_Steering);    // turn left backward
          Motor(1,-1,Speed); 
          Motor(2,-1,Speed);
          delay(400);
    }
  }
}

// delay(100);
}
}

void Light_Tracking(){
value_Init = GetPhotosensitive();
while (1){
StopFunction();
if (Function_Stop_flag == 3){ // Press OK, stop function.
break;
}
value = GetPhotosensitive();
if (value < (value_Init - threshold)){
Servo_Angle(1, servo_Init + deviation + wheel_Steering);
Motor(1, 1, motor_speed);
Motor(2, 1, motor_speed);
Serial.print(value_Init);
Serial.print(":");
Serial.println(value);

}
else if (value > (value_Init + threshold)){
  Servo_Angle(1, servo_Init + deviation - wheel_Steering);
  Motor(1, 1, motor_speed); 
  Motor(2, 1, motor_speed);
  Serial.print(value_Init);
  Serial.print(":");
  Serial.println(value);
}

else if (abs(value - value_Init) < 10){
  // Servo_1_Angle(servo_Init);
  Servo_Angle(1, servo_Init + deviation);
  Motor(1, 1, 0);
  Motor(2, 1, 0);
  Serial.print(value_Init);
  Serial.print(":");
  Serial.println(value);
}
// else if (value - value_Init < 10){
//   // Servo_1_Angle(servo_Init);
//   Servo_Angle(1, servo_Init + deviation);
//   Motor(1, 1, 0);
//   Motor(2, 1, 0);
//   Serial.print(value_Init);
//   Serial.print(":");
//   Serial.println(value);
// }

else{
  if (value_Init - value > 0){
  value_angle = map((value_Init - value),10,150, 0,30);
  }
  else if (value_Init - value < 0){
    value_angle = map((value_Init - value),-150,-10, -30,0);
  }
  Servo_Angle(1, servo_Init + deviation + value_angle);

  Motor(1, 1, motor_speed); 
  Motor(2, 1, motor_speed);
}

}
}

void Line_Tracking(){
int value;
while (1){
StopFunction();
if (Function_Stop_flag == 2){ // Press OK, stop function.
break;
}
value = Track_Read(); //Read the value of the tracking module.
// Serial.println(value);
switch (value)
{
case 0: //000 stop
Servo_Angle(1, servo_Init + deviation); // mid
Motor(1, 1, 0);
Motor(2, 1, 0);
if (Track_value != 0){
display.clear();
display.set2X();
display.setCursor(30,0);
display.println("Stop\n");
display.setCursor(30,30);
display.println("0 0 0");
// display.display();
}
Track_value = 0;
break;

  case 1:   //010 forward
    Servo_Angle(1, servo_Init + deviation);    // mid
    Motor(1, 1, motor_speed); //Motor1 forward
    Motor(2, 1, motor_speed); //Motor2 forward
    if (Track_value != 2){
      
      display.clear();
      display.set2X();
      display.setCursor(30,0);
      display.println("Forward\n");
      display.setCursor(30,30);
      display.println("0 1 0");
    }
    Track_value = 2; 
    break;
  
  case 2:   //100 Left
    Servo_Angle(1, servo_Init + deviation + Ultra_wheel_Steering_H);    // left
    Motor(1, 1, motor_speed); 
    Motor(2, 1, motor_speed); 
    if (Track_value != 4){
      display.clear();
      display.set2X();
      display.setCursor(30,0);
      display.println("Left\n");
      display.setCursor(30,30);
      display.println("1 0 0");
    }
    Track_value = 4; 
    break;
    
  case 3:   //110 Left
    Servo_Angle(1, servo_Init + deviation + Ultra_wheel_Steering_L);    // left
    Motor(1, 1, motor_speed); 
    Motor(2, 1, motor_speed); 
    if (Track_value != 6){
      display.clear();
      display.set2X();
      display.setCursor(30,0);
      display.println("Left\n");
      display.setCursor(30,30);
      display.println("1 1 0");
    }
    Track_value = 6; 
    break;
    
  case 4:   //001 right
    Servo_Angle(1, servo_Init + deviation - Ultra_wheel_Steering_H);    // right
    Motor(1, 1, motor_speed); 
    Motor(2, 1, motor_speed); 
    if (Track_value != 1){
      display.clear();
      display.set2X();
      display.setCursor(30,0);
      display.println("Right\n");
      display.setCursor(30,30);
      display.println("0 0 1");
    }
    Track_value = 1; 
    break;
    
  case 5:   //011 right
    Servo_Angle(1, servo_Init + deviation - Ultra_wheel_Steering_L);    // right
    Motor(1, 1, motor_speed); 
    Motor(2, 1, motor_speed); 
    if (Track_value != 3){
      display.clear();
      display.set2X();
      display.setCursor(30,0);
      display.println("Right\n");
      display.setCursor(30,30);
      display.println("0 1 1");
    }
    Track_value = 3; 
    break;

  case 6:   //111 stop
    Servo_Angle(1, servo_Init + deviation);    // mid
    Motor(1, 1, 0); 
    Motor(2, 1, 0); 
    
    if (Track_value != 7){
      display.clear();
      display.set2X();
      display.setCursor(30,0);
      display.println("Stop\n");
      display.setCursor(30,30);
      display.println("1 1 1");
    }
    
  // Serial.println("444");
    Track_value = 7; 
    break;
  case 7:   //101 forward
    Servo_Angle(1, servo_Init + deviation);    // mid
    Motor(1, 1, motor_speed); //Motor1 forward
    Motor(2, 1, motor_speed); //Motor2 forward
    if (Track_value != 5){
      display.clear();
      display.set2X();
      display.setCursor(30,0);
      display.println("Forward\n");
      display.setCursor(30,30);
      display.println("1 0 1");
    }
    Track_value = 5; 
    break;
  default:
    break;
}

}
}

void Keep_Distance(){
Servo_Angle(2, servo_Angle2);
while (1){
StopFunction();
if (Function_Stop_flag == 4){ // Press OK, stop function.
break;
}
distance = GetDistance();
if (distance < 30){
Servo_Angle(1, servo_Init + deviation); // front wheel
Motor(1,-1,Speed); //forward
Motor(2,-1,Speed);
}
else if (distance > 40){
Servo_Angle(1, servo_Init + deviation); // front wheel
Motor(1,1,Speed); //forward
Motor(2,1,Speed);
}
else {
Motor(1,1,0); // stop
Motor(2,1,0);
}
delay(100);
}
}

```this is the error i get.

 #include <malloc.h> // memalign() function
          ^~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: exit status 1

````Use code tags to format code for the forum`

Your topic has been moved to the Programming category of the forum

I see that you ignored this suggestion

As to the error, please post the full error message from the IDE copied using the convenient button in the IDE. Please use code tags when posting it

Which Arduino board are you using ?

C:\Users\JOHN\Documents\Arduino\libraries\Adafruit_Zero_DMA_Library\Adafruit_ZeroDMA.cpp:30:10: fatal error: malloc.h: No such file or directory
 #include <malloc.h> // memalign() function
          ^~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: exit status 1
type or paste code here

Is this yet another "can you fix someone else's code for me" thread?

@borrao76 where did you get the code from and which Arduino board are you using ?

i got it from: Adeept Smart Car Kit(Compatible with Arduino IDE)

Adeept smart car and I am using Arduino uno

Please post your sketch in a new reply, using code tags when you do

This is the easiest way to tidy up the code and add the code tags

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

You copy/pasted badly on your other topic, and had wires mis-placed. Probably the same issues this topic. Check your work.

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