Be easy on me, im learning. I have flora and v2 neopixels. Im trying to control the neopixels individually, just to get a feel of how everything works. I am trying to follow the neopixel tutorial that breaks down the steps on how to assign colours to the pixels but I am starting to get errors and I'm not sure where Im going wrong. Any advise or code recommendations would be great. Im currently trying to assign a pixel a number using n, and then giving the RGB numbers after. Hope it makes sense what Im trying to do
Control Individual NeoPixels
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Control Individual NeoPixels
The problem is that you have not defined 'n' or 'red', 'green' or 'blue. The compiler does not know what those symbols mean.Im currently trying to assign a pixel a number using n, and then giving the RGB numbers after.
If you add the following declarations before your setPixelColor():
Code: Select all
int n = 1;
int red = 255;
int green = 255;
int blue = 255;
-
- Posts: 7
- Joined: Mon Jun 30, 2014 9:33 am
Re: Control Individual NeoPixels
Ok that makes sense. I am still having trouble turning on any specific Pixel. I will shoot up the code and what it looks like now with the modifications. Im not sure if I placed it in the wrong place or if I am still missing a chunk to make it all work
Thanks
Thanks
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Control Individual NeoPixels
You will also need to add "strip.show();" after setPixelColor() to display the new pixel color on the strip.
To light up a different pixel, change the value of 'n'. To change the color, modify the values of red, green and/or blue.
To light up a different pixel, change the value of 'n'. To change the color, modify the values of red, green and/or blue.
-
- Posts: 7
- Joined: Mon Jun 30, 2014 9:33 am
Re: Control Individual NeoPixels
Great! got it to work. Only thing Im confused about is that it doesnt seem to matter what number I assign n, as all the pixels will still work if addressed individually. I'm also looking to add in a switch of sorts, such as the Radio transmitter that was used on the backpack. I'll post the code I sort of put together. Again any help or recommendations are appreciated.
Thanks
Thanks
Code: Select all
#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(4, PIN, NEO_GRB + NEO_KHZ800);
const int cPin = 9;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(cPin, INPUT);
}
void loop() {
int n = 2;
int red = 255;
int green = 255;
int blue = 255;
if (cPin == HIGH){
strip.setPixelColor(n,red,green,blue);
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(2, 0, 255, 0);
strip.setPixelColor(1, 0, 0, 255);
strip.setPixelColor(3, 255, 0, 0);
strip.show();
}
if (cPin == LOW) {
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.show();
}
}
Last edited by adafruit_support_bill on Thu Aug 07, 2014 2:37 pm, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.
Please be positive and constructive with your questions and comments.