Click here to Skip to main content
14,579,188 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am getting a "expected unqualified-id before numeric constant" error
(note this is Arduino code)




also , the code isn't finished yet but if its compiled the error still shows


Im just simply creating a project that can control two motors and some leds

Thanks



//The pulseIn Function
#include <Servo.h> //Use the Servo librarey for generating PWM
Servo ESC1;
Servo ESC2;              //name the servo object, here ESC
byte PWM_PIN = A0;

//keypoint is on 1490 around
int pwm_value;

void setup() {
  //Coil 1
  pinMode(22, OUTPUT);
  pinMode(23, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(25, OUTPUT);
  //Coil 2
  pinMode(27, OUTPUT);
  pinMode(28, OUTPUT);
  pinMode(29, OUTPUT);
  pinMode(30, OUTPUT);
  //Coil 3
  pinMode(32, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(34, OUTPUT);
  pinMode(35, OUTPUT);

  pinMode(PWM_PIN, INPUT);
  Serial.begin(115200);
  ESC1.attach(8);
  ESC1.write(10);
  ESC2.attach(9);
  ESC2.write(10);
  delay(5000);
}
int val;
int num;

void loop() {
  do {

    switch (num) {
      case 1:

        break;

      case 2:

        break;

      case 3:

        break;

      case 4:

        break;

      case 5:

        break;

      case 6:

        break;


        num += 1;
        if (num > 6) {
          num = 1;
        }
    }

  }
  while (1 != 2);


}


//Case 1
void 1 loop() {

  digitalwrite(22, HIGH)
  digitalwrite(23, LOW)
  digitalwrite(24, LOW)
  digitalwrite(25, HIGH)

  digitalwrite(27, LOW)
  digitalwrite(28, HIGH)
  digitalwrite(29, HIGH)
  digitalwrite(30, LOW)

  digitalwrite(32, HIGH)
  digitalwrite(33, LOW)
  digitalwrite(34, LOW)
  digitalwrite(35, HIGH)


  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
  //val = map(pwm_value, 0, 1023, 0, 180);
  val = pwm_value;
  ESC1.write(val);
  ESC2.write(val);


}
//Case 2
void  2 First loop() {

  digitalwrite(22, HIGH)
  digitalwrite(23, LOW)
  digitalwrite(24, LOW)
  digitalwrite(25, HIGH)

  digitalwrite(27, HIGH)
  digitalwrite(28, LOW)
  digitalwrite(29, LOW)
  digitalwrite(30, HIGH)

  digitalwrite(32, LOW)
  digitalwrite(33, HIGH)
  digitalwrite(34, HIGH)
  digitalwrite(35, LOW)

  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
  //val = map(pwm_value, 0, 1023, 0, 180);
  val = pwm_value;
  ESC1.write(val);
  ESC2.write(val);


}
//Case 3
void 3 loop() {

  digitalwrite(22, HIGH)
  digitalwrite(23, LOW)
  digitalwrite(24, LOW)
  digitalwrite(25, HIGH)

  digitalwrite(27, HIGH)
  digitalwrite(28, LOW)
  digitalwrite(29, LOW)
  digitalwrite(30, HIGH)

  digitalwrite(32, LOW)
  digitalwrite(33, HIGH)
  digitalwrite(34, HIGH)
  digitalwrite(35, LOW)

  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
  //val = map(pwm_value, 0, 1023, 0, 180);
  val = pwm_value;
  ESC1.write(val);
  ESC2.write(val);


}
//Case 4
void 4 loop() {


  digitalwrite(22, LOW)
  digitalwrite(23, HIGH)
  digitalwrite(24, HIGH)
  digitalwrite(25, LOW)

  digitalwrite(27, HIGH)
  digitalwrite(28, LOW)
  digitalwrite(29, LOW)
  digitalwrite(30, HIGH)

  digitalwrite(32, HIGH)
  digitalwrite(33, LOW)
  digitalwrite(34, LOW)
  digitalwrite(35, HIGH)


  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
  //val = map(pwm_value, 0, 1023, 0, 180);
  val = pwm_value;
  ESC1.write(val);
  ESC2.write(val);


}
//Case 5
void 5 loop() {

  digitalwrite(22, HIGH)
  digitalwrite(23, LOW)
  digitalwrite(24, LOW)
  digitalwrite(25, HIGH)

  digitalwrite(27, LOW)
  digitalwrite(28, HIGH)
  digitalwrite(29, HIGH)
  digitalwrite(30, LOW)

  digitalwrite(32, HIGH)
  digitalwrite(33, LOW)
  digitalwrite(34, LOW)
  digitalwrite(35, HIGH)

  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
  //val = map(pwm_value, 0, 1023, 0, 180);
  val = pwm_value;
  ESC1.write(val);
  ESC2.write(val);


}
//Case 6
void 6 loop() {

  digitalwrite(22, LOW)
  digitalwrite(23, HIGH)
  digitalwrite(24, HIGH)
  digitalwrite(25, LOW)

  digitalwrite(27, HIGH)
  digitalwrite(28, LOW)
  digitalwrite(29, LOW)
  digitalwrite(30, HIGH)

  digitalwrite(32, HIGH)
  digitalwrite(33, LOW)
  digitalwrite(34, LOW)
  digitalwrite(35, HIGH)

  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
  //val = map(pwm_value, 0, 1023, 0, 180);
  val = pwm_value;
  ESC1.write(val);
  ESC2.write(val);


}


What I have tried:

I thought at first it was to do with the fact that the subroutine loops where numbers instead of starting with a character but the error has been found on the 6th subroutine
Posted
Updated 2-May-20 4:19am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

Name your methods void 1 loop, void 2 loop, ... correctly something like
void loop1()
void loop2()
etc.
and call them in your loop forever like this
void loop() {
  do {

    switch (num) {
      case 1:
        loop1();
        break;

      case 2:
        loop2();
        break;
...

I hope it helps.
   
Comments
Richard MacCutchan 2-May-20 11:21am
   
Exactly right, +5.
0x01AA 2-May-20 11:28am
   
Thank you very much
Rate this:
Please Sign up or sign in to vote.

Solution 1

Your code has several mistakes:

  • Is A0 a variable, constant or define? If not, you'd better write byte PWM_PIN = 0xA0;
  • while (1 != 2);: Your loop will never end, since one won't ever equal two.
  • void 1 loop, void 2 loop, etc.: all of these six method declarations are invalid. Why don't you write the body of those inside their respective case statements?
   
Comments
0x01AA 2-May-20 10:06am
   
A0 is a pin usually defined in pins_arduino.h
while (1!=2) I think is on purpose and is the loop forever
;)
phil.o 2-May-20 10:08am
   
while (FALSE) maybe?
0x01AA 2-May-20 10:12am
   
Uuups :-) I think more while (TRUE)
phil.o 2-May-20 10:16am
   
Oops ^^
HamzaMcBob 2-May-20 10:42am
   
YES THE Do while was meant to be infant …
I am not very confident with Arduino sorry about any errors

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100