Adding multiple analog inputs to code

Hi,

New to Arduino and cant figure out how to get the code for multiple analog inputs to be read for use in PureData. I want six potentiometers to run as inputs. Any ideas?

Thanks very much.

#include <Firmata.h>

byte analogPin = 0;

void analogWriteCallback(byte pin, int value)
{
    if (IS_PIN_PWM(pin)) {
        pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
        analogWrite(PIN_TO_PWM(pin), value);
    }
}

void setup()
{
    Firmata.setFirmwareVersion(0, 1);
    Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
    Firmata.begin(57600);
}

void loop()
{
    while(Firmata.available()) {
        Firmata.processInput();
    }
    // do one analogRead per loop, so if PC is sending a lot of
    // analog write messages, we will only delay 1 analogRead
    Firmata.sendAnalog(analogPin, analogRead(analogPin)); 
    analogPin = analogPin + 1;
    if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0;
}

New to Arduino and cant figure out how to get the code for multiple analog inputs to be read for use in PureData. I want six potentiometers to run as inputs. Any ideas?

It is NOT done by changing the Arduino code.

J_Sev90: I want six potentiometers to run as inputs. Any ideas?

[/code]

i'm no expert here But i think you can done this by using

val1 = analogRead(pin1);
val2 = analogRead(pin2);
val3 = analogRead(pin3);
.
.
val6  = analogRead(pin6)

Or even better, use a for loop

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

void loop()
{
  for (int analogPin = 0; analogPin < 6; analogPin++)
  {
    Serial.println(analogRead(analogPin));
  }
  Serial.println();
  delay(1000);  //just an example.  Don't use delay() in real code
}

and array to store values

void loop()
{
  for (int analogPin = 0; analogPin < 6; analogPin++)
  {
   val[analogPin] = Serial.println(analogRead(analogPin));
  }
  Serial.println();
  delay(1000);  //just an example.  Don't use delay() in real code
}

Did either of you look at OP's code? OP is loading Firmata on the Arduino, putting it under PureData's control. Reading multiple analog pins is something that PureData will need to make happen.

Reading multiple analog pins is something that PureData will need to make happen.

and he is asking for help with this in an Arduino programming forum ?

This

#include <Firmata.h>

byte analogPin;

void analogWriteCallback(byte pin, int value)
{
    pinMode(pin,OUTPUT);
    analogWrite(pin, value);
}

void setup()
{
    Firmata.setFirmwareVersion(0, 1);
    Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
    Firmata.begin();
}

void loop()
{
    while(Firmata.available()) {
        Firmata.processInput();
    }
    for(analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
        Firmata.sendAnalog(analogPin, analogRead(analogPin)); 
    }
}

from
http://arduino.cc/en/Reference/Firmata
looks relevant. Haven’t I seen that for loop, or something very like it. somewhere before ?