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
Previous revision
Next revision Both sides next revision
projects:neopixel-bandwidth-room-light [2017-10-15 08:44]
trinitor [SNMP Example]
projects:neopixel-bandwidth-room-light [2017-10-27 18:08]
trinitor
Line 1: Line 1:
 ====== NeoPixel Bandwidth Room Light ====== ====== NeoPixel Bandwidth Room Light ======
 +
 +{{:projects:neopixel_bandwidth_room_light.gif?direct|}}
  
 ===== Overview ===== ===== Overview =====
Line 57: Line 59:
 ///////////////////////////// config ///////////////////////////// ///////////////////////////// config /////////////////////////////
 // Network // Network
-const char*  ssid         = "your_wifi_ssid"; +const char*  ssid         = "yourSSID"; 
-const char*  password     = "our_wifi_psk";+const char*  password     = "yourPassw0rd";
 unsigned int localUdpPort = 2342; unsigned int localUdpPort = 2342;
-char incomingPacket[255];  // buffer for incoming packets +char incomingPacket[255];   
-char replyPacket[] = "message received";  // a reply string to send back+char replyPacekt[] = "message received"; 
  
 // neopixel // neopixel
Line 67: Line 69:
 const int NUMPIXELS        300; const int NUMPIXELS        300;
 int displayrefresh        =   10; int displayrefresh        =   10;
 +int shiftpixels              2; //2 = shift pixels, 1 = no shift
 ////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
  
-// usage examples:  +// usage examples: 
-// echo "{red:0,green:100,blue:0}" | nc -w -u 192.168.x.x 2342 +// echo "{red:0,green:100,blue:0}" | nc -w -u 192.168.x.x 2342 
-// echo "{red:32,green:32,blue:0,all:1}" | nc -w -u 192.168.x.x 2342 +// echo "{red:32,green:32,blue:0,all:1}" | nc -w -u 192.168.x.x 2342 
-// echo "{clearall:1}" | nc -w 1 -u 192.168.x.x 2342+// echo "{clearall:1}" | nc -w 0 -u 192.168.x.x 2342 
 +// echo "{refresh: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
  
  
Line 101: Line 107:
 void loop() void loop()
 { {
-  int red      = -1+  int red      = 0
-  int green    = -1+  int green    = 0
-  int blue     -1+  int blue     0
-  int refresh  =  0; +  int refresh 0; 
-  int all      =  0; +  int scroll   = 0; 
-  int clearall =  0;+  int pixel    = 0; 
 +  int all      = 0; 
 +  int clearall = 0;
      
   int packetSize = Udp.parsePacket();   int packetSize = Udp.parsePacket();
   if (packetSize)   if (packetSize)
   {   {
-//    Serial.println("Read Packet"); 
     // receive incoming UDP packets     // receive incoming UDP packets
 //    Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort()); //    Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
Line 120: Line 127:
       incomingPacket[len] = 0;       incomingPacket[len] = 0;
 //      Serial.printf("UDP packet contents: %s", incomingPacket); //      Serial.printf("UDP packet contents: %s", incomingPacket);
-//      Serial.println("Parse Packet"); 
       StaticJsonBuffer<200> jsonBuffer;       StaticJsonBuffer<200> jsonBuffer;
       JsonObject& json = jsonBuffer.parseObject(incomingPacket);       JsonObject& json = jsonBuffer.parseObject(incomingPacket);
Line 136: Line 142:
         blue     = json["blue"];         blue     = json["blue"];
         refresh  = json["refresh"];         refresh  = json["refresh"];
 +        pixel    = json["pixel"];
         all      = json["all"];         all      = json["all"];
         clearall = json["clearall"];         clearall = json["clearall"];
 +        scroll   = json["scroll"]; 
       }       }
     }     }
Line 144: Line 152:
 //    Serial.println("send UDP response"); //    Serial.println("send UDP response");
 //    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); //    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
-//    Udp.write(replyPacket);+//    Udp.write(replyPacekt);
 //    Udp.endPacket(); //    Udp.endPacket();
   }   }
  
-  // new refresh rate received+  // new refreshrate received
   if (refresh > 0) {   if (refresh > 0) {
     Serial.println("new refresh rate received");     Serial.println("new refresh rate received");
Line 154: Line 162:
   }   }
  
-  // set all pixel to black if clearall was set to 1+  // change of scroll parameter 
 +  if (scroll > 0) { 
 +    Serial.printf("change scroll: %i", scroll); 
 +    if (scroll == 1) { 
 +      shiftpixels = 1; 
 +    } else { 
 +      shiftpixels = 2; 
 +    } 
 +  } 
 + 
 +  // set all pixel to color
   if(all == 1) {   if(all == 1) {
-//    Serial.println("set all pixels");+    Serial.printf("set all pixels -> red: %i, green: %i, blue: %i", red, green, blue);
     for(int i=0; i<NUMPIXELS; i++) {     for(int i=0; i<NUMPIXELS; i++) {
       pixels.setPixelColor(i, pixels.Color(red,green,blue));       pixels.setPixelColor(i, pixels.Color(red,green,blue));
Line 164: Line 182:
   // set all pixel to black if clearall was set to 1   // set all pixel to black if clearall was set to 1
   if(clearall == 1) {   if(clearall == 1) {
-//    Serial.println("clear all received");+    Serial.println("clear all received");
     for(int i=0; i<NUMPIXELS; i++) {     for(int i=0; i<NUMPIXELS; i++) {
       pixels.setPixelColor(i, pixels.Color(0,0,0));       pixels.setPixelColor(i, pixels.Color(0,0,0));
Line 171: Line 189:
  
   //shift pixels    //shift pixels 
-  for(int i=NUMPIXELS; i>=0; i--) { +  if (shiftpixels == 2) { 
-    uint32_t color = pixels.getPixelColor(i); +//    Serial.println("shift pixels"); 
-    pixels.setPixelColor(i+1, color);+    for(int i=NUMPIXELS; i>=0; i--) { 
 +      uint32_t color = pixels.getPixelColor(i); 
 +      pixels.setPixelColor(i+1, color); 
 +    }
   }   }
  
-  //set color of Pixel 0+  // set color of Pixel
   // new color proviced color changed?   // new color proviced color changed?
-  if (red >=0 || green >=0 || blue >=0) {+  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 185: Line 206:
     uint8_t  CurrentBlue  = CurrentColor;     uint8_t  CurrentBlue  = CurrentColor;
  
-    //if new color < 0 reuse the old color +    // if no new color was set -> reuse the old color 
-    if (red   0) {red   = CurrentRed;+    if (red   == 0) {red  = CurrentRed;
-    if (green 0) {green = CurrentGreen;+    if (green == 0) {green = CurrentGreen;
-    if (blue  0) {blue  = CurrentBlue;+    if (blue  == 0) {blue  = CurrentBlue;
-     + 
-//    Serial.printf("New color LED 0 -> red: %i, green: %i, blue: %i", red, green, blue); +    // set pixel 0 in case no spesific pixel was requested 
-    pixels.setPixelColor(0, pixels.Color(red,green,blue));+    if (pixel == 0) { 
 +//      Serial.printf("New color LED 0 -> red: %i, green: %i, blue: %i \n", red, green, blue); 
 +      pixels.setPixelColor(0, pixels.Color(red,green,blue)); 
 +    } else { 
 +      // if spesific pixel was request change the color and also copy pixel 1 to pixel 0 
 +//      Serial.printf("New color LED %i -> red: %i, green: %i, blue: %i \n", pixel, red, green, blue); 
 +      pixels.setPixelColor(pixel, pixels.Color(red,green,blue)); 
 +      if (shiftpixels == 2) { 
 +        uint32_t color = pixels.getPixelColor(1); 
 +        pixels.setPixelColor(0, color); 
 +      } 
 +    }
   } else {   } else {
 //    Serial.printf("no new color"); //    Serial.printf("no new color");
-    uint32_t color = pixels.getPixelColor(1); +    if (shiftpixels == 2) { 
-    pixels.setPixelColor(0, color);+      uint32_t color = pixels.getPixelColor(1); 
 +      pixels.setPixelColor(0, color); 
 +    }
   }   }
  
Line 276: Line 310:
  
      if [ "$OUT2" -gt "$OUT" ] || [ "$IN2" -gt "$IN" ] ; then      if [ "$OUT2" -gt "$OUT" ] || [ "$IN2" -gt "$IN" ] ; then
 +       clear
        if [ "$TIME2" == "$TIME" ]; then        if [ "$TIME2" == "$TIME" ]; then
          TIME=1          TIME=1
Line 290: Line 325:
        echo Inbound %: $INPUTPERCENT"%"        echo Inbound %: $INPUTPERCENT"%"
        echo Outbound %: $OUTPUTPERCENT"%"        echo Outbound %: $OUTPUTPERCENT"%"
-       RED=$(echo "$MAXBRIGHTNESS*$OUTPUTPERCENT/100" | bc) +       RED=$(echo "($MAXBRIGHTNESS*$OUTPUTPERCENT/100)+1" | bc) 
-       GREEN=$(echo "$MAXBRIGHTNESS*$INPUTPERCENT/100" | bc)+       GREEN=$(echo "($MAXBRIGHTNESS*$INPUTPERCENT/100)+1" | bc)
        echo "{red:$RED,green:$GREEN}"        echo "{red:$RED,green:$GREEN}"
        echo "{red:$RED,green:$GREEN}" | nc -w 0 -u $NEOPIXELIP $NEOPIXELPORT        echo "{red:$RED,green:$GREEN}" | nc -w 0 -u $NEOPIXELIP $NEOPIXELPORT
projects/neopixel-bandwidth-room-light.txt · Last modified: 2017-12-23 11:49 by trinitor