Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Type "w" for wheel effect
- * Type "r" and you'll get just red leds
- * Type "q" to clear all leds
- */
- //Constants
- #include <Adafruit_NeoPixel.h> //The wizardry of addressable LEDs
- #define PIN 6 // Output pin for led strip
- #define NUMPIXELS 12 // Number of LED Diodes
- #define SPEED 30 // Creates the speed of an effect
- //Make your "strip" object. Note the macro's used "NUMPIXELS, PIN"
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- //Variables
- char BTdata = 0; //Variable to store received serial data
- int count = 0; //Used to change wipe color
- int r, g, b; //Variables for changing the color
- bool wipeEffect = false; //Turns wipe effect On and OFF
- bool single = false; //Turn single color On or Off
- void setup(){
- Serial.begin(38400); //Sets the baud for serial data transmission
- strip.begin(); //Adafruit_NeoPixel library object begin class "object.begin();)
- strip.setBrightness(50); //class to setup NeoPixel brightness level
- strip.show(); //Initialize all pixels to 'off'
- }
- //Everything above is the "scope" and is common to both sketches
- void loop(){
- if(Serial.available() > 0) // Send data only when you receive data:
- {
- BTdata = Serial.read(); //Read the incoming data and store it into variable data
- Serial.println(BTdata); //Print Value inside data in Serial monito
- if(BTdata == 'q'){ //Input q to turn strip LEDs OFF
- wipeEffect = false;
- r=0; g=0; b=0;
- single = true;
- }
- if(BTdata == 'r'){ //Input r to turn strip LEDs OFF
- wipeEffect = false;
- r=255; g=0; b=0;
- single = true;
- }
- if(BTdata == 'w'){ //Enter w into the serial monitor to run Wheel effect
- wipeEffect = true; //Starts Wipe sequence
- single = false;
- count = 0;
- }
- }
- if(single){
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, strip.Color(r, g, b));
- strip.show();
- delay(SPEED);
- }
- single = false;
- }
- if(wipeEffect){ //When true wipe is runnig
- if(count == 0){ //Incrementing counter changes the wipe color
- r=255;g=0;b=0; //Display RED
- }else if(count == 1){
- r=0;g=0;b=0; //Clear
- }else if(count == 2){
- r=0;g=255;b=0; //Display Green
- }else if(count == 3){
- r=0;g=0;b=0; //Clear
- }else if(count == 4){
- r=0;g=0;b=255; //Display Blue
- }else if(count == 5){
- r=0;g=0;b=0; //Clear
- }
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, strip.Color(r, g, b));
- strip.show();
- if(i == NUMPIXELS - 1){ //When we hit the last LED
- count++; //We increment by +1
- if(count > 5){ //Sequence complete
- count = 0; //So we start again by resetting the counter
- }
- }
- delay(SPEED);
- }
- }
- }
Add Comment
Please, Sign In to add comment