-
Notifications
You must be signed in to change notification settings - Fork 1
/
model_adc.h
41 lines (32 loc) · 1.25 KB
/
model_adc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once // Please format this file with clang before check-in to GitHub
/*
File: morse_adc.h
Software: Barry Hansen, K7BWH, [email protected], Seattle, WA
Hardware: John Vanderbeck, KM7O, Seattle, WA
Purpose: Measure the voltage on the coin battery that powers
the Quectel GPS. If the battery falls below 1.6v then
the GPS can no longer acquire satellites.
Note: PCB v7+ has wiring to measure battery voltage.
PCB v4 has no such sensor.
*/
// ========== class BatteryVoltage ==================================
class BatteryVoltage {
private:
int inputPin;
int coinBattery; // measured coin battery ADC sample (0..1024)
const float voltsPerSample = (3.3 / 1023.0); // PCB v6+ circuit's reference voltage is Vcc = 3.3 volts
public:
// Griduino v7 uses Analog input pin A1 to measure 3v coin battery
BatteryVoltage(int inputPin = A1) {}
void setup() {
}
float getCoinBatteryVoltage() {
#if defined(ARDUINO_ADAFRUIT_FEATHER_RP2040)
coinBattery = analogRead(A1);
float coinVoltage = coinBattery * voltsPerSample;
return coinVoltage;
#else
return -1.0; // indicate no coin battery voltage sensor
#endif
}
}; // end class BatteryVoltage