Advertisement
macca-nz

NeoPixel RGB Wipe (no calls, longhand)

Apr 7th, 2022 (edited)
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Use the Serial monitor to start and stop the effect
  3.  * Enter s to start the wheel effect and enter q to stop the effect
  4.  */
  5.  
  6. //Constants
  7. #include <Adafruit_NeoPixel.h>        //The wizardry of addressable LEDs
  8.  
  9. #define PIN 6                         // Output pin for led strip
  10. #define NUMPIXELS 12                  // Number of LED Diodes
  11. #define SPEED 30                      // Creates the speed of an effect
  12.  
  13. //Make your "strip" object. Note the macro's used "NUMPIXELS, PIN"  
  14. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
  15.  
  16. //Variables
  17. char BTdata = 0;                      //Variable to store received serial data
  18. int count = 0;                        //Used to change wipe color
  19. int r, g, b;                          //Variables for changing the color
  20. bool wipeEffect = false;              //Turns effect On and OFF
  21.  
  22. void setup(){
  23.     Serial.begin(38400);              //Sets the baud for serial data transmission                              
  24.     strip.begin();                    //Adafruit_NeoPixel library object begin class "object.begin();)
  25.     strip.setBrightness(50);          //class to setup NeoPixel brightness level
  26.     strip.show();                     //Initialize all pixels to 'off'
  27. }
  28.  
  29. //Everything above is the "scope" and is common to both sketches
  30.  
  31. void loop(){                          
  32.    if(Serial.available() > 0)         // Send data only when you receive data:
  33.    {
  34.       BTdata = Serial.read();         //Read the  incoming  data and store it into variable data
  35.       Serial.println(BTdata);         //Print Value inside data in Serial monito
  36.  
  37.       if(BTdata == 'q')                       //Input q to turn strip LEDs OFF
  38.       wipeEffect = false;
  39.       r=0; g=0; b=0;
  40.           for(uint16_t i=0; i<strip.numPixels(); i++) {
  41.               strip.setPixelColor(i, strip.Color(r, g, b));
  42.               strip.show();
  43.               delay(SPEED);
  44.           }
  45.      
  46.       if(BTdata == 's')                       //Enter r into the serial monitor to run effect
  47.       wipeEffect = true;                      //Starts Wipe sequence
  48.       count = 0;
  49.    }
  50.    if(wipeEffect){                            //When true wipe is runnig
  51.       if(count == 0){                         //Incrementing counter changes the wipe color
  52.         r=255;g=0;b=0;                        //Display RED
  53.       }else if(count == 1){
  54.         r=0;g=0;b=0;                          //Clear
  55.       }else if(count == 2){
  56.         r=0;g=255;b=0;                        //Display Green
  57.       }else if(count == 3){
  58.         r=0;g=0;b=0;                          //Clear
  59.       }else if(count == 4){
  60.         r=0;g=0;b=255;                        //Display Blue
  61.       }else if(count == 5){
  62.         r=0;g=0;b=0;                          //Clear
  63.       }
  64.           for(uint16_t i=0; i<strip.numPixels(); i++) {
  65.               strip.setPixelColor(i, strip.Color(r, g, b));
  66.               strip.show();
  67.                   if(i == NUMPIXELS - 1){         //When we hit the last LED
  68.                       count++;                    //We increment by +1
  69.                           if(count > 5){          //Sequence complete
  70.                              count = 0;           //So we start again by resetting the counter
  71.                           }
  72.                   }
  73.                   delay(SPEED);
  74.           }
  75.    }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement