Add Supply Voltage Display

This commit is contained in:
seiichiro 2021-05-15 21:12:18 +02:00
parent c5872bf77d
commit 778874cd1e

View file

@ -45,6 +45,21 @@ String statusmsg = "";
uint8_t loraBuffer[9]; // Lora Data Packet uint8_t loraBuffer[9]; // Lora Data Packet
uint32_t lastmillis; 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 // Button Handler Function
void handler(Button2& btn) { void handler(Button2& btn) {
switch (btn.getClickType()) { switch (btn.getClickType()) {
@ -109,6 +124,8 @@ void updateDisplay() {
oled.println(buffer[3]); oled.println(buffer[3]);
oled.print("Speed: "); oled.print("Speed: ");
oled.println(buffer[4]); oled.println(buffer[4]);
oled.print("Bat: ");
oled.println((float)readSupplyVoltage()/1000);
} else { } else {
if (hasFix != oldFix){ if (hasFix != oldFix){
oled.clear(); oled.clear();
@ -123,6 +140,8 @@ void updateDisplay() {
oled.println(interval); oled.println(interval);
oled.print("Packet: "); oled.print("Packet: ");
oled.println(Frame_Counter_Tx); oled.println(Frame_Counter_Tx);
oled.print("Bat: ");
oled.println((float)readSupplyVoltage()/1000);
} }
oled.print(statusmsg); oled.print(statusmsg);
oled.println(" "); oled.println(" ");