diff --git a/src/main.cpp b/src/main.cpp index bacf497..76e27c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,21 @@ String statusmsg = ""; uint8_t loraBuffer[9]; // Lora Data Packet uint32_t lastmillis; +// Supply Voltage +uint16_t readSupplyVoltage() { + uint16_t temp = 0; + analogReference(VDD); + VREF.CTRLA = VREF_ADC0REFSEL_1V5_gc; + ADC0.CTRLD = ADC_INITDLY_DLY256_gc; + ADC0_CTRLB = ADC_SAMPNUM_ACC64_gc; + uint16_t reading = analogRead(ADC_INTREF); + temp = reading / 64; + uint32_t intermediate = 1534500; + reading = 0; + reading = intermediate / temp; + return reading; +} + // Button Handler Function void handler(Button2& btn) { switch (btn.getClickType()) { @@ -109,6 +124,8 @@ void updateDisplay() { oled.println(buffer[3]); oled.print("Speed: "); oled.println(buffer[4]); + oled.print("Bat: "); + oled.println((float)readSupplyVoltage()/1000); } else { if (hasFix != oldFix){ oled.clear(); @@ -123,6 +140,8 @@ void updateDisplay() { oled.println(interval); oled.print("Packet: "); oled.println(Frame_Counter_Tx); + oled.print("Bat: "); + oled.println((float)readSupplyVoltage()/1000); } oled.print(statusmsg); oled.println(" ");