Arduino – NeoPixel – strandtest
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
#include <Adafruit_NeoPixel.h> #define PIN 2 Adafruit_NeoPixel strip=Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); strip.show(); } void loop() { colorWipe(strip.Color(255, 0, 0), 50); colorWipe(strip.Color(0, 255, 0), 50); colorWipe(strip.Color(0, 0, 255), 50); theaterChase(strip.Color(127, 127, 127), 50); theaterChase(strip.Color(127, 0, 0), 50); theaterChase(strip.Color(0, 0, 127), 50); rainbow(20); rainbowCycle(20); theaterChaseRainbow(50); } void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { for(i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); } } void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256*5; j++) { for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j++) { for (int q=0; q < 3; q++) { for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); } strip.show(); delay(wait); for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); } } } } void theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { for (int q=0; q < 3; q++) { for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, Wheel( (i+j) % 255)); } strip.show(); delay(wait); for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); } } } } uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } |