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 to implement PIR distance sensor to verify door of safe closed
|
||||||
* Need low power mode implementation(s)
|
* Need low power mode implementation(s)
|
||||||
* Need to add support for Adafruit Trinket Pro
|
* 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
|
* Add note about adjusting values for distance
|
||||||
|
|
24
src/src.ino
24
src/src.ino
|
@ -8,7 +8,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Various defines / pins / etc
|
// Various defines / pins / etc
|
||||||
#define DEBUG false
|
#define DEBUG true
|
||||||
#define BUTTON_CAP_TOGGLE 9
|
#define BUTTON_CAP_TOGGLE 9
|
||||||
#define POT_BRIGHT_PIN A0
|
#define POT_BRIGHT_PIN A0
|
||||||
#define POT_COLOR_PIN A1
|
#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);
|
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
|
uint8_t rgb[3]; // index 0 = red / index 1 = green / index 2 = blue
|
||||||
bool white = false;
|
bool white = false;
|
||||||
|
bool max_found = false;
|
||||||
|
|
||||||
// Various function definitions
|
// Various function definitions
|
||||||
void hsvToRgb(int h, double s, double v); // See end of file for implementation
|
void hsvToRgb(int h, double s, double v); // See end of file for implementation
|
||||||
|
@ -47,8 +48,12 @@ void setup() {
|
||||||
pinMode(PIN_WHITE, INPUT);
|
pinMode(PIN_WHITE, INPUT);
|
||||||
|
|
||||||
// Setup / config MAX1704
|
// Setup / config MAX1704
|
||||||
fuelGauge.reset();
|
Wire.beginTransmission(MAX1704_ADDR);
|
||||||
fuelGauge.quickStart();
|
max_found = (Wire.endTransmission() == 0);
|
||||||
|
if (max_found == 0) {
|
||||||
|
fuelGauge.reset();
|
||||||
|
fuelGauge.quickStart();
|
||||||
|
}
|
||||||
|
|
||||||
// AdaFruit NeoPixel init
|
// AdaFruit NeoPixel init
|
||||||
// Begin trinket special code (per NeoPixel examples)
|
// Begin trinket special code (per NeoPixel examples)
|
||||||
|
@ -68,7 +73,9 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Read various values needed
|
// 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
|
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)
|
raw_color = analogRead(POT_COLOR_PIN); // Color (0-1024)
|
||||||
always_on = (digitalRead(BUTTON_CAP_TOGGLE) == HIGH); // Toggle button pressed == ALWAYS ON
|
always_on = (digitalRead(BUTTON_CAP_TOGGLE) == HIGH); // Toggle button pressed == ALWAYS ON
|
||||||
|
@ -93,8 +100,13 @@ void loop() {
|
||||||
|
|
||||||
// Debugging code
|
// Debugging code
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Serial.print("Battery %: ");
|
if (max_found) {
|
||||||
Serial.println(charge_percent);
|
Serial.print("Battery %: ");
|
||||||
|
Serial.println(charge_percent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println("MAX1704 not found!");
|
||||||
|
}
|
||||||
Serial.print("Brightness: ");
|
Serial.print("Brightness: ");
|
||||||
Serial.println(brightness);
|
Serial.println(brightness);
|
||||||
Serial.print("White: ");
|
Serial.print("White: ");
|
||||||
|
|
Reference in a new issue