Neopixel (ring 12) controlled using bluefruit LE

Hi there everyone!

I'm completely new to arduino but have done a few tutorials and so far so good. I'm ok at understanding how code works through examples and it makes total sense... what I'm struggling with is putting the dots together.

I know how to control individual LED's on the neopixel and set their color. I can use a button to control an LED (not neopixel), using debounce. I can't seem to put those two together though and can't find anything online to do so. Ideally I want to be able to control the red, green and blue colors individually using 3 potentiometers (I have 1K Ohm potentiometers), so I can bleed colors together and play with it. I thought I would be able to find tutorials to do so online, but I can't seem to find them anywhere. Does anyone know of any tutorials I can follow to do this? (coming up with the code myself seems unrealistic).

Any help would be greatly appreciated!

Thanks in advance

I found this code it is using a potentiometer to control the NeoPixel. Does it help you?

#include <Adafruit_NeoPixel.h>

#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

int potpin = 0; 
int potval = 0;

void setup() {
  
  Serial.begin(9600);

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  potval = analogRead(potpin);
    Serial.println(potval);

  if ( potval <=40 ) {

//red_half
strip.setPixelColor(0, 255, 0, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 255, 0, 0);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 255, 0, 0);//4
strip.setPixelColor(5, 0, 0, 0);//5
strip.setPixelColor(6, 255, 0, 0);//6
strip.setPixelColor(7, 0, 0, 0);//7
strip.setPixelColor(8, 255, 0, 0);//8
strip.setPixelColor(9, 0, 0, 0);//9
strip.setPixelColor(10, 255, 0, 0);//10
strip.setPixelColor(11, 0, 0, 0);//11
strip.setPixelColor(12, 255, 0, 0);//12
strip.setPixelColor(13, 0, 0, 0);//13
strip.setPixelColor(14, 255, 0, 0);//14
strip.setPixelColor(15, 0, 0, 0);//15
strip.setPixelColor(16, 255, 0, 0);//16
strip.setPixelColor(17, 0, 0, 0);//17
strip.setPixelColor(18, 255, 0, 0);//18
strip.setPixelColor(19, 0, 0, 0);//19
strip.setPixelColor(20, 255, 0, 0);//20
strip.setPixelColor(21, 0, 0, 0);//21
strip.setPixelColor(22, 255, 0, 0);//22
strip.setPixelColor(23, 0, 0, 0);//23

strip.show();

}    

else if ( potval <= 80){
//red_full 
strip.setPixelColor(0, 255, 0, 0);//0
strip.setPixelColor(1, 255, 0, 0);//1
strip.setPixelColor(2, 255, 0, 0);//2
strip.setPixelColor(3, 255, 0, 0);//3
strip.setPixelColor(4, 255, 0, 0);//4
strip.setPixelColor(5, 255, 0, 0);//5
strip.setPixelColor(6, 255, 0, 0);//6

  
strip.show();

}

else if ( potval <= 120) {
//blue_half  
strip.setPixelColor(0, 0, 0,255 );//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 0, 0, 255);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 0, 0, 255);//4
strip.setPixelColor(5, 0, 0, 0);//5
strip.setPixelColor(6, 0, 0, 255);//6
strip.setPixelColor(7, 0, 0, 0);//7
strip.setPixelColor(8, 0, 0, 255);//8


strip.show();

}

 else if ( potval <= 160)
 {
//blue_full    
strip.setPixelColor(0, 0, 0,255 );//0
strip.setPixelColor(1, 0, 0,255);//1
strip.setPixelColor(2, 0, 0, 255);//2
strip.setPixelColor(3,0, 0,255);//3
strip.setPixelColor(4, 0, 0, 255);//4
strip.setPixelColor(5,0, 0,255);//5
strip.setPixelColor(6, 0, 0, 255);//6
strip.setPixelColor(7, 0, 0,255);//7


strip.show();

}
   
   else if ( potval <= 200){
//green_half   
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 0, 255, 0);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 0, 255, 0);//4
strip.setPixelColor(5, 0, 0, 0);//5
strip.setPixelColor(6, 0, 255, 0);//6

strip.show();

}
 
 else if ( potval <= 240){ 
//green_full
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 0, 255, 0);//1
strip.setPixelColor(2, 0, 255, 0);//2
strip.setPixelColor(3, 0, 255, 0);//3
strip.setPixelColor(4, 0, 255, 0);//4


strip.show();

}

else if ( potval <= 300)
{ 
//green/blue_half
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 0, 0, 255);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 0, 255, 0);//4
strip.setPixelColor(5, 0, 0, 0);//5
strip.setPixelColor(6, 0, 0, 255);//6
strip.setPixelColor(7, 0, 0, 0);//7
strip.setPixelColor(8, 0, 255, 0);//8
strip.setPixelColor(9, 0, 0, 0);//9
strip.setPixelColor(10, 0, 0, 255);//10
strip.setPixelColor(11, 0, 0, 0);//11
strip.setPixelColor(12, 0, 255, 0);//12


strip.show();

}

else if ( potval <= 340){ 
//green/blue_full
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 0,0, 255);//1
strip.setPixelColor(2, 0, 255, 0);//2
strip.setPixelColor(3, 0, 0, 255);//3


strip.show();

}

else if ( potval <= 380)
{ 
//green/red_half
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 255, 0, 0);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 0, 255, 0);//4
strip.setPixelColor(5, 0, 0, 0);//5



strip.show();

}

else if ( potval <= 420){ 
//green/red_full
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 255, 0, 0);//1
strip.setPixelColor(2, 0, 255, 0);//2
strip.setPixelColor(3, 255, 0, 0);//3


strip.show();

}

else if ( potval <= 460){ 
//green/magneta_half
 strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 255, 0, 255);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 0, 255, 0);//4
strip.setPixelColor(5, 0, 0, 0);//5
strip.setPixelColor(6, 255,0, 255);//6
strip.setPixelColor(7, 0, 0, 0);//7
 

strip.show();

}

else if ( potval <= 500){ 
//green/magenta_full
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 255, 0, 255);//1
strip.setPixelColor(2, 0, 255, 0);//2
strip.setPixelColor(3, 255, 0, 255);//3
strip.setPixelColor(4, 0, 255, 0);//4
strip.setPixelColor(5, 255, 0, 255);//5
strip.setPixelColor(6, 0, 255, 0);//6
strip.setPixelColor(7, 255, 0, 255);//7
strip.setPixelColor(8, 0, 255, 0);//8
strip.setPixelColor(9, 255, 0, 255);//9
strip.setPixelColor(10, 0, 255, 0);//10
strip.setPixelColor(11, 255, 0, 255);//11
strip.setPixelColor(12, 0, 255, 0);//12
strip.setPixelColor(13, 255, 0, 255);//13
strip.setPixelColor(14, 0, 255, 0);//14
strip.setPixelColor(15, 255, 0, 255);//15
strip.setPixelColor(16, 0, 255, 0);//16
strip.setPixelColor(17, 255, 0, 255);//17
strip.setPixelColor(18, 0, 255, 0);//18
strip.setPixelColor(19, 255, 0, 255);//19
strip.setPixelColor(20, 0, 255, 0);//20
strip.setPixelColor(21, 255, 0, 255);//21
strip.setPixelColor(22, 0, 255, 0);//22
strip.setPixelColor(23, 255, 0, 255);//23

strip.show();

}

else if ( potval <= 540){ 
//green/magenta_quarter
strip.setPixelColor(0, 0, 255, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 0, 0, 0);//2
strip.setPixelColor(3, 255, 0, 255);//3
strip.setPixelColor(4, 0, 0, 0);//4


strip.show();

}

else if ( potval <= 600){ 
//blue/magenta_half
strip.setPixelColor(0, 0, 0, 255);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 255, 0, 255);//2
strip.setPixelColor(3, 0, 0, 0);//3

  


strip.show();

}

else if ( potval <= 640){ 
//blue/magenta_full
strip.setPixelColor(0, 0, 0, 255);//0
strip.setPixelColor(1, 255, 0, 255);//1
strip.setPixelColor(2, 0, 0,255);//2
strip.setPixelColor(3, 255, 0, 255);//3
strip.setPixelColor(4, 0, 0, 255);//4
strip.setPixelColor(5, 255, 0, 255);//5
strip.setPixelColor(6, 0, 0, 255);//6



strip.show();

}

else if ( potval <= 700){ 
//red/magenta_half
strip.setPixelColor(0, 255, 0, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 255, 0, 255);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 255, 0, 0);//4
strip.setPixelColor(5, 0, 0, 0);//5
strip.setPixelColor(6, 255,0, 255);//6
strip.setPixelColor(7, 0, 0, 0);//7

   

strip.show();

}

else if ( potval >740){ 
//red/blue_half
strip.setPixelColor(0, 255, 0, 0);//0
strip.setPixelColor(1, 0, 0, 0);//1
strip.setPixelColor(2, 0, 255,0);//2
strip.setPixelColor(3, 0, 0, 0);//3
strip.setPixelColor(4, 0, 0, 255);//4
strip.setPixelColor(5, 0, 0, 0);//5


strip.show();

}

else if ( potval <= 780){ 
//red/green/blue_full
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 0, 255, 0);
strip.setPixelColor(2, 0, 0,255);
strip.setPixelColor(3, 255, 0, 0);
strip.setPixelColor(4, 0, 255, 0);
strip.setPixelColor(5, 0, 0, 255);
strip.setPixelColor(6, 255, 0, 0);
strip.setPixelColor(7, 0, 255, 0);
strip.setPixelColor(8, 0, 0, 255);
strip.setPixelColor(9, 255, 0, 0);
strip.setPixelColor(10,0 , 255, 0);

 

strip.show();

}





}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(20);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

This is great! I'll give it a go (hopefully I can work it out! Guessing it's just a case of linking the parts to the inputs stated).

Thank you very much for this! Where did you find this? I've spent all day looking for this type of code

ahh, just got it to work, was quite simple. But it doesn't seem to control the actual color... the potentiometer basically is just used to flick through a series of predefined lighting sequences.

I'm looking to control say just red from 0% to 100% through a potentiometer. I don't understand how I would implement that though. could I just use a digitalRead and then a digitalWrite?

and use say this piece of code to control colour... but change say the red colour to a defined variable that is predefined to carry out a digitalRead of the potentiometer and then input that as a value between 0-255 red?

I can understand the logic of what I need to do, I just don't have the experience of coding it.

I found some code to control the brightness of an LED using a potentiometer. It works fine for a simple LED but I can’t figure out what I have to change to make it work for the neopixel. I have added all the standard code to the start and void setup() for the neopixel to work.

Here is my code:

#include <Adafruit_NeoPixel.h>

 #define PIN 6
 
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);



// to the pins used:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 6; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);            
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);  
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);           

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);      
  Serial.print("\t output = ");      
  Serial.println(outputValue);   

  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(2);                     
}

Hi,
first of all sorry for the very delayed reply I am only rarely active on this forum.
If you want red going up from 0% to 100% I think you would have to do something like that

loop{

strip.setPixelColor(0, potval, 0, 0);

strip.show();
}

to simple? maybe I did not understand you right but setPixelColor worrks like that:

strip.setPixelColor(theLED number, RED, GREEN, BLUE);

well, so all you got to do is making the RED value equal to the potval 0 for 0% red and 255 for 100% red.

full code would be something like this:

#include <Adafruit_NeoPixel.h>

#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

int potpin = 0; 
int potval = 0;

void setup() {
  
  Serial.begin(9600);

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  potval = analogRead(potpin);
    Serial.println(potval);

strip.setPixelColor(0, potval, 0, 0);//0


strip.show();


}