#include #ifdef __AVR__ #include #endif #include #define RxD 2 #define TxD 0 #define ledPIN 1 SoftwareSerial BT(RxD,TxD); // 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) Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, ledPIN, NEO_GRB + NEO_KHZ800); int wait=20;//determines the speed of effects int val=5;//the value 1-9 entered by user char mode='m';//the mode entered by the user char oldMode='m';//the previous mode entered by the user int brightness = 8; boolean stopFlag = false; int r=255;//red val int g=255;//green val int b=255;//blue val int j=0; boolean pastel=false; void setup(){ BT.begin(9600); strip.begin(); strip.show(); // Initialize all pixels to 'off' delay(1000); int j=0; } void loop(){ if(BT.available()){ oldMode=mode; mode=BT.read(); } j=(j+1)%255; //counter, used for timing of transitions, 0 to 255 then loop switch (mode) { case 'f'://f //fade mode for(int i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(j)); } break; case 'm'://m //mix fade for(int i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } break; case 's'://s //toggle stopFlag stopFlag=!stopFlag; mode=oldMode; break; case '0'://0 //change speed wait=1000; mode=oldMode; break; case '1'://1 //change speed wait=200; mode=oldMode; break; case '2'://2 //change speed wait=80; mode=oldMode; break; case '3'://3 //change speed wait=20; mode=oldMode; break; case '4'://4 //change speed wait=2; mode=oldMode; break; case '5'://5 //change brightness brightness=1; mode=oldMode; break; case '6'://6 //change brightness brightness=2; mode=oldMode; break; case '7'://7 //cahnge brightness brightness=5; mode=oldMode; break; case '8'://8 //change brightness brightness=7; mode=oldMode; break; case '9'://9 //change brightness brightness=10; mode=oldMode; break; case 'p'://p pastel=!pastel; mode=oldMode; break; case 'w'://w //white for(int i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i,255*brightness/10,255*brightness/10,255*brightness/10); } break; default: // if invalid input, print the instructions printInstructions(); mode=oldMode; break; } if(stopFlag==false){ strip.show(); } delay(wait); } void printInstructions(){ BT.print("f=fade together, m=mix fade, w=white, p=pastel\r\n"); BT.print("0-4=speed,6-9=brightness, s=stop/start\r\n"); } //******From adafruit's neopixel example // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { if (pastel==false){ WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color((255 - WheelPos * 3)*brightness/10, 0, WheelPos * 3*brightness/10); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3*brightness/10, (255 - WheelPos * 3)*brightness/10); } WheelPos -= 170; return strip.Color(WheelPos * 3*brightness/10, (255 - WheelPos * 3)*brightness/10, 0); } else{ WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color((255 - WheelPos * 2)*brightness/10, 85*brightness/10, (WheelPos * 2+85)*brightness/10); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(85*brightness/10, (WheelPos * 2+85)*brightness/10, (255 - WheelPos * 2)*brightness/10); } WheelPos -= 170; return strip.Color((WheelPos * 2+85)*brightness/10, (255 - WheelPos * 2)*brightness/10, 116*brightness/10); } }