Warning code with Arrays

Hi,

I have been trying to make a little program to monitor 5 pots independently however I have ran into this error and everything online seems a little complicated.

warning: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]

Also since switching to Arrays I can’t actually read my pots anymore.
Any ideas on this?

here is my code:
int i,j;

int values[5][2]= {
{analogRead(A0), “Working”},
{analogRead(A1), “Nice”},
{analogRead(A2), “Broken”},
{analogRead(A3), “Mess”},
{analogRead(A4), “Well Done”}
};

void setup(){

Serial.begin(9600);

}

void loop(){

for(i=0; i<5; i++){
for(j=0; j<2; j++){
printf("%d ", values*[j]);*

  • }*
  • }*
    }
    Any help would be greatly appreciated. :slight_smile:

The array datatype doesn't match the elements you're trying to store and you aren't printing the array correctly.

What are you trying to do?

You say your array is going to contain ints. Do things like "Warning" or "Broken" look like ints to you because they don't to the compiler?

You need to spend a little time looking at how arrays really work in C++/C because you seem to have invented your own syntax and that rarely works well. It might also be as well to look into the use of structs because I think they might do what you seem to want when arrays really can't.

And it doesn't make a lot of sense to try to do all your analogRead()s at compile time. Sometime later, after the program is running would probably be better.

Steve

dl324:
The array datatype doesn't match the elements you're trying to store and you aren't printing the array correctly.

What are you trying to do?

I'm just trying to get the values of the pots to display in monitor that's all.
After that I want to adjust a stepper motor to turn on and off dependant on the resistance from the Pot.

You’ve defined an array of ints. In your initializer list, you set the first element to the result of analogRead(), which should be a value between 0-1023…no problem. The second element is a character array with a quoted string (e.g., “Working”) which cannot be resolved to an int. One solution is to create an array of structures for your data.

econjack:
You’ve defined an array of ints. In your initializer list, you set the first element to the result of analogRead(), which should be a value between 0-1023…no problem. The second element is a character array with a quoted string (e.g., “Working”) which cannot be resolved to an int. One solution is to create an array of structures for you data.

Hi,

I have looked into Structs however I am finding it hard to read the analogue reads that I am declaring in the stucts.

//#include
//using namespace std;

int val = 0;

int pin0(0);

struct start{
int analogPin;
char feedback[20];
};

void setup() {

Serial.begin(9600);

}

void loop() {

start one = {
pin0, “Working”
};

Serial.print(one.analogPin);

//cout << one.analogPin << endl;

delay(100);

}

This my full code.

I’ve different ways to call the analogRead within the code previously however constaly run into an -fpermisve error.

Any ideas on how to fix this?

This how I was trying to declare it.

int pin0(analogRead[A0]);

void loop() {

start one = {
pin0, “Working”
};

Serial.print(one.analogPin);

//cout << one.analogPin << endl;

delay(100);

}

Sorry but from that code I can't even tell what it is that you're trying to do. Why don't you start by just reading a value from a pot and displaying it to the serial monitor. The IDE example AnalogReadSerial will help you get that right. Then you can extend that to more pots.

When you have that working you can try adding your text values like "Warning" or "Working". I can't tell what they are supposed to be associated with so I can't help there unless you can explain what exactly they are supposed to do.

Steve

slipstick:
Sorry but from that code I can't even tell what it is that you're trying to do. Why don't you start by just reading a value from a pot and displaying it to the serial monitor. The IDE example AnalogReadSerial will help you get that right. Then you can extend that to more pots.

When you have that working you can try adding your text values like "Warning" or "Working". I can't tell what they are supposed to be associated with so I can't help there unless you can explain what exactly they are supposed to do.

Steve

Hi I've already got that working I'm trying to make it more advanced so it takes up less room and is more usable with the later commands I'm wanting to run.

BenjaminoTzu:
int pin0(0);

What are you trying to do with this statement? It makes no sense.

Perhaps if you just stated what you're trying to accomplish instead of posting nonsensical code, someone might be able to help.

BenjaminoTzu:
Hi I’ve already got that working I’m trying to make it more advanced.

“Make it more advanced” does not in any way describe what it is supposed to be doing. Unless you can describe in detail what you’re trying to achieve I don’t think we’ll be able to help.

Steve

BenjaminoTzu:
I’m just trying to get the values of the pots to display in monitor that’s all.

This is an example of printing out the values of the pots, along with the text you have in the original post. You seem to be trying to make this way more complicated than it needs to be:

byte Pots[] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots
byte numberPots = 5; //number of inputs to read
char values[][10] { //text to print with corresponding input pot
  "Working",
  "Nice",
  "Broken",
  "Mess",
  "Well Done"
};

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (byte i = 0; i < numberPots; i++) {
    Serial.print(analogRead(Pots[i])); //print value read from pot
    Serial.print(" "); //space between sensor value and text
    Serial.println(values[i]); //print corresponding text with pot
  }
  Serial.println(); //print blank line between groups of output
  delay(1000); //slows loop to once per second
}

Sometimes it’s useful to keep similar data together in a structure. Because I often use structures as arrays, I tend to think of structure arrays as arrays for adults. Unlike a common array, structure arrays allow you to aggregate different data types in the same data structure. The attached code shows an example of how you can use structures to aggregate dissimilar data.

#define NUMBEROFPOTS(x)   (sizeof(x) /  sizeof(x[0]))

byte Pots[] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots
int sensorValue;

struct {

  int sensorPins;           // the pin assignments
  char *msg;                // the asssociated messages

} myStructure[] = {         // Initialize the members of the structure
  {A0, "Working"},
  {A1, "Nice"},
  {A2, "Broken"},
  {A3, "Mess"},
  {A4, "Well Done"}
};


void setup() {
  Serial.begin(9600);

  for (byte i = 0; i < NUMBEROFPOTS(Pots); i++) {
    sensorValue = analogRead(myStructure[i].sensorPins);
    Serial.print("The current value for sensor ");   //space between sensor value and text
    Serial.print(myStructure[i].sensorPins);         // No sensors to read, so just show pin values
    Serial.print(" and its associated message is "); //space between sensor value and text
    Serial.println(myStructure[i].msg); //print corresponding text with pot
  }
}

void loop() {
}

You could do away with the Pots[] array if you wanted to, but I left it in to show how the NUMBEROFPOTS macro might be used. You could also do away with sensorValue.

dl324:
What are you trying to do with this statement? It makes no sense.

Perhaps if you just stated what you're trying to accomplish instead of posting nonsensical code, someone might be able to help.

Hi I was trying to get around the -fpermisive error i keep getting.
it had originally analogRead[A0]; however that gave the error so changed it 0 to test it.

slipstick:
"Make it more advanced" does not in any way describe what it is supposed to be doing. Unless you can describe in detail what you're trying to achieve I don't think we'll be able to help.

Steve

I'm wanting to create a program which will register the data recorded by the pots and use a stepmotor to turn the pot to a specific number that is preset on an amplifier.

i.e. it would turn 5 to 8 or 8 to 5 etc.

BenjaminoTzu:
I'm wanting to create a program which will register the data recorded by the pots and use a stepmotor to turn the pot to a specific number that is preset on an amplifier.

i.e. it would turn 5 to 8 or 8 to 5 etc.

Still too confusing for me. Pots don't record anything. When you read them you generally get values between 0 and 1023. You can record those values if you like and use them to drive something else but you aren't doing anything like that in your code.

And I still can't see what strings like "Working" or "Broken" have to do with any of that?

Steve

slipstick:
Still too confusing for me. Pots don't record anything. When you read them you generally get values between 0 and 1023. You can record those values if you like and use them to drive something else but you aren't doing anything like that in your code.

And I still can't see what strings like "Working" or "Broken" have to do with any of that?

Steve

effectively i will assign a resistance value to a number on an amplifier and get a stepper motor to move the resistance to a specified amplifier value. i.e. 5 could be resistance value between 500-600 resistance and the stepper motor will be used to move the pot to specified value per the users request thus making an automated amplifier.

david_2018:
This is an example of printing out the values of the pots, along with the text you have in the original post. You seem to be trying to make this way more complicated than it needs to be:

byte Pots[] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots

byte numberPots = 5; //number of inputs to read
char values[10] { //text to print with corresponding input pot
  “Working”,
  “Nice”,
  “Broken”,
  “Mess”,
  “Well Done”
};

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (byte i = 0; i < numberPots; i++) {
    Serial.print(analogRead(Pots[i])); //print value read from pot
    Serial.print(" "); //space between sensor value and text
    Serial.println(values[i]); //print corresponding text with pot
  }
  Serial.println(); //print blank line between groups of output
  delay(1000); //slows loop to once per second
}

Thank you for your insight I didn’t realise that it could be that easy the tutorials online looked so much more complicated. So I adjusted my code to incorporate what they were doing.

Thanks Again,
Ben

i.e. 5 could be resistance value between 500-600

No it can't.
Communication and understanding are fundamental to programming (and getting help)