Added battery threshold alert blinking
This commit is contained in:
parent
be66f958fb
commit
81eab5e545
|
@ -22,6 +22,7 @@ The following external libraries are included and may not be licensed under the
|
||||||
* Adafruit NeoPixel Library
|
* Adafruit NeoPixel Library
|
||||||
* SparkFun Lipo Fuel Gauge Library / Example code
|
* SparkFun Lipo Fuel Gauge Library / Example code
|
||||||
* "Sleepy" class from https://github.com/jcw/jeelib/
|
* "Sleepy" class from https://github.com/jcw/jeelib/
|
||||||
|
* Metro timing lib from https://github.com/thomasfredericks/Metro-Arduino-Wiring
|
||||||
|
|
||||||
Non-Code License
|
Non-Code License
|
||||||
=
|
=
|
||||||
|
|
1
TODO.md
1
TODO.md
|
@ -1,4 +1,3 @@
|
||||||
* Implement flashing lights if battery level is too low (use fuelgauge.isAlerting() and setAlertThreshold())
|
|
||||||
* Need to implement PIR distance sensor to verify door of safe closed
|
* Need to implement PIR distance sensor to verify door of safe closed
|
||||||
* Need to add support for Adafruit Trinket Pro
|
* Need to add support for Adafruit Trinket Pro
|
||||||
* Add note about adjusting values for distance
|
* Add note about adjusting values for distance
|
||||||
|
|
14
src/src.ino
14
src/src.ino
|
@ -5,6 +5,7 @@
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
#include "MAX1704.h"
|
#include "MAX1704.h"
|
||||||
#include "Sleepy.h"
|
#include "Sleepy.h"
|
||||||
|
#include "Metro.h"
|
||||||
#include "Adafruit_NeoPixel.h"
|
#include "Adafruit_NeoPixel.h"
|
||||||
#ifdef __AVR__
|
#ifdef __AVR__
|
||||||
#include <avr/power.h>
|
#include <avr/power.h>
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
// Objects / values / etc
|
// Objects / values / etc
|
||||||
// //////////
|
// //////////
|
||||||
MAX1704 fuelGauge;
|
MAX1704 fuelGauge;
|
||||||
|
Metro timer = Metro(1000); // Timer for battery level alert (flashes pixels red or yellow [if red set]) to alert
|
||||||
float charge_percent;
|
float charge_percent;
|
||||||
uint8_t brightness;
|
uint8_t brightness;
|
||||||
uint16_t raw_color;
|
uint16_t raw_color;
|
||||||
|
@ -38,6 +40,7 @@ uint8_t color;
|
||||||
bool always_on = false;
|
bool always_on = false;
|
||||||
Adafruit_NeoPixel neopix = Adafruit_NeoPixel(NEO_PIX_NUM, PIN_NEO, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel neopix = Adafruit_NeoPixel(NEO_PIX_NUM, PIN_NEO, NEO_GRB + NEO_KHZ800);
|
||||||
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
||||||
|
uint8_t red_threshold = 10; // 10 on the 360 degree mapping represents where red / orange / yellow start to bleed and the alert blink needs to be a different color
|
||||||
bool white = false;
|
bool white = false;
|
||||||
bool max_found = false;
|
bool max_found = false;
|
||||||
bool door_open = false;
|
bool door_open = false;
|
||||||
|
@ -150,6 +153,17 @@ void pixel_update() {
|
||||||
|
|
||||||
// Set color accordingly
|
// Set color accordingly
|
||||||
for (uint8_t i=0; i<NEO_PIX_NUM; i++) {
|
for (uint8_t i=0; i<NEO_PIX_NUM; i++) {
|
||||||
|
// Set to red/yellow for alert if alerting and the timer has run out
|
||||||
|
if (fuelGauge.isAlerting() && timer.check() == 1) {
|
||||||
|
if (color <= red_threshold) {
|
||||||
|
rgb[0] = 0;
|
||||||
|
rgb[1] = rgb[2] = 255;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rgb[0] = 255;
|
||||||
|
rgb[1] = rgb[2] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
neopix.setPixelColor(i, neopix.Color(rgb[0], rgb[1], rgb[2]));
|
neopix.setPixelColor(i, neopix.Color(rgb[0], rgb[1], rgb[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue