#include <avr/io.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ICR(INT1_vect){
// }
float read_adc() {
ADCSRA |= (1 << ADSC); // Start the Conversion
while (ADCSRA & (1 << ADSC)); // Wait for Conversion to Complete
uint16_t adcValue = ADC; // Read the ADC Value
float voltage = adcValue / (1023 / 5.00);
return voltage;
}
volatile float voltage = 0.0;
void print_voltage() {
lcd.clear();
lcd.print(voltage);
lcd.print(" V");
}
void setup() {
PORTD = 1 << PD2; // ? //interal pull up
lcd.init();
lcd.backlight();
voltage = read_adc();
print_voltage();
}
int main() {
init();
setup();
while(true) {
float new_voltage = read_adc();
// print_voltage();
if (new_voltage != voltage) {
voltage = new_voltage;
print_voltage();
}
}
}