TinkerCad project : https://www.tinkercad.com/things/gtjDmncLAZv-copy-of-documentation-potentiometer/
//----------------LIBRARIES----------------
// adafruit neopixel library
// find out more about library here: <https://adafruit.github.io/Adafruit_NeoPixel/html/class_adafruit___neo_pixel.html>
#include <Adafruit_NeoPixel.h>
//------------------WIRING------------------
// 5V -> 3.3V or 5V
// GND -> GND
// DI -> Digital pin
#define LED_PIN 2
// 5V -> 3.3V or 5V
// GND -> GND
// DI -> Digital pin
#define POT_PIN A0
//----------------VARIABLES----------------
// number of LEDs
#define LED_COUNT 12
// NeoPixel luminosity, 0 (min) to 255 (max)
#define BRIGHTNESS 20
// store POT value
int potValue = 0;
// --------- OBJECTS DECLARATION ----------
// Declare neopixel Ring
Adafruit_NeoPixel ring(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = number of led
// Argument 2 = Pin
// Argument 3 = Pixel type
//This is how to declare var using RGB space for led ring
uint32_t red = ring.Color(255, 0, 0);
uint32_t purple = ring.Color(130, 0, 180);
uint32_t lightBlue = ring.Color(30, 30, 150);
void setup() {
// Start serial communication
Serial.begin(9600);
// INITIALIZE NeoPixel ring object (REQUIRED)
ring.begin();
// Set BRIGHTNESS to about 1/10 (max = 255)
ring.setBrightness(BRIGHTNESS);
}
void loop() {
// Set all pixel colors to 'off'
ring.clear();
// Read potentiometer and store value in var
potValue = analogRead(POT_PIN);
// Map the value on led ring scale (from 0 -> 1000 to 0 -> 12)
potValue = map(potValue, 0, 1000, 0, ring.numPixels());
// Serial print potentiometer value
Serial.print("Pot value mapped is :");
Serial.println(potValue);
// Set Led color depending on potentiometer value
for(int i = 0; i < potValue; i++){
ring.setPixelColor(i, red);
}
// Switch on the ring led
ring.show();
delay(300);
}