-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Battery gauge demo (customize to length of strip)
- Loading branch information
1 parent
40a48f5
commit c3de014
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |