18
Note: RGB is very bright, please protect your eyes and avoid looking directly.
1. Import the RGB library.
2. Declare the pin of Crowtail-RGB-LED.
3. Create an RGB LED instance and select parameters for it.
4. Initialize the RGB strip.
5. Create functions that light up the RGB dots.
6. Call the function we create to show the RGB light.
Code overview
Code usage
Import the RGB library. “Adafruit_NeoPixel.h” import many convenient functions to use the RGB, so
we just need to import the library and use.
RGB library: #include <Adafruit_NeoPixel.h>
Create an RGB instance called strip. There are three parameters we need to pass to the instance.
Parameter 1 is the number of pixels in strip. Parameter 2 is the pin number. Parameter 3 is the pixel
type flags, you can 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)
Create instance: Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, PIN, N
NEO_KHZ800);
“strip.Color()” is the build-in function of “Adafruit_NeoPixel.h” library. You can use this function to set
the color of the RGB. For example, strip.Color(20,0,0) mean set RGB strip to red color. In addition,
you can change the brightness of the RGB dots by changing the first parameter which we set to 20 in
here.
Choose RGB color: strip.Color(20, 0, 0);
“strip.setPixelColor()” is a built-in function of “Adafruit_NeoPixel.h” library. We use this function to set
which pixel or color of RGB strip we need to show. The first parameter represents the number of pixels
of the RGB strip, and the second parameter represents the color.
Set pixel color: strip.setPixelColor(i, c);
After we have set up how to display the RGB strip, we need to call this function to display the RGB
strip we have set.
RGB show function: strip.show();
Содержание Crowtail Deluxe Kit
Страница 47: ......