Browse Source

Added battery threshold alert blinking

master
Mike C 6 years ago
parent
commit
81eab5e545
  1. 1
      README.md
  2. 1
      TODO.md
  3. 14
      src/src.ino

1
README.md

@ -22,6 +22,7 @@ The following external libraries are included and may not be licensed under the
* Adafruit NeoPixel Library
* SparkFun Lipo Fuel Gauge Library / Example code
* "Sleepy" class from https://github.com/jcw/jeelib/
* Metro timing lib from https://github.com/thomasfredericks/Metro-Arduino-Wiring
Non-Code License
=

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 add support for Adafruit Trinket Pro
* Add note about adjusting values for distance

14
src/src.ino

@ -5,6 +5,7 @@
#include "Wire.h"
#include "MAX1704.h"
#include "Sleepy.h"
#include "Metro.h"
#include "Adafruit_NeoPixel.h"
#ifdef __AVR__
#include <avr/power.h>
@ -31,6 +32,7 @@
// Objects / values / etc
// //////////
MAX1704 fuelGauge;
Metro timer = Metro(1000); // Timer for battery level alert (flashes pixels red or yellow [if red set]) to alert
float charge_percent;
uint8_t brightness;
uint16_t raw_color;
@ -38,6 +40,7 @@ uint8_t color;
bool always_on = false;
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 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 max_found = false;
bool door_open = false;
@ -150,6 +153,17 @@ void pixel_update() {
// Set color accordingly
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]));
}

Loading…
Cancel
Save