]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
9ch ADC with Pro Micro Board: first working version
authorOle Artz <ole.artz@t-online.de>
Tue, 16 May 2017 13:37:37 +0000 (15:37 +0200)
committerOle Artz <ole.artz@t-online.de>
Tue, 16 May 2017 13:37:37 +0000 (15:37 +0200)
atmega32u4/9ch_adc/9ch_adc.ino [new file with mode: 0644]

diff --git a/atmega32u4/9ch_adc/9ch_adc.ino b/atmega32u4/9ch_adc/9ch_adc.ino
new file mode 100644 (file)
index 0000000..55261be
--- /dev/null
@@ -0,0 +1,42 @@
+// These constants won't change.  They're used to give names
+// to the pins used:
+// const int analogInPin = A8;  // Analog input pin that the potentiometer is attached to
+
+const int numPins = 9;
+const int analogInPins[] = {A0, A1, A2, A3, A6, A7, A8, A9, A10};
+const float scaling[] = {4.267, 4.267, 4.267, 4.267, 4.267, 4.267, 4.267, 4.267, 4.267};
+/*
+const int numPins = 1;
+const int analogInPins[] = {A8};
+const float scaling[] = {4.267};
+*/
+int   sensorValues[numPins];  // 0 - 1023
+float sensorVoltages[numPins]; // actual voltage on analog in pins
+float scaledSensorVoltages[numPins]; // corrected (scaled) voltages before voltage divider
+
+void setup() {
+  // initialize serial communications at 9600 bps:
+  Serial.begin(9600);
+  analogReference(INTERNAL); 
+ }
+
+void loop() {
+  // read the analog in value:
+  for (int i = 0; i < numPins; i++) {
+    sensorValues[i] = analogRead(analogInPins[i]);
+    sensorVoltages[i] = sensorValues[i] * 2.56 / 1023.;
+    scaledSensorVoltages[i] = scaling[i] * sensorVoltages[i];
+    //Serial.print(sensorValues[i]);
+    //Serial.print(" ");
+    //Serial.print(sensorVoltages[i], 4);
+    //Serial.print(" ");
+    Serial.print(scaledSensorVoltages[i], 3);
+    Serial.print(" ");
+  }
+  Serial.println();
+
+  // wait 2 milliseconds before the next loop
+  // for the analog-to-digital converter to settle
+  // after the last reading:
+  delay(250);
+}