Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Use the Serial monitor to start and stop the effect
- * Enter s to start the wheel effect and enter q to stop the effect
- */
- //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_RGB + 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 effect On and 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;
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, strip.Color(r, g, b));
- strip.show();
- delay(SPEED);
- }
- if(BTdata == 's') //Enter r into the serial monitor to run effect
- wipeEffect = true; //Starts Wipe sequence
- count = 0;
- }
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement