void configure_input(void){
DDRD &=~(1<<PD2);
PORTD |=(1<<PORTD2);
}
void init_INT0(){
EIMSK |= (1 << INT0);
EICRA |= (1 << ISC01);
EICRA &=~(1 << ISC00);
}
void init_adc() {
ADCSRB = 0x02;
ADMUX = 0x40; // Reference: AVCC, Input Channel: ADC0
ADCSRA = 0xA7; // Enable ADC, Auto Trigger, Prescaler 128
ADCSRA |= (1 << ADATE) | (1 << ADEN) | (1 << ADIE); // Enable ADC interrupt Enable the ADC Start the first conversion
//ADCSRA |= (1 << ADEN); // Enable the ADC
//ADCSRA |= (1 << ADIE); // Start the first conversion
}
ISR(ADC_vect) {
uint8_t lowByte = ADCL;
uint8_t highByte = ADCH;
uint16_t adc_value = (highByte << 8) | lowByte;
Serial.println(adc_value);
}
ISR(INT0_vect) {
ADCSRA |= (1 << ADSC); // Start ADC conversion
}
//ADCSRA = 0xA7;
void setup() {
Serial.begin(9600);
configure_input();
init_INT0();
init_adc();
sei(); // Enable global interrupts
}
void loop() {
// Main loop can stay empty, ADC results are printed in the ISR.
}