How to apply a constraint to an analogue value

Hi Everyone,

I am working with Potentiometers and I am wanting to pass their values through a database and into a web page. I have managed to get the initial read working but have no idea how to pass the data through as INT has a 255 restriction.

An idea I had was to create constraints on the analogue values and assign them to an INT value i.e 267 - 284 = 3

Does anyone know how I could adapt my code to do this on an arduino?

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]);*

  • }*
  • }*
    };
    Kind Regards,
    Ben

Does your code compile ?

{analogRead(A0), "Working"},
 {analogRead(A1), "Nice"},

"Working" and "Nice" are not int type things. What were you hoping this would do?

If you want to constrain a value then look here:

and see if there isn't a command literally called "constrain".

Hi,

It does compile and works fine.

As for the words yes I understand what you mean but these were purely for testing purposes only.
Once working with constraints they would be removed.

Sorry I did not know of the comand.

Kind Regards,
Ben

BenjaminoTzu:
As for the words yes I understand what you mean but these were purely for testing purposes only.
Once working with constraints they would be removed.

Yeah, that still doesn't explain what you hoped that line was going to do. It certainly doesn't store a character string in your array. So if you say it works then you must either have some odd expectations or a very odd definition of the word "works".

BenjaminoTzu:
Hi Everyone,

I am working with Potentiometers and I am wanting to pass their values through a database and into a web page. I have managed to get the initial read working but have no idea how to pass the data through as INT has a 255 restriction.

An idea I had was to create constraints on the analogue values and assign them to an INT value i.e 267 - 284 = 3

Does anyone know how I could adapt my code to do this on an arduino?

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]);*

  • }*
    }
    };
    Kind Regards,
    Ben
    [/quote]
    INT on Arduino is signed 16 bit (+32767 ... -32768). There is not a "255" limit. If you want to convert 10 bit ADC values to 0...255 then just divide the ADC value by 4... like this:
    * *uint8_t value = analogRead (A0) / 4;* *
    Hope this helps.

krupski:
INT on Arduino is signed 16 bit (+32767 ... -32768).

...or 32 bit depending on which Arduino board you're using.