Potentiometer back and forth movement individual pixel

Hi

I am trying to use a Potentiometer to control the back and forth movement of an individual pixel or group of pixels (say 10) on a neopixel strip. I have been trying for days.

Has anyone achieved this, or knows of some links or tutorials.

Any help would be greatly appreciated!

Thank you so much,

Cory

Which part do you need help with?

  • Reading the potentiometer

  • Making a decision based on the reading

  • Moving the pixel according to that decision

Thanks for your possible help. I seem to have gotten past the potentiometer pixel issue.

I tried to combined two sketches that seems to be working okay individually, and it won’t load. It gets down to the very end with this error code.

exit status 1

expected ‘}’ at end of input

I have tried everything with } I have used up to three (which I’ve never seen more of) down to one with no luck.

If you could take a look and see if you can figure out why it seems to stop loading I would greatly appreciate it.

I Know I’ll have some code tweaking to do once it loads but Maybe I’m getting close to my ultimate solution.

Thank you so much for your time.

Cory

// 
//Arduino code for Neopixel LED controller
// using a potentiometer and switch button
// (C) Ismail Uddin, 2015
// www.scienceexposure.com

#include <FastLED.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
 #define PSTR // Make Arduino Due happy
#endif

#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 31
#define NUM_PIXELS 31
#define DATA_PIN 5
Adafruit_NeoPixel strip = Adafruit_NeoPixel(31, DATA_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, DATA_PIN, NEO_GRB + NEO_KHZ800);

const byte potPin = A0;
const byte potPin2 = A2;
int litPixel = (6);
int val = 0;
int val_2 = 0;
int colorVal = 0;
int reading = 0;
int x;
int prevVal = 0;
int prevVal_2 = 0;
int switchPin = 13;
int Brightness = 0;
boolean lastBtn = LOW;
boolean NeopixelColor = false;
boolean lastButton = LOW;

uint32_t c_orange = strip.Color(248, 73, 3);

CRGB leds[NUM_LEDS];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  strip.begin();
  strip.show();
  FastLED.show();
  pinMode(switchPin, INPUT);
   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
   pixels.begin(); // This initializes the NeoPixel library
 
   }

void loop() {
  // put your main code here, to run repeatedly:
  //leds[25] = CRGB::Red; 
        //FastLED.show(); 
        //delay(30); 
    //strip.setPixelColor(0-31,100,0,100);
    //strip.setPixelColor(20,100,0,100);
    int newPixel = map(analogRead(potPin2), 0, 1023, 20, 25);
  pixels.setBrightness(10);
  if (newPixel != litPixel)
  {
    for (int i = 21; i < NUM_PIXELS; i++)
    for (int j = 0; j <21; j++)
    {
      if (i > newPixel && i < newPixel+6)
      {
          pixels.setPixelColor(i, pixels.Color(0,0, 255));
          pixels.setPixelColor(j, pixels.Color(100,0, 100));
          
      }
      else
      {
           pixels.setPixelColor(i, pixels.Color(255, 255, 255));
      }
    }
  pixels.show(); // This sends the updated pixel color to the hardware.
    litPixel = newPixel;
  reading = analogRead(potPin);
  //reading = analogRead(potPin_2);
  val = (reading/1024.0) * 10;
  //val_2 = (reading/1024.0) * 25;
  colorVal = (reading/1024.0) * 255;
 
  
  if (digitalRead(switchPin) == HIGH && lastButton == LOW)
  {
    //delay(250); // Account for contact debounce
    //NeopixelColor = !NeopixelColor;
    
  }
  
  if (NeopixelColor == false)
  {
    // Neopixel LED number code
    strip.setBrightness(10);
    if (val != prevVal)
    //if (val_2 != prevVal_2)
    
    {
      for ( x = 0; x < val; x++)
      
      
      //for ( x = 0; x < val_2; x++) 
      
        //for ( x = 10; x >= val; x--);
      {
        strip.setPixelColor(10 + x,CRGB::Blue); // increasing *
        strip.setPixelColor(9 + x,CRGB::Blue); // increasing *
        strip.setPixelColor(10 - x,CRGB::Blue); // decreasing 
        //strip.setPixelColor(9 + x,0); // increasing *
        //strip.setPixelColor(11 - x,0); // decreasing
      }
      //for (x=val; x<22; x++)
      //for (x=val_2; x<31; x++) 
      { 
        strip.setPixelColor(10 + x,100,0,100); // increasing Erasing *
        strip.setPixelColor(10 - x,100,0,100); // decreasing Erasing
        //strip.setPixelColor(10 + x,0,0,0); // increasing
        //strip.setPixelColor(9 - x,0,0,0); // decreasing
        //strip.show();
       }
      prevVal = val;
      //prevVal_2 = val_2;
    }
//    else
    {
      strip.show();
    }
    
  }
  else
  {
    // Neopixel Color code
    for (x=0; x < prevVal; x++)
    {
      //strip.setPixelColor(x,colorVal,0,255-colorVal);
      strip.show();
    }
  }
}

Just Letting you know I got it Working.

Cory