Exit Status 1? I don't know how to fix this

#include "mbed.h"

mbed::DigitalOut led(LED1);
mbed::PwmOut MotorLPwm(P0_27);
mbed::DigitalOut MotorLDir(P0_4);
mbed::PwmOut MotorRPwm(P1_2);
mbed::DigitalOut MotorRDir(P0_5);

//variable declarations
const int ultraPing = D6;
long duration, centimetres; //establish variable for ping time and distance in cm
int Orient = 1;
bool NClear, EClear, SClear, WClear;      //variable determining if directions are clear
int VMoves = 0;

int moves[100];
byte arrayIndex = 0;
//create an array of moves for red thread
//depending on the robot's orientation, the array will contain numbers as follows
//North 1 unit - 1
//North 0.25 unit - 1.25
//East 1 unit - 2
//East .25 unit - 2.25
//South 1 unit - 3
//South .25 unit - 3.25
//West 1 unit - 4
//West .25 unit - 4.25
//First input, used to indicate completion



//movement and conversion functions
long microsecondsToCentimetres(long microseconds){
  return microseconds / 29 / 2;
}

void moveup() {
  //move forward one unit
  MotorLDir = 0;
  MotorLPwm = 0.252;
  MotorRDir = 1;
  MotorRPwm = 0.5;
  led = 1;
  delay(1050);
  MotorLPwm = 0;
  MotorRPwm = 0;
  led = 0;
  if (Orient == 1){
    VMoves = VMoves += 1;
    arrayIndex++;
    moves[arrayIndex] = 1;
  } else if (Orient == 2){
    arrayIndex++;
    moves[arrayIndex] = 2;
  } else if (Orient == 3){
    VMoves = VMoves -= 1;
    arrayIndex++;
    moves[arrayIndex] = 3;
  } else if (Orient == 4){
    arrayIndex++;
    moves[arrayIndex] = 4;
  }
}



void shuffle()  {
    //move forward a fraction of a unit, for if only forward is applicable but wall is close
  MotorLDir = 0;
  MotorLPwm = 0.252;
  MotorRDir = 1;
  MotorRPwm = 0.5;
  led = 1;
  delay(262);
  MotorLPwm = 0;
  MotorRPwm = 0;
  led = 0;
  if (Orient == 1){
    VMoves = VMoves += 0.25;
    arrayIndex++;
    moves[arrayIndex] = 1.25;
  } else if (Orient == 2){
    arrayIndex++;
    moves[arrayIndex] = 2.25;
  } else if (Orient == 3){
    VMoves = VMoves -= 0.25;
    arrayIndex++;
    moves[arrayIndex] = 3.25;
  } else if (Orient == 4){
    arrayIndex++;
    moves[arrayIndex] = 4.25;
  }
}

void turnleft() {
  //turn 90 degrees left
  MotorLDir = 1;
  MotorLPwm = 0.252;
  MotorRDir = 1;
  MotorRPwm = 0.5;
  led = 1;
  delay(975);        
  MotorLPwm = 0;
  MotorRPwm = 0;
  led = 0;
  Orient = Orient - 1;
  if (Orient = 0){
    Orient = 4;
  } else if (Orient = 5){
      Orient = 1;
  }

}

void turnright() {
  MotorLDir = 0;
  MotorLPwm = 0.252;
  MotorRDir = 0;
  MotorRPwm = 0.5;
  led = 1;
  delay(975);
  MotorLPwm = 0;
  MotorRPwm = 0;
  led = 0;
  Orient = Orient + 1;
  if (Orient = 0){
    Orient = 4;
  } else if (Orient = 5){
      Orient = 1;
  }
}

void backstep() {
  //same as shuffle but in reverse, to get away from walls
  MotorLDir = 1;
  MotorLPwm = 0.252;
  MotorRDir = 0;
  MotorRPwm = 0.5;
  delay(262);
  MotorLPwm = 0;
  MotorRPwm = 0;
  if (Orient == 1){
    VMoves = VMoves -= 0.25;
    arrayIndex++;
    moves[arrayIndex] = 3.25;
  } else if (Orient == 2){
    arrayIndex++;
    moves[arrayIndex] = 4.25;
  } else if (Orient == 3){
    VMoves = VMoves += 0.25;
    arrayIndex++;
    moves[arrayIndex] = 1.25;
  } else if (Orient == 4){
    arrayIndex++;
    moves[arrayIndex] = 2.25;
  }
}


void setup() {
  Serial.begin(9600);         //establish serial connection
  pinMode(LEDR, OUTPUT);      //initialise RGB LED for output
  pinMode(LEDG, OUTPUT);
  pinMode(LEDB, OUTPUT);
  moves[arrayIndex] = 10;
  // put your setup code here, to run once:
}

void measureDistance() {

  //measure distance
  pinMode(ultraPing, OUTPUT);
  digitalWrite(ultraPing, LOW);
  delayMicroseconds(2);
  digitalWrite(ultraPing, HIGH);
  delayMicroseconds(5);
  digitalWrite(ultraPing, LOW);
  
  pinMode(ultraPing, INPUT);
  duration = pulseIn(ultraPing, HIGH);

  centimetres = microsecondsToCentimetres(duration);
}


void backToStart() {
  delay(1000);
  while (Orient != 3){
    turnleft();
    delay(1000);
  }
  
  while (arrayIndex > 0){
    if ()
  }
}


void loop() {
  // put your main code here, to run repeatedly:
  if VMoves > 15.5 {                  //check if robot has reached far wall, using movement units. Will flash green and activate return algorithm if it has reached the end.
      digitalWrite(LEDR, HIGH);
      digitalWrite(LEDG, LOW);
      digitalWrite(LEDB, HIGH);
      delay(200);
      digitalWrite(LEDR, HIGH);
      digitalWrite(LEDG, HIGH);
      digitalWrite(LEDB, HIGH);
      backToStart();
  } else {
      digitalWrite(LEDR, LOW);
      digitalWrite(LEDG, HIGH);
      digitalWrite(LEDB, HIGH);
      delay(200);
      digitalWrite(LEDR, HIGH);
      digitalWrite(LEDG, HIGH);
      digitalWrite(LEDB, HIGH);
  }



//loop of all movements
  measureDistance();
  delay(250);
  if (centimetres >= 14)  {                   //Measure all 4 direction distances
    NClear = 1;
  } else if (8 <= centimetres <= 14) {
    shuffle();
  } else {
    NClear = 0;
  }
  turnleft();
  delay(250);
  measureDistance();
  delay(250);
  if (centimetres >= 14)  {
    WClear = 1;
  } else if (8 <= centimetres <= 14) {
    shuffle();
  } else {
    WClear = 0;
  }
  turnleft();
  delay(250);
  measureDistance();
  delay(250);
  if (centimetres >= 14)  {
    SClear = 1;
  } else if (8 <= centimetres <= 14) {
    shuffle();
  } else {
    SClear = 0;
  }
  turnleft();
  delay(250);
  measureDistance();
  delay(250);
  if (centimetres >= 14)  {
    EClear = 1;
  } else if (8 <= centimetres <= 14) {
    shuffle();
  } else {
    EClear = 0;
  }
  turnleft();
  delay(250);

  if (NClear = 1) {
    moveup();
  } else if ((NClear = 0) && (WClear = 1)) {
    turnleft();
    delay(500);
    moveup();
    delay(500);
    turnright();
  } else if ((NClear = 0) && (WClear = 0) && (EClear = 1))  {
    turnright();
    delay(500);
    moveup();
    delay(500);
    turnleft();
  } else if ((NClear = 0) && (WClear = 0) && (EClear = 0) && (SClear = 1)) ;
    backstep();
    delay(500);
    turnleft();
    delay(250); 
    turnleft();

  }






//print distance to serial monitor
  Serial.print(centimetres);
  Serial.print("cm");
  Serial.println();
In file included from C:\Users\MYNAME\AppData\Local\Temp\arduino\sketches\03B0F9497760549AE97E92DD1A9258E4\sketch\program-combination01.ino.cpp:1:0:
C:\Users\MYNAME\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.1.5\cores\arduino/Arduino.h:107:16: error: '_UART_USB_' does not name a type
 #define Serial _UART_USB_
                ^
C:\Users\MYNAME\Documents\Arduino\program-combination01\program-combination01.ino:267:3: note: in expansion of macro 'Serial'
   Serial.print(centimetres);
   ^
C:\Users\MYNAME\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.1.5\cores\arduino/Arduino.h:107:16: error: '_UART_USB_' does not name a type
 #define Serial _UART_USB_
                ^
C:\Users\MYNAME\Documents\Arduino\program-combination01\program-combination01.ino:268:3: note: in expansion of macro 'Serial'
   Serial.print("cm");
   ^
C:\Users\MYNAME\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\4.1.5\cores\arduino/Arduino.h:107:16: error: '_UART_USB_' does not name a type
 #define Serial _UART_USB_
                ^
C:\Users\MYNAME\Documents\Arduino\program-combination01\program-combination01.ino:269:3: note: in expansion of macro 'Serial'
   Serial.println();
   ^

exit status 1

Compilation error: exit status 1

Hi, I'm getting this error and it won't let me upload my code to my microcontroller. Please Help!

1 Like

Remove the image and paste your code in code tags (use the <CODE> button) and do the same with the error.

1 Like

Just a hunch but have you selected the correct board?

For which microcontroller are you compiling?

Yes, I have it plugged in and the dropdown menu at the top has selected it.

Arduino Nano 33 BLE

For a start, you should upgrade the boards package to the most recent version.

Did you write this code?

If not, where does it come from. Please provide a link.

There are some things I don't understand, and there are many errors.

Is there more in the sketch than what you posted?

Yes I wrote this code, yes I know it's messy.
But as far as I can tell the content of the code shouldn't be causing this error, no?

No that's the whole thing

I took a copy of your code, but there are so many errors. Aside from 20 or 30 rookie coding errors, you have an error that manifests in a system wide library throwing an error. Either you have selected the wrong board or some other fundamental error is happening.
Take a screen grab of the board dropdown as follows

Show us with a screen grab.

If you use auto format on your code, you will see that these are stray lines outside the loop() brackets. They are what is causing the error, and if you comment them out, the code compiles, but there are still many errors and warnings.

What is this?

while (arrayIndex > 0){
  if ()
  }

My goal is to work backwards through the array, so I’m stepping backwards from the last entry until it reaches the 0th entry, at which point it would stop.

How does the array index change from its initial value?

Does you code compile? What errors have you fixed?

Please post your latest code. Does it perform as you expect? If not, describe the problems in detail.

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