User Tools

Site Tools


projects:neopixel-bandwidth-room-light

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
projects:neopixel-bandwidth-room-light [2017-10-27 18:08]
trinitor
projects:neopixel-bandwidth-room-light [2017-12-03 13:20]
trinitor [Programm]
Line 68: Line 68:
 const int LEDPIN          =   15; const int LEDPIN          =   15;
 const int NUMPIXELS        300; const int NUMPIXELS        300;
 +
 int displayrefresh        =   10; int displayrefresh        =   10;
 int shiftpixels              2; //2 = shift pixels, 1 = no shift int shiftpixels              2; //2 = shift pixels, 1 = no shift
 +int alwaysoff                0; //1 = blank 1st pixel if no new color
 ////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
  
Line 79: Line 81:
 // echo "{red:0,green:100,blue:0,pin:50}" | nc -w 0 -u 192.168.x.x 2342 // echo "{red:0,green:100,blue:0,pin:50}" | nc -w 0 -u 192.168.x.x 2342
 // echo "{scroll:1}" | nc -w 0 -u 192.168.x.x 2342 // echo "{scroll:1}" | nc -w 0 -u 192.168.x.x 2342
 +// echo "{effect:1}" | nc -w 0 -u 192.168.x.x 2342
 +// echo "{effect:1,option1:20}" | nc -w 0 -u 192.168.x.x 2342
  
  
Line 107: Line 111:
 void loop() void loop()
 { {
-  int red      = 0; +  int red       = 0; 
-  int green    = 0; +  int green     = 0; 
-  int blue     = 0; +  int blue      = 0; 
-  int refresh  = 0; +  int refresh   = 0; 
-  int scroll   = 0; +  int scroll    = 0; 
-  int pixel    = 0; +  int pixel     = 0; 
-  int all      = 0; +  int all       = 0; 
-  int clearall = 0;+  int clearall  = 0; 
 +  int effect    = 0; 
 +  int option1   = 0;
      
   int packetSize = Udp.parsePacket();   int packetSize = Udp.parsePacket();
Line 145: Line 151:
         all      = json["all"];         all      = json["all"];
         clearall = json["clearall"];         clearall = json["clearall"];
-        scroll   = json["scroll"]; +        scroll   = json["scroll"]; 
 +        effect   = json["effect"]; 
 +        option1  = json["option1"];
       }       }
     }     }
Line 197: Line 205:
   }   }
  
 +  if (effect == 1) {
 +    if (option1 == 0) { option1 = 128; }
 +    fade(option1);
 +  } 
 +  else if (effect == 2) {
 +    if (option1 == 0) { option1 = 20; }
 +    rainbow(option1);
 +  }
   // set color of Pixel   // set color of Pixel
   // new color proviced color changed?   // new color proviced color changed?
-  if (red >0 || green >0 || blue >0) {+  else if (red >0 || green >0 || blue >0) {
     //read current color     //read current color
     uint32_t CurrentColor = pixels.getPixelColor(1);     uint32_t CurrentColor = pixels.getPixelColor(1);
Line 228: Line 244:
     if (shiftpixels == 2) {     if (shiftpixels == 2) {
       uint32_t color = pixels.getPixelColor(1);       uint32_t color = pixels.getPixelColor(1);
-      pixels.setPixelColor(0, color);+      if (alwaysoff = 1) { 
 +        pixels.setPixelColor(0, color); 
 +      } else { 
 +        pixels.setPixelColor(0, 0, 0, 0); 
 +      }
     }     }
   }   }
Line 235: Line 255:
  
   delay(displayrefresh);   delay(displayrefresh);
 +}
 +
 +// Effects
 +void fade(int maxBrightness){
 +  for(int brightness = 0; brightness < maxBrightness; brightness++) { 
 +    for(int i = 0; i < NUMPIXELS; i++ ) {
 +      pixels.setPixelColor(i, pixels.Color(0, brightness, 0));
 +    }
 +    pixels.show();
 +    delay(5);
 +  }
 +  // Fade OUT
 +  for(int brightness = maxBrightness; brightness >= 0; brightness--) { 
 +    for(int i = 0; i < NUMPIXELS; i++ ) {
 +      pixels.setPixelColor(i, pixels.Color(0, brightness, 0));
 +    }
 +    pixels.show();
 +    delay(5);
 +  }
 +}
 +
 +void rainbow(uint8_t wait) {
 +  uint16_t i, j;
 +
 +  for(j=0; j<256; j++) {
 +    for(i=0; i < NUMPIXELS; i++) {
 +      pixels.setPixelColor(i, Wheel((i+j) & 255));
 +    }
 +    pixels.show();
 +    delay(wait);
 +  }
 +  for(int i=0; i<NUMPIXELS; i++) {
 +    pixels.setPixelColor(i, pixels.Color(0,0,0));
 +  }
 +  pixels.show();
 +}
 +
 +uint32_t Wheel(byte WheelPos) {
 +  WheelPos = 255 - WheelPos;
 +  if(WheelPos < 85) {
 +    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
 +  }
 +  if(WheelPos < 170) {
 +    WheelPos -= 85;
 +    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
 +  }
 +  WheelPos -= 170;
 +  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
 } }
 </code> </code>
projects/neopixel-bandwidth-room-light.txt · Last modified: 2017-12-23 11:49 by trinitor