diff --git a/the-cup.ino b/the-cup.ino index 89ad5cf..eb28f04 100644 --- a/the-cup.ino +++ b/the-cup.ino @@ -19,6 +19,8 @@ #include #include +#include "Adafruit_MAX1704X.h" + #define SS_PIN SDA #define RC522_POWER_PIN 1 #define SLEEP_DURATION 1 @@ -31,6 +33,8 @@ MFRC522 reader{driver_1}; // Create MFRC522 instance. RTC_DATA_ATTR int nbCycles = 0; +Adafruit_MAX17048 lipo; + const char *rootCACertificate = R"string_literal( -----BEGIN CERTIFICATE----- MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw @@ -76,6 +80,8 @@ void setup() { Serial.println(nbCycles++); #endif + measureBattery(); + pinMode(RC522_POWER_PIN, OUTPUT); digitalWrite(RC522_POWER_PIN, HIGH); reader.PCD_Init(); // Init each MFRC522 card. @@ -97,6 +103,15 @@ void loop() { } } +void measureBattery() { + if (nbCycles % 10) { + lipo.begin(); + if (lipo.cellVoltage() < 2.6) { + displayError(); + } + } +} + void readCard(char reader_uid[]) { reader.PICC_HaltA(); reader.PCD_StopCrypto1();