Hi, I'm am a complete beginner and I am trying to set up some IR distance sensors using an arduino mini. I already found example code (in Making Things Talk) for one sensor:
int sensorPin = 0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
int range = (6797 / (sensorValue - 3)) - 4;
Serial.println(range, DEC);
delay(10);
}
But can't seem to find any sort of instructions on how to take values from all pins zero to three (then output them separately into a Max patch)
I must sound completely stupid but...
Can anyone help?
You could also declare an array of values if you needed to store them (there is an example commented out in the code below)
#define NUMBER_OF_PINS 4 // this is the number of pins you want to read
int sensorValue;
//int sensorValue[NUMBER_OF_PINS]; // declare an array of pin values if you want to store them
void setup() {
Serial.begin(9600);
}
void loop() {
for(int pin=0; pin < NUMBER_OF_PINS; pin++){
sensorValue = analogRead(pin); // you are using pins from 0 to 3
//sensorValue[pin] = analogRead(pin); // example using array
int range = (6797 / (sensorValue - 3)) - 4;
Serial.println(range, DEC);
delay(10);
}
}