Adafruit Feather OLED
Adafruit_FeatherOLED.h
Go to the documentation of this file.
1 
5 #ifndef _Adafruit_FeatherOLED_H_
6 
9 #define _Adafruit_FeatherOLED_H_
10 
11 #include <Adafruit_GFX.h>
12 #include <Adafruit_SSD1306.h>
13 #include <Wire.h>
14 
15 #if defined(__SAMD51__)
16 // m4 feathers
17 #define VBATPIN A6
18 #define VBAT_MULTIPLIER 2.0 * 3.3 / 1024.0
19 
20 #elif defined(ARDUINO_ARCH_SAMD)
21 // m0 feathers
22 #define VBATPIN A7
23 #define VBAT_MULTIPLIER 2.0 * 3.3 / 1024.0
24 
25 #elif defined(__AVR_ATmega32U4__)
26 // 32u4 feather
27 #define VBATPIN A9
28 #define VBAT_MULTIPLIER 2.0 * 3.3 / 1024.0
29 
30 #elif defined(ESP8266)
31 // esp8266 feather
32 #define VBATPIN A0
33 /*
34  * The ESP8266 Feather Huzzah does not have an internal voltage divider, so you
35  * must build one. However, the voltage on the Analog Input must be between
36  * 0-1.0V or you could risk damaging the chip. So please keep this in mind when
37  * selecting resistor values. For the default values you could use a 100K
38  * resistor between ADC and the BAT pin (RESISTOR_BAT) and a 10K Resistor
39  * between ADC and Ground (RESISTOR_GND) or change the values below for other
40  * combinations.
41  */
42 #define RESISTOR_BAT 100000
43 #define RESISTOR_GND 10000
44 #define VBAT_MULTIPLIER ((RESISTOR_BAT + RESISTOR_GND) / RESISTOR_GND) / 1024.0
45 
46 #elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
47 // esp32 feather
48 #define VBATPIN A13
49 // Multiply by 1.1V, the adC reference voltage, convert to voltage 4098 is max
50 // value
51 #define VBAT_MULTIPLIER 2.0 * 3.3 * 1.1 / 4098.0
52 
53 #elif defined(ARDUINO_STM32_FEATHER)
54 // wiced feather
55 #define VBATPIN PA1
56 #define VBAT_MULTIPLIER 2.0 * 0.80566F / 1000.0
57 
58 #elif defined(ARDUINO_FEATHER52) || defined(NRF52840_XXAA)
59 #define VBATPIN PIN_VBAT
60 #define VBAT_MV_PER_LSB \
61  (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
62 
63 #ifdef NRF52840_XXAA // if this is for nrf52840
64 #define VBAT_DIVIDER (0.5F) // 150K + 150K voltage divider on VBAT
65 #define VBAT_MULTIPLIER (2.0F) // Compensation factor for the VBAT divider
66 #else
67 #define VBAT_DIVIDER \
68  (0.71275837F) // 2M + 0.806M voltage divider on VBAT = (2M / (0.806M + 2M))
69 #define VBAT_MULTIPLIER (1.403F) // Compensation factor for the VBAT divider
70 #endif
71 
72 #define REAL_VBAT_MV_PER_LSB (VBAT_MULTIPLIER * VBAT_MV_PER_LSB)
73 
74 #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
75 #include "Adafruit_LC709203F.h"
76 
77 #else
78 #warning "Board VBAT pin is not known!"
79 #endif
80 
81 /**************************************************************************/
86 /**************************************************************************/
87 class Adafruit_FeatherOLED : public Adafruit_SSD1306 {
88 protected:
89  float _battery; //
90  bool _batteryIcon; //
91  bool _batteryVisible; //
92 #if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
93  Adafruit_LC709203F *lc = NULL;
94 #endif
95 
96 public:
97  /**************************************************************************/
101  /**************************************************************************/
106  };
107 
108  /**************************************************************************/
114  /**************************************************************************/
115  Adafruit_FeatherOLED(TwoWire *wire = &Wire, int reset = -1)
116  : Adafruit_SSD1306(128, 32, wire, reset) {
117  _battery = 0.0F;
118  _batteryIcon = true;
119  _batteryVisible = true;
120  }
121 
122  /**************************************************************************/
127  /**************************************************************************/
128  void setBattery(float vbat) { _battery = vbat; }
129 
130  /**************************************************************************/
135  /**************************************************************************/
136  void setBatteryVisible(bool enable) { _batteryVisible = enable; }
137 
138  /**************************************************************************/
143  /**************************************************************************/
144  void setBatteryIcon(bool enable) { _batteryIcon = enable; }
145 
146  float getBatteryVoltage();
147 
148  void init(void);
149  void clearMsgArea(bool update = true);
150  void renderBattery(void);
151 };
152 
153 #define BATTTEXT_STARTX 77
154 #define BATTTEXT_STARTY 0
155 #define BATTICON_STARTX 110
156 #define BATTICON_STARTY 0
157 #define BATTICON_WIDTH 18
158 #define BATTICON_BARWIDTH3 \
159  ((BATTICON_WIDTH - 6) / 3)
160 
161 #endif /* _Adafruit_FeatherOLED_H_ */
Adafruit FeatherOLED H.
Definition: Adafruit_FeatherOLED.h:87
BatteryIconType
Definition: Adafruit_FeatherOLED.h:102
bool _batteryVisible
Definition: Adafruit_FeatherOLED.h:91
void setBatteryVisible(bool enable)
Sets the Battery Value Visibility.
Definition: Adafruit_FeatherOLED.h:136
void renderBattery(void)
Renders the battery icon.
Definition: Adafruit_FeatherOLED.cpp:48
void setBattery(float vbat)
Sets the Battery Value.
Definition: Adafruit_FeatherOLED.h:128
Adafruit_FeatherOLED(TwoWire *wire=&Wire, int reset=-1)
Class Constructor.
Definition: Adafruit_FeatherOLED.h:115
Definition: Adafruit_FeatherOLED.h:105
bool _batteryIcon
Definition: Adafruit_FeatherOLED.h:90
Definition: Adafruit_FeatherOLED.h:103
float getBatteryVoltage()
Query the Feather for the Lipoly battery voltage.
Definition: Adafruit_FeatherOLED.cpp:151
float _battery
Definition: Adafruit_FeatherOLED.h:89
void init(void)
Initialises the display (always call this first!)
Definition: Adafruit_FeatherOLED.cpp:113
void clearMsgArea(bool update=true)
Clears the message area (the middle 128x16 pixels) and sets the cursor to 0, 8.
Definition: Adafruit_FeatherOLED.cpp:137
void setBatteryIcon(bool enable)
Sets the Battery Icon Visibility.
Definition: Adafruit_FeatherOLED.h:144