Shorting fuel cells using an Arduino UNO

So I have been programming my board to receive voltage inputs from the fuel cells and to short fuel cells but so far I’ve been having problems compiling the code

i keep getting this error message

Shorting_algorithm:20:29: error: expected unqualified-id before ‘[’ token

struct short_AnalogReading[6]{

^

Shorting_algorithm:27:2: error: ‘short_analogReading’ does not name a type; did you mean ‘short_AnalogReading’?

}short_analogReading;

^~~~~~~~~~~~~~~~~~~

short_AnalogReading

Shorting_algorithm:28:2: error: expected ‘;’ after class definition

}

^

;

Shorting_algorithm:34:4: error: a function-definition is not allowed here before ‘{’ token

{

^

Shorting_algorithm:92:5: error: a function-definition is not allowed here before ‘{’ token

{

^

Shorting_algorithm:150:1: error: expected ‘}’ at end of input

}

^

exit status 1

expected unqualified-id before ‘[’ token

and this is the program
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
}

class variables {
struct short_AnalogReading[6]{
double val0;
double val1;
double val2;
double val3;
double val4;
double val5;
}short_analogReading;
}

void loop() {

int shorting()
{
static int MuxPointer = 0;
if (MuxPointer > 5) { // check if Mux Pointer is within bounds
MuxPointer = 0; // reset to zero if not
}

switch (MuxPointer) { // lookup to assign PORT bits to Mux number

case 0:
val0 = analogRead(A0); // read the input pin
Serial.println(“Module 1 short begin”);
while(unsigned int i=0; i<100; i++)
{
digitalWrite(2, HIGH);
Serial.println(".\r"); //after 100ms
}
digitalWrite(2,LOW);
//get the reading for voltage (pulse module short voltage)
break;

case 1:
val1 = analogRead(A1); // read the input pin
Serial.println(“Module 2 shorted”);
digitalWrite(3, HIGH);
break;

case 2:
val2 = analogRead(A2); // read the input pin
Serial.println(“Module 3 shorted”);
digitalWrite(4, HIGH);
delay(100);
break;

case 3:
val3 = analogRead(A3); // read the input pin
Serial.println(“Module 4 shorted”);
digitalWrite(5, HIGH);
delay(100);
break;

case 4:
val4 = analogRead(A4); // read the input pin
Serial.println(“Module 4 shorted”);
digitalWrite(6, HIGH);
delay(100);
break;

case 5:
val5 = analogRead(A5); // read the input pin
Serial.println(“Module 4 shorted”);
digitalWrite(7, HIGH);
delay(100);
break;

delay(1000); // Allow ADC to settle

MuxPointer++;

}

}
int Readings()
{
struct AnalogReading[6]{
double cellv0;
double cellv1;
double cellv2;
double cellv3;
double cellv4;
double cellv5;
}analogReading;
static int modulePointer = 0;
if (modulePointer > 5) { // check if Mux Pointer is within bounds
modulePointer = 0; // reset to zero if not
}

switch (modulePointer) { // lookup to assign PORT bits to Mux number

case 0:
cellv0 = analogRead(A0); // read the input pin
Serial.println(“Module 1 voltage”);
Serial.print(cellv0);
break;

case 1:
cellv1 = analogRead(A1); // read the input pin
Serial.println(“Module 2 voltage”);
Serial.print(cellv1);
break;

case 2:
cellv2 = analogRead(A2); // read the input pin
Serial.println(“Module 3 voltage”);
Serial.print(cellv2);
break;

case 3:
cellv3 = analogRead(A3); // read the input pin
Serial.println(“Module 4 voltage”);
Serial.print(cellv3);
break;

case 4:
cellv4 = analogRead(A4); // read the input pin
Serial.println(“Module 5 voltage”);
Serial.print(cellv4);
break;

case 5:
cellv5 = analogRead(A5); // read the input pin
Serial.println(“Module 6 voltage”);
Serial.print(cellv5);
break;

delay(1000); // Allow ADC to settle

modulePointer++;

}

}

Please post your topic according to the forum guidelines with code formatted using the ctrl T option in the Arduino IDE and with code blocks (use the </> button). Putting the error message in a code block will also help.

Why are you bothering with a class when all it contains is a struct? If you really need to use that approach then maybe define the struct before the class and just declare it within.

it looks like your defining sub-functions with loop(). shorting() and Readings () should be outside of loop(). presumably loop() will call them.

        struct  AnalogReading[6]{
            double  cellv0;
            double  cellv1;
            double  cellv2;
            double  cellv3;
            double  cellv4;
            double  cellv5;
        }analogReading;

it looks like you’re trying to define an array with 6 values, possibly

double AnalogReading[6];

or a structure, AnalogReading, with 6 elements and a variable of that type of struct, analogReading.

struct  AnalogReading {
            double  cellv0;
            double  cellv1;
            double  cellv2;
            double  cellv3;
            double  cellv4;
            double  cellv5;
        }analogReading;

earlier in the code you seem to be trying to so the same within a class called variables

class variables {
    struct  short_AnalogReading[6]{
        double  val0;
        double  val1;
        double  val2;
        double  val3;
        double  val4;
        double  val5;
    }short_analogReading;

}

a for loop is coded as while loop

            while(unsigned int i=0;
            i<100;
            i++)

assume there are other gross mis-uses of the language

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