Я включив простий ескіз, який буде цикл одного RGB світлодіодних з використанням техніки синуса зникають
// Cycle a single RGB led using the sine fade technique
// For common cathode led
const uint8_t lights[360]={
0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 35, 37, 39,
42, 44, 47, 49, 52, 55, 58, 60, 63, 66, 69, 72, 75, 78, 81, 85, 88, 91, 94, 97, 101, 104, 107, 111, 114, 117, 121, 124, 127, 131, 134, 137,
141, 144, 147, 150, 154, 157, 160, 163, 167, 170, 173, 176, 179, 182, 185, 188, 191, 194, 197, 200, 202, 205, 208, 210, 213, 215, 217, 220, 222, 224, 226, 229,
231, 232, 234, 236, 238, 239, 241, 242, 244, 245, 246, 248, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 253, 253,
252, 251, 251, 250, 249, 248, 246, 245, 244, 242, 241, 239, 238, 236, 234, 232, 231, 229, 226, 224, 222, 220, 217, 215, 213, 210, 208, 205, 202, 200, 197, 194,
191, 188, 185, 182, 179, 176, 173, 170, 167, 163, 160, 157, 154, 150, 147, 144, 141, 137, 134, 131, 127, 124, 121, 117, 114, 111, 107, 104, 101, 97, 94, 91,
88, 85, 81, 78, 75, 72, 69, 66, 63, 60, 58, 55, 52, 49, 47, 44, 42, 39, 37, 35, 32, 30, 28, 26, 24, 22, 20, 18, 17, 15, 13, 12,
11, 9, 8, 7, 6, 5, 4, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const byte redpin = 3;
const byte greenpin = 5;
const byte bluepin = 6;
int loopdelay = 5000;//ms
int displaylength = 50;//ms
boolean showiterations = false;
//_______________________________
void setup() {
Serial.begin(9600);
}
void loop() {
for (int k=0; k<360; k++)
{
if (showiterations) {
Serial.print(k);
Serial.print(F(","));
}
analogWrite(redpin, lights[(k+120)%360]);
analogWrite(greenpin, lights[k]);
analogWrite(bluepin, lights[(k+240)%360]);
delay(displaylength);
}
if (showiterations) {
Serial.println(" ");
}
delay(loopdelay);
}
Цей нарис походить від публікації Instructables під назвою "Як зробити правильні кольори веселки та випадкових кольорів за допомогою кольорової моделі RGB", http://www.instructables.com/id/How-to-Make-Proper-Rainbow-and-Random-Colors-With-/
Крім того, він надає інформацію та обґрунтування різних методів велосипедних кольорів.
Якщо ви намагаєтеся похитнути кольори вздовж смуги, створюючи ефект веселки, у мене є ще один ескіз [від Adafruit, я вважаю], що зробить це. Я використовував його ефективно з різними конфігураціями кільця Neopixel. Ескіз демонструє ряд різних методів. В даний час я прокоментував виклики всіх, крім театруChaseRainbow, але ви можете вивчити їх усі.
#include
// following atatement should be wrapped with an ifdef for __AVR__, but this facility botches it up.
// As it is, formatting for the sketch is not quite right, and I do not have a solution for that.
#include
const byte PIN = 7;
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino 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)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
// Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800)`
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, 6, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
//This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
//End of trinket special code
strip.begin();
colorWipe(strip.Color(0, 0, 0), 50);//blank
strip.show();//Initialize all pixels to 'off'
}
void loop() {
//Some example procedures showing how to display to the pixels:
// colorWipe(strip.Color(255, 0, 0), 50);//Red
// colorWipe(strip.Color(0, 255, 0), 50);//Green
// colorWipe(strip.Color(0, 0, 255), 50);//Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50);//White RGBW
//Send a theater pixel chase in...
// theaterChase(strip.Color(127, 127, 127), 50);//White
// theaterChase(strip.Color(127, 0, 0), 50);//Red
// theaterChase(strip.Color(0, 0, 127), 50);//Blue
// rainbow(20);
// delay(50000);
// colorWipe(strip.Color(0, 0, 0), 50);//blank
// rainbowCycle(10);
// delay(5000);
// colorWipe(strip.Color(0, 0, 0), 50);//blank
// delay(5000);
theaterChaseRainbow(50);
// delay(5000);
// colorWipe(strip.Color(0, 0, 0), 50);//blank
// delay(5000);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i