3

I'm getting a "'Serial' does not name a type" error when this program is compiled. I need for the 8 channels of voltage to be displayed. I'm sure it's a simple fix, however I'm still learning Arduino programming. I thank you for your help.

int pin_Out_S0 = 8;
int pin_Out_S1 = 9;
int pin_Out_S2 = 10;
int pin_In_Mux1 = A0;
int Mux1_State[8] = {0};
//float Mux1_State[i] =0;
int RawValue=0;
float Voltage = 0;
void setup() {
  pinMode(pin_Out_S0, OUTPUT);
  pinMode(pin_Out_S1, OUTPUT);
  pinMode(pin_Out_S2, OUTPUT);
  pinMode(pin_In_Mux1, INPUT);
  Serial.begin(9600);
}

void loop() {
 RawValue = analogRead(pin_In_Mux1);
 Voltage = (RawValue * 5.0) / 1024; //scale the ADC
  updateMux1();
  //Serial.println(Mux1_State);
  for(int i = 0; i < 8; i ++) {
    if(i == 7) {
      Serial.println(Mux1_State[i]);
    } else {
      Serial.print(Mux1_State[i]);
      Serial.print(",");
      //vout = (value * 5.0) / 1024.0;
    }
  }
}

void updateMux1 () {
  for (int i = 0; i < 8; i++){
    digitalWrite(pin_Out_S0, HIGH && (i & B00000001));
    digitalWrite(pin_Out_S1, HIGH && (i & B00000010));
    digitalWrite(pin_Out_S2, HIGH && (i & B00000100));
    Mux1_State[i] = analogRead(pin_In_Mux1);
  }
}
Serial.print("Raw  Value = " );
Serial.print(RawValue); 

migrated from electronics.stackexchange.com Mar 4 '16 at 4:05

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 2
    Tom, StackExchange has got built-in code formatting and syntax colorization. Paste raw code, select it in the editor, click the {} button on the toolbar. – Nick Alexeev Mar 4 '16 at 3:49
  • Things like pin_Out_S0 need to be declared, otherwise they will generate error messages. – Nick Gammon Mar 4 '16 at 4:41
8

Your last two lines are not in any function. This confuses the compiler. You need to move those two statements inside a function.

Because those statements refer to RawValue, I'm guessing you want to put them in loop(), where RawValue is being updated.

Also, remember that the IDE will tell you on which line the error is, which is helpful when debugging compilation errors.

1

Please put these lines inside the loop() function block:

Serial.print("Raw  Value = " );
Serial.print(RawValue); 

Should look something like:

void loop() {
 RawValue = analogRead(pin_In_Mux1);
 Voltage = (RawValue * 5.0) / 1024; //scale the ADC
  updateMux1();
  //Serial.println(Mux1_State);
  for(int i = 0; i < 8; i ++) {
    if(i == 7) {
      Serial.println(Mux1_State[i]);
    } else {
      Serial.print(Mux1_State[i]);
      Serial.print(",");
      //vout = (value * 5.0) / 1024.0;
    }
  }
  Serial.print("Raw  Value = " );
  Serial.print(RawValue); 
}

That should at least remove the first issue with your code.

Cheers!

1

In addition to the good answers by Mikael and Uint, everything needs to be inside {curly braces} otherwise the IDE does not know where it belongs. If you didn't want the last 2 lines in your loop segment you could put them in a separate void xxxx () section to be called when the time is right (by using an ISR with an enableinterrupt function for example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.