#include <Adafruit_NeoPixel.h>
// Define the GPIO pin connected to the potentiometer.
#define POTPIN 12 // Analog input pin (use GPIO34 as an example)
// Define the pin where the NeoPixel ring is connected
#define PIN 26 // Replace with the GPIO pin number you use
// Define the number of LEDs in the ring
#define NUM_LEDS 16
// Create the NeoPixel object
Adafruit_NeoPixel ring = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize the NeoPixel ring
Serial.begin(115200);
ring.begin();
ring.show(); // Turn off all LEDs initially
}
void loop() {
static bool richting = false;
static int numerLet = 0;
int analogValue = analogRead(POTPIN);
int timeOut = map(analogValue, 0, 4095, 30, 500);
static int timeStamp1;
if(millis() - timeStamp1 >= timeOut){
timeStamp1 = millis();
if(numerLet == NUM_LEDS - 2){
richting = true;
}else if(numerLet == 1){
richting = false;
}
if(richting == false){
ring.setPixelColor(numerLet, ring.Color(150, 0, 0));
ring.setPixelColor(numerLet + 1, ring.Color(255, 0, 0));
ring.setPixelColor(numerLet + 2, ring.Color(150, 0, 0));
ring.setPixelColor(numerLet - 1, ring.Color(0, 0, 0));
numerLet++;
ring.show();
}else if(richting == true){
ring.setPixelColor(numerLet, ring.Color(150, 0, 0));
ring.setPixelColor(numerLet - 1, ring.Color(255, 0, 0));
ring.setPixelColor(numerLet - 2, ring.Color(150, 0, 0));
ring.setPixelColor(numerLet + 1, ring.Color(0, 0, 0));
numerLet--;
ring.show();
}
Serial.println(numerLet);
}
}