From: Ole Artz Date: Tue, 16 May 2017 13:37:37 +0000 (+0200) Subject: 9ch ADC with Pro Micro Board: first working version X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=b3074f253f301c46e53925ff28d0a6b7eeb15776;p=avr.git 9ch ADC with Pro Micro Board: first working version --- diff --git a/atmega32u4/9ch_adc/9ch_adc.ino b/atmega32u4/9ch_adc/9ch_adc.ino new file mode 100644 index 0000000..55261be --- /dev/null +++ b/atmega32u4/9ch_adc/9ch_adc.ino @@ -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); +}