Add Supply Voltage Display

This commit is contained in:
seiichiro 2021-05-15 21:12:18 +02:00
parent c5872bf77d
commit 778874cd1e
1 changed files with 19 additions and 0 deletions

View File

@ -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(" ");