Arduino – NeoPixel – Variable Resistor
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 |
#include <Adafruit_NeoPixel.h> #define PIN 2 Adafruit_NeoPixel strip=Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800); int varRes=A1; int speeds=0; void setup() { strip.begin(); strip.show(); } void loop() { rainbowCycle(20); } 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); speeds=map(analogRead(varRes), 0, 1023, 0, 20); delay(speeds); } } 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); } |