Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Cyclic ADC sampling for Arduino Mega
int sensorPin0 = A0; // select the input pin for the potentiometer
int sensorPin1 = A1; // select the input pin for the potentiometer
int sensorPin2 = A2; // select the input pin for the potentiometer
int sensorPin3 = A3; // select the input pin for the potentiometer
int sensorPin4 = A4; // select the input pin for the potentiometer
int sensorPin5 = A5; // select the input pin for the potentiometer
int sensorPin6= A6; // select the input pin for the potentiometer
int sensorPin7 = A7; // select the input pin for the potentiometer
int sensorPin8 = A8; // select the input pin for the potentiometer
int sensorPin9 = A9; // select the input pin for the potentiometer
int sensorPin10 = A10; // select the input pin for the potentiometer
int sensorPin11 = A11; // select the input pin for the potentiometer
int sensorPin12 = A12; // select the input pin for the potentiometer
int sensorPin13 = A13; // select the input pin for the potentiometer
int sensorPin14 = A14; // select the input pin for the potentiometer
unsigned long values[1500];
unsigned long howmanysamples;
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
analogReference(DEFAULT);
Serial.begin(115200);
howmanysamples = 0;
}
void loop() {
//turn on the LED, read the samples
digitalWrite(ledPin, HIGH);
for (int i = 0; i<100;i++){
values[i] = analogRead(sensorPin0);
values[i+100] = analogRead(sensorPin1);
values[i+200] = analogRead(sensorPin2);
values[i+300] = analogRead(sensorPin3);
values[i+400] = analogRead(sensorPin4);
values[i+500] = analogRead(sensorPin5);
values[i+600] = analogRead(sensorPin6);
values[i+700] = analogRead(sensorPin7);
values[i+800] = analogRead(sensorPin8);
values[i+900] = analogRead(sensorPin9);
values[i+1000] = analogRead(sensorPin10);
values[i+1100] = analogRead(sensorPin11);
values[i+1200] = analogRead(sensorPin12);
values[i+1300] = analogRead(sensorPin13);
values[i+1400] = analogRead(sensorPin14);
}
//delay(10);
digitalWrite(ledPin, LOW);
for (int i=0;i<100;i++){
Serial.print(howmanysamples);
Serial.print(", ");
Serial.print(i);
Serial.print(", ");
Serial.print(values[i]);
Serial.print(", ");
Serial.print(values[i+100]);
Serial.print(", ");
Serial.print(values[i+200]);
Serial.print(", ");
Serial.print(values[i+300]);
Serial.print(", ");
Serial.print(values[i+400]);
Serial.print(", ");
Serial.print(values[i+500]);
Serial.print(", ");
Serial.print(values[i+600]);
Serial.print(", ");
Serial.print(values[i+700]);
Serial.print(", ");
Serial.print(values[i+800]);
Serial.print(", ");
Serial.print(values[i+900]);
Serial.print(", ");
Serial.print(values[i+1000]);
Serial.print(", ");
Serial.print(values[i+1100]);
Serial.print(", ");
Serial.print(values[i+1200]);
Serial.print(", ");
Serial.print(values[i+1300]);
Serial.print(", ");
Serial.print(values[i+1400]);
Serial.println(";");
}
howmanysamples++;
delay(4991);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment