Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.46 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_TYPE    WS2812B
  4. #define DATA_PIN    3       // Data pin led data written out
  5. #define COLOR_ORDER GRB     // Impact the show of the color
  6. #define BRIGHTNESS  5
  7. #define NUM_LEDS    140     // How many leds in the strip
  8. CRGB leds[NUM_LEDS];        // Array of leds
  9.  
  10. #define SPACE 14
  11.  
  12. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  13.  
  14. void setup() {
  15.   delay(2000);// power-up safety delay
  16.   Serial.begin(9600);
  17.   Serial.println("resetting");
  18.   LEDS.addLeds<LED_TYPE,DATA_PIN,GRB>(leds,NUM_LEDS);
  19.   LEDS.setBrightness(BRIGHTNESS);
  20. }
  21.  
  22. void fadeall() {
  23.   for(int i = 0; i < NUM_LEDS; i++) {
  24.       leds[i].nscale8(230); }
  25. }
  26.  
  27. void loop() {
  28.  
  29.   //WhitePurple();
  30.   //Jungle();
  31.   //MiddleOut();
  32.   //Blink();
  33.   //SparkSlowToFast();
  34.   //GlowGradient();
  35.   //BeatsPerMinute();
  36.   //Confetti();
  37.   Sinelon();
  38.   //ClearAll();
  39.  
  40. }
  41.  
  42. void WhitePurple() {
  43.  
  44.   // First slide the led in one direction
  45.   for(int i = 0; i < SPACE; i++) {
  46.     for(int j=0;j<NUM_LEDS/SPACE;j++){
  47.       if(j%2==0)leds[i+SPACE*j] = CRGB::White;
  48.       else      leds[i+SPACE*j] = CRGB::Purple;
  49.      
  50.     }
  51.     FastLED.show();
  52.     delay(80);
  53.   }
  54.  
  55.   delay(300);
  56.   for(int i = 0; i < SPACE; i++) {
  57.     for(int j=0;j<NUM_LEDS/SPACE;j++){
  58.       leds[i+SPACE*j] = CRGB::Black;
  59.     }
  60.     FastLED.show();
  61.     delay(100);
  62.   }
  63.  
  64. }
  65.  
  66. void Jungle() {
  67.  
  68.   fadeToBlackBy( leds, NUM_LEDS, 20);
  69.   byte dothue = 0;
  70.   for( int i = 0; i < 8; i++) {
  71.     leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
  72.     dothue += 1;//select the color purple
  73.   }
  74.  
  75.   FastLED.show();
  76.  
  77. }
  78.  
  79. void MiddleOut() {
  80.  
  81.   for(int i = 0; i < NUM_LEDS/2 ; i++){
  82.     leds[NUM_LEDS/2+i] = CRGB::DarkOrchid;
  83.     leds[NUM_LEDS/2-i] = CRGB::DarkOrchid;
  84.     FastLED.show();
  85.     delay(25);
  86.   }
  87.   for(int i = 0; i < NUM_LEDS/2 ; i++){
  88.     leds[NUM_LEDS/2+i] = CRGB::DarkSalmon;
  89.     leds[NUM_LEDS/2-i] = CRGB::DarkSalmon;
  90.     FastLED.show();
  91.     delay(25);
  92.   }
  93.  
  94.   for(int i = 0; i < NUM_LEDS/2 ; i++){
  95.     leds[NUM_LEDS-i] = CRGB::Black;
  96.     leds[i] = CRGB::Black;
  97.     FastLED.show();
  98.     delay(25);
  99.   }
  100.   for(int i = 0; i < NUM_LEDS/4+1 ; i++){
  101.     leds[NUM_LEDS-i] = CRGB::MediumSlateBlue;
  102.     leds[NUM_LEDS/2+i] = CRGB::MediumSlateBlue;
  103.     leds[NUM_LEDS/2-i] = CRGB::MediumSlateBlue;
  104.     leds[i] = CRGB::MediumSlateBlue;
  105.     FastLED.show();
  106.     delay(25);
  107.   }
  108.  
  109.  
  110. }
  111.  
  112. void Blink(){
  113.   fill_solid(leds,NUM_LEDS,0);
  114.   for(int i = 0; i < 6 ; i++){
  115.     leds[ random8(NUM_LEDS) ] += CRGB::White;
  116.     leds[ random8(NUM_LEDS) ] += CRGB::Purple;
  117.     leds[ random8(NUM_LEDS) ] += CRGB::DarkOrchid;
  118.   }
  119.   FastLED.show();
  120.   delay(25);
  121. }
  122.  
  123. void GlowGradient(){
  124.   //fill_gradient(leds,0, CHSV(50,255,255) ,NUM_LEDS-1, CHSV(150,255,255), SHORTEST_HUES);
  125.   for(int i = 1; i < 60 ; i=i+1){
  126.     fill_gradient_RGB(leds,0, CRGB::Purple ,NUM_LEDS-1, CRGB::Grey);
  127.     LEDS.setBrightness(i);
  128.     FastLED.show();
  129.     delay(10);
  130.   }
  131.   for(int i = 59; i >0 ; i=i-1){
  132.     fill_gradient_RGB(leds,0,CRGB::Purple,NUM_LEDS-1,CRGB::Grey);
  133.     LEDS.setBrightness(i);
  134.     FastLED.show();
  135.     delay(10);
  136.   }
  137.   for(int i = 1; i < 60 ; i=i+1){
  138.     fill_gradient_RGB(leds,0, CRGB::Gray ,NUM_LEDS-1, CRGB::Purple);
  139.     LEDS.setBrightness(i);
  140.     FastLED.show();
  141.     delay(10);
  142.   }
  143.   for(int i = 59; i >0 ; i=i-1){
  144.     fill_gradient_RGB(leds,0,CRGB::Gray,NUM_LEDS-1,CRGB::Purple);
  145.     LEDS.setBrightness(i);
  146.     FastLED.show();
  147.     delay(10);
  148.   }
  149. }
  150.  
  151. void SparkSlowToFast(){
  152.  
  153.  
  154. }
  155. void BeatsPerMinute(){
  156.   // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  157.   uint8_t BeatsPerMinute = 62;
  158.   CRGBPalette16 palette = PartyColors_p;
  159.   uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  160.   for( int i = 0; i < NUM_LEDS; i++) { //9948
  161.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  162.   }
  163.   FastLED.show();
  164.   delay(50);
  165. }
  166.  
  167. void Confetti()
  168. {
  169.   // random colored speckles that blink in and fade smoothly
  170.   fadeToBlackBy( leds, NUM_LEDS, 10);
  171.   int pos = random16(NUM_LEDS);
  172.   leds[pos] += CHSV( gHue + random8(64), 200, 255);
  173.   FastLED.show();
  174.   delay(50);
  175. }
  176.  
  177. void Sinelon()
  178. {
  179.   // a colored dot sweeping back and forth, with fading trails
  180.   fadeToBlackBy( leds, NUM_LEDS, 20);
  181.   int pos = beatsin16( 13, 0, NUM_LEDS-1 );
  182.   leds[pos] += CRGB::Purple;
  183.   FastLED.show();
  184.   delay(10);
  185. }
  186.  
  187. void ClearAll() {
  188.   for(int i = 0; i < NUM_LEDS ; i++){
  189.     leds[i] = CRGB::Black;
  190.     FastLED.show();
  191.   }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement