Teacher in need of help with a project

I was just looking at that!

i'll be writing a code now to try test. Roughly it will look like this

val = analogRead(potpin);
val = map(val, 0, 1023, 0, 1023);

Then try something like

// Turn the LED on, then pause
leds[val] = CRGB::Red;
FastLED.show();
delay(10);
leds[val] = CRGB::Black;
FastLED.show();
delay(10);

Special needs primary.

Try this? Just insert your data pin (for the strip) and the number of LEDs in your strip in NUM_LEDS. Will automatically adjust for any number of LEDs up to 256. Put a 0.1uF cap from the pot wiper to ground to filter noise.

#include <FastLED.h>

#define NUM_LEDS 16  // change number this for your strip

const byte DATA_PIN = 4;
const byte potPin = A0;

CRGB leds[NUM_LEDS];

void setup()
{
   Serial.begin(115200);
   LEDS.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
   LEDS.setBrightness(60);
}

void loop()
{
     int potValue = analogRead(potPin);
     fill_solid(leds, NUM_LEDS, CRGB::Black);
     byte ledToLight = map(potValue, 0, 1023, 0, NUM_LEDS);
     leds[ledToLight] = CRGB::Red;
     FastLED.show();   
}

Successfully tested with an Uno and 16 LED WS2812 strip on external 5V power.

3 Likes

I just tested mine and it worked perfectly

val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)

val = map(val, 0, 1023, 0, 10);

// Turn the LED on, then pause
leds[val] = CRGB::Red;
FastLED.show();
delay(1);
// Now turn the LED off, then pause
leds[val] = CRGB::Black;
FastLED.show();
delay(1

but now I'm going to test yours to compare! thank you so much for going through the effort

Yours works great too! love it and much more elegant than mine.

Something for me to think about, for 10 leds the movement is consistent but when I upped it 180 there was flicker between the leds as the pots readings were between values and it gets more unstable the more leds added for obvious reasons

Getting more stable pot values would be the solution here, I'm sure a hardware solution would be best but I'll look through the forums for a digital one too. Thank you all!

Maybe just have two switches.

Closing the left switch decrements a variable, closing the right switch increments.

Continually holding a switch closed continually inc/dec the variable.

The variable range can go from 0 to the number of LEDs.

1 Like

I edited one of my posts with the suggestion of putting a 0.1uF (or so, not critical) from the wiper of the pot (analog input) to ground to filter noise. That usually helps.

1 Like

BTW
Instead of using two switches, you can use a spring loaded, centre off, SPDT (single pole double throw) switch.


@LarryD You mean this? Toggle Switches | Cricklewood Electronics

1 Like

Exactly


One way to use:
For example, the centre terminal could be connected to a toggling Arduino output pin, frequency controlled by software.

Moving the switch, causes this frequency to present to either the increment or decrement input.


For flexibility, the output frequency could be controlled by, you guessed it, a potentiometer.

1 Like

You may want to consider adding a simple filter of some sort. In this case a sebnil/Moving-Avarage-Filter--Arduino-Library-: A moving average, also called rolling average, rolling mean or running average, is a type of finite impulse response filter (FIR) used to analyze a set of datum points by creating a series of averages of different subsets of the full data set. (github.com) might interest you.

1 Like

OP was hoping to track the pot speed with the light show..
Apart. from smoothing the pot value,he can keep track of the ‘previous LED, and always turn that off when turning the ‘new’ LED on.
That means no matter how fast the pattern changes, there won’t be stray lights left on before a fast move.

1 Like

You might consider a digital encoder control. The steps are absolute and eliminates the need for filtering.

1 Like