Skip to content

Commit

Permalink
Create batt_gauge_demo.ino
Browse files Browse the repository at this point in the history
Battery gauge demo (customize to length of strip)
  • Loading branch information
vskbellala committed Nov 1, 2021
1 parent 40a48f5 commit c3de014
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scmc/batt_gauge_demo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 14
#define LOW_BATT 20
#define MID_BATT 50


CRGB leds[NUM_LEDS];
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);//varies
Serial.begin(115200);
Serial.print("Lit fam :)");
}

void batt(int percent) {
//
memset(leds, CRGB(0, 0, 0), sizeof(leds));
int nb = round((float) percent / 100.0 * (float) NUM_LEDS);
Serial.println(nb);
for (int i = 0; i < nb; i++) {
if (percent <= LOW_BATT) {
leds[i] = CRGB(255, 0, 0);
} else if (percent <= MID_BATT) {
leds[i] = CRGB(255, 255, 0);
} else {
leds[i] = CRGB(0, 255, 0);
}
}
FastLED.show();
}
void loop() {
for (int j = 0; j < 100; j++) { // loops through animation (100ms steps)
batt(j);
delay(100);
}
}

0 comments on commit c3de014

Please sign in to comment.