The following code does not update initial adcValue. LEDs are working properly with different program, and they also work properly given the initial adcValue. They dont respond to potentiometer adjusting. The delay is there just to make it slower, it also doesnt work without it.
#define F_CPU 1000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
double adcValue = 700;
void startConversion()
{
ADCSRA |= (1 << ADSC);
}
void setupADC()
{
// AVcc with external capacitor as reference, ADC5 as input
ADMUX = (1 << REFS0) | (1 << MUX0) | (1 << MUX2);
// Enabling ADC, acticating interrupts, setting prescaler to 8
ADCSRA = (1 << ADEN) | (1 << ADIE) | (1 << ADPS0) | (1 << ADPS1) ;
//disabling digital input buffer
DIDR0 = (1 << ADC5D);
startConversion();
}
ISR(ADC_vect)
{
adcValue = ADC;
}
int main(void)
{
DDRB = 0b00111111;
setupADC();
sei();
while(1)
{
_delay_ms(500);
if( adcValue < 400)
{
PORTB = 0b00000000;
}
else if ( adcValue < 800)
{
PORTB = 0b00000011;
}
else
{
PORTB = 0b00000111;
}
startConversion();
}
}
SOLUTION:
now it works
volatile double adcValue = 700;
ADC
has typeuint16_t
makingadcValue
adouble
is unnecessary in this case and ill-advised in any event on this platform. – Clifford