
#include "Adafruit_NeoPixel.h"
#define PIN 6
#define CNT 24
#define C_alarm 3
#define C_warning 7
#define C_full 18
int pos = 0;
Adafruit_NeoPixel ring = Adafruit_NeoPixel(CNT, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
ring.begin();
}
void loop() {
int value = analogRead(0);
// 0 --> 0V
// 680 --> 10V
// 970 --> 14,2V
// 1023 --> 15V
int charge = map(value, 680, 970, 0, CNT);
Serial.print(value);
Serial.print(" --> ");
Serial.println(charge);
for (int i = 0; i < CNT; i++) {
if (i<charge) {
if(i<=C_alarm) {
ring.setPixelColor((i + pos), 255, 0, 0);
}
if(i>C_alarm & i<=C_warning) {
ring.setPixelColor((i + pos), 255, 128, 0);
}
if(i>C_warning & i<=C_full) {
ring.setPixelColor((i + pos), 51, 255, 51);
}
if(i>C_full) {
ring.setPixelColor((i + pos), 0, 255, 0);
}
} else {
ring.setPixelColor((i + pos), 0, 0, 0);
}
}
ring.show();
}