So i tried to solve it with an array but it doesnt want to work. it saves just 1 value in both array places.
#include "Arduino.h"
// Global Variables
unsigned long int t_ref; // Reference time
// whenever a variable is used by both, Interrupt and main programm we
// need to tell the compiler about it ==> volatile
volatile unsigned long int millisekunden; // milli seconds timer
unsigned long int last_msg; //
char buffer[256];
unsigned int c;
unsigned int adc2;
unsigned int adc5;
unsigned int anVal[2];
volatile unsigned int adc_curr_ch = 0;
void setup() {
// Timer 0
TCCR0A |= (1 << WGM01); // CTC Mode
TCCR0B |= (1 << CS01) | (1 << CS00); // Prescaler 64
OCR0A = 250;
// Compare Interrupt
TIMSK0 |= (1 << OCIE0A);
// ADC
ADCSRA |= (1 << ADEN) | (1 << ADPS2) | (1 << ADIE);
ADMUX |= (1 << REFS0); // avcc
ADCSRA |= 1 << ADSC; // start cconversion
Serial.begin(9600);
}
void loop() {
if (millisekunden - last_msg >= 1000) {
sprintf(buffer, "\nt=[%lu] ADC0=%d ADC1=%d ",
millisekunden, anVal[0], anVal[1]);
last_msg = millisekunden;
Serial.println(buffer);
}
}
// Timer-Interrupt-Routine
ISR(TIMER0_COMPA_vect) {
millisekunden++;
}
ISR(ADC_vect) {
anVal[adc_curr_ch] = ADC;
// save to adc2
if (adc_curr_ch == 0) {
ADMUX |= (1 << MUX1);
adc_curr_ch = 1;
}
// save to adc5
else if (adc_curr_ch == 1) {
ADMUX |= (1 << MUX2) | (1 << MUX0);
ADMUX &= ~(1 << MUX1);
adc_curr_ch = 0;
}
ADCSRA |= 1 << ADSC;
}