#include <Adafruit_NeoPixel.h>
#define ADC_PIN 34
#define LED_PIN 18
#define ADC_CONVERSION 4095.0
#define LED_COUNT (16 * 2)
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
pinMode(ADC_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
strip.begin();
strip.show();
strip.setBrightness(255);
}
void loop()
{
float inVolt = (float) analogRead(ADC_PIN) / ADC_CONVERSION;
drawNeoBar(inVolt * strip.numPixels(), strip.Color(inVolt * 255, 0, 255 - inVolt * 255));
delay(10);
}
void drawNeoBar(int pixelEnd, uint32_t color)
{
for(int i = 0; i < pixelEnd; i++) {
strip.setPixelColor(i, color);
strip.show();
}
for(int i = pixelEnd + 1; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0, 0, 0));
strip.show();
}
if (!pixelEnd)
{
strip.setPixelColor(0, strip.Color(0, 0, 0));
}
}