Added check during init to ensure fuel gauge is present, will no longer fail if it's not present
This commit is contained in:
parent
9cc9ee4a61
commit
61b5c90e9b
1
TODO.md
1
TODO.md
|
@ -3,5 +3,4 @@
|
|||
* Need to implement PIR distance sensor to verify door of safe closed
|
||||
* Need low power mode implementation(s)
|
||||
* Need to add support for Adafruit Trinket Pro
|
||||
* Need to make it work if fuel gauge is not present
|
||||
* Add note about adjusting values for distance
|
||||
|
|
24
src/src.ino
24
src/src.ino
|
@ -8,7 +8,7 @@
|
|||
#endif
|
||||
|
||||
// Various defines / pins / etc
|
||||
#define DEBUG false
|
||||
#define DEBUG true
|
||||
#define BUTTON_CAP_TOGGLE 9
|
||||
#define POT_BRIGHT_PIN A0
|
||||
#define POT_COLOR_PIN A1
|
||||
|
@ -26,6 +26,7 @@ bool always_on = false;
|
|||
Adafruit_NeoPixel neopix = Adafruit_NeoPixel(NEO_PIX_NUM, NEO_PIN, NEO_GRB + NEO_KHZ800);
|
||||
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
||||
bool white = false;
|
||||
bool max_found = false;
|
||||
|
||||
// Various function definitions
|
||||
void hsvToRgb(int h, double s, double v); // See end of file for implementation
|
||||
|
@ -47,8 +48,12 @@ void setup() {
|
|||
pinMode(PIN_WHITE, INPUT);
|
||||
|
||||
// Setup / config MAX1704
|
||||
fuelGauge.reset();
|
||||
fuelGauge.quickStart();
|
||||
Wire.beginTransmission(MAX1704_ADDR);
|
||||
max_found = (Wire.endTransmission() == 0);
|
||||
if (max_found == 0) {
|
||||
fuelGauge.reset();
|
||||
fuelGauge.quickStart();
|
||||
}
|
||||
|
||||
// AdaFruit NeoPixel init
|
||||
// Begin trinket special code (per NeoPixel examples)
|
||||
|
@ -68,7 +73,9 @@ void setup() {
|
|||
|
||||
void loop() {
|
||||
// Read various values needed
|
||||
charge_percent = fuelGauge.stateOfCharge(); // Battery level
|
||||
if (max_found) {
|
||||
charge_percent = fuelGauge.stateOfCharge(); // Battery level
|
||||
}
|
||||
brightness = map(analogRead(POT_BRIGHT_PIN), 0, 1024, 0, 255); // Brightness (0-1023) mapped to 0-255
|
||||
raw_color = analogRead(POT_COLOR_PIN); // Color (0-1024)
|
||||
always_on = (digitalRead(BUTTON_CAP_TOGGLE) == HIGH); // Toggle button pressed == ALWAYS ON
|
||||
|
@ -93,8 +100,13 @@ void loop() {
|
|||
|
||||
// Debugging code
|
||||
if (DEBUG) {
|
||||
Serial.print("Battery %: ");
|
||||
Serial.println(charge_percent);
|
||||
if (max_found) {
|
||||
Serial.print("Battery %: ");
|
||||
Serial.println(charge_percent);
|
||||
}
|
||||
else {
|
||||
Serial.println("MAX1704 not found!");
|
||||
}
|
||||
Serial.print("Brightness: ");
|
||||
Serial.println(brightness);
|
||||
Serial.print("White: ");
|
||||
|
|
Reference in a new issue