#ifdef __AVR_ATmega328P__
// AVCC=4.7V, POTI Vmax=3.3V
- #define K (1023.0 / 738.0)
+ #define K 1.32
#endif
void R2r::init () {
- ADMUX = (1 << REFS0) | 2; // ADC2, VREF=AVCC=3.3V
+ ADMUX = (1 << REFS0) | 2; // ADC2, VREF=AVCC (=3.3V for Nano-644/1284, =5V for Arduino Nano)
ADCSRA = (1 << ADEN) | 7; // ADC Enable, Prescaler 128
}
ADCSRA |= (1 << ADSC); // start ADC
while (ADCSRA & (1 << ADSC)) {} // wait for result
printf_P(PSTR("%4d (0x%03x)"), ADC, ADC);
- uint8_t sw = (uint8_t)( ((float)(ADC) + 32.0) / 64.0 * K );
- printf_P(PSTR(" SW9:6 = %d %d% d %d "), sw >> 3, (sw >> 2) & 0x01, (sw >> 1) & 0x01, sw & 0x01 );
+ // uint8_t sw = (uint8_t)( ((float)(ADC) + 4.0) / 64.0 * K );
+ float swf = ((float)(ADC) * K) / 64.8 + 0.55;
+ uint8_t sw = (uint8_t)swf ;
+ printf_P(PSTR(" %3.1f => SW9:6 = %d %d% d %d "), swf, sw >> 3, (sw >> 2) & 0x01, (sw >> 1) & 0x01, sw & 0x01 );
}
return 0;
}