I have a bit of a problem and I need some help, so hopefully someone can aid me.
I have this code written for a simple RGB light which fades from yellow to red when reed switch is off and produces continuous yellow light when reed switch is on. However, I need to have the same effect with NeoPixel leds (only 2) and I can't figure out how to adjust my code, so that it works smoothly. Could someone help me with that?
I looked through all the forums, and did find similar codes, but none of them fits what I need or are way too complicated for my beginners knowledge...
neopixels are very useful, and super easy to use. There are many wonderful things you can do with them, but getting them going is easy:
// you have to include the library
# include <Adafruit_NeoPixel.h>
// and where the strip is hooked up on the Arduino
# define PIXEL_PIN 6
// how many pixels on the strip?
# define N_LEDS 20
// make the neopixel object.
// here I use NEO_GRB + NEO_KHZ800. that's typical, but must match the strip you have
// it is called myStrip. Most just call it "strip"
Adafruit_NeoPixel myStrip(N_LEDS, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// in your setup, make one call to the begin method
myStrip.begin();
}
void loop() {
// in your code, change any pixel's color
// pixel number: NN from 0 to the end of the strip (NLEDS - 1) in this example 0..19
// red level: redBrightness 0 off to - 255 full brightness red
// green level: greenBrightness
// red level: blueBrightness
int NN = 4; // some pixel
byte redBrightness = 128; // half bright red +
byte greenBrightness = 0; // no green +
byte blueBrightness = 255; // full bright blue
myStrip.setPixelColor(NN, redBrightness, greenBrightness, blueBrightness);
// when you have set all the pixel colors, the call to show will update the physical strip:
myStrip.show();
}
I hope it is obvious that you can declare your variables like any normal variables and set them to get the pixel you want to be the color/brightness you need.
The strip should be connected with a series resistor and have a capacitor on its power leads, see
I plucked this page from the uber-guide, the whole thing is good reading, but this is... the least you need to know and more than enough to get into some serious trouble fun.
Thank you for your answer. It does produce the color I want, however I still do not know how to crossfade them and make them react to reed sensor.
Do you have knowledge in that?