#include <Adafruit_NeoPixel.h>
const uint8_t LED_STRIP = 13;
const uint16_t LED_COUNT = 1;
Adafruit_NeoPixel NeoPixel(LED_COUNT, LED_STRIP, NEO_GRB + NEO_KHZ800);
int red = 0;
int green = 0;
int colorbatterySoC = 0;
void setup() {
Serial.begin(9600);
NeoPixel.begin();
}
void loop() {
getBatteryGraphColor(colorbatterySoC);
colorbatterySoC++;
if (colorbatterySoC > 100) colorbatterySoC = 0;
NeoPixel.setPixelColor(0, NeoPixel.Color(red, green, 0));
NeoPixel.show();
delay(200);
}
void getBatteryGraphColor(int batterySoC) {
// red color
if (batterySoC <= 20) {
red = 255;
green = 0;
}
// Shift to orange to yellow
else if (batterySoC <= 60) {
red = 255;
green = (batterySoC - 20) * 7;
if (green > 255) green = 255;
}
// Shift to green
else if (batterySoC > 60) {
red = 255 - (batterySoC - 60) * 7;
if (red < 0) red = 0;
green = 255;
}
// Palautetaan tässä Color(red, green, 0)
}