Skip to content

Instantly share code, notes, and snippets.

@pingud98
Created July 21, 2015 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pingud98/91efc69e2181ecaf7966 to your computer and use it in GitHub Desktop.
Save pingud98/91efc69e2181ecaf7966 to your computer and use it in GitHub Desktop.
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