User Tools

Site Tools


projects:neopixel-backpack

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
projects:neopixel-backpack [2019/12/03 14:39]
seven
projects:neopixel-backpack [2019/12/05 14:27] (current)
seven [Current Arduino Code]
Line 23: Line 23:
  
 ==== Current Arduino Code ==== ==== Current Arduino Code ====
- 
-Quick and dirty code, need to clean up. 
- 
  
   #include <​Adafruit_NeoPixel.h>​   #include <​Adafruit_NeoPixel.h>​
   #define PIN 15   #define PIN 15
-  #​define ​NUM_LEDS 75 +  #​define ​LED_AMOUNT 72 
-  Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);​+  #define PIXEL_SPEED 100 
 +  ​ 
 +  Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_AMOUNT, PIN, NEO_GRB + NEO_KHZ800);​
   ​   ​
   void setup() {   void setup() {
     strip.begin();​     strip.begin();​
-    strip.show(); ​// Initialize all pixels to '​off'​+    strip.show();​
   }   }
   ​   ​
   void loop() {   void loop() {
-    ​Main(0x50, 0, 0x50, 4, 60, 0); +    ​TestFun(20, 0, 0, 0, 20, 0); 
-    Party(0x50, 0x50, 0, 2, 100, 100); +    for (int a=0; a<2a++) { 
-    Interrupt(0x50, 0, 0x50, 25, 100); +      ​SnakeFun(2020, 0, 20 , 0, 20);
-    Main1(0x50, 0x50, 0, 4, 60, 0); +
-    Party(0x50, 0, 0x50, 2, 100, 100); +
-    Interrupt(0x50,​ 0x50, 0, 25, 100); +
-  } +
-   +
-  void Main(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){ +
-    CenterToOutside(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​ +
-    OutsideToCenter(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​ +
-    CenterToOutside(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​ +
-    OutsideToCenter(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​ +
-  } +
-   +
-  void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { +
-    for(int ​i =((NUM_LEDS-EyeSize)/​2);​ i>=0; i--) { +
-      setAll(0,​0,​0);​ +
-       +
-      setPixel(i, 0x50, 0x50, 0); +
-      for(int j = 1; j <= EyeSizej++) { +
-        setPixel(i+j,​ red, green, blue); +
-      ​+
-      setPixel(i+EyeSize+1,​ 0x500x50, 0); +
-   +
-      setPixel(NUM_LEDS-i0x50, 0x50, 0); +
-      for(int j = 1; j <= EyeSize; j++) { +
-      setPixel(NUM_LEDS-i-jred, green, blue); +
-      } +
-      setPixel(NUM_LEDS-i-EyeSize-1,​ 0x50, 0x50, 0); +
-     +
-      showStrip();​ +
-      delay(SpeedDelay);+
     }     }
-    ​delay(ReturnDelay);​ +    ​MaxFun(2020020 ,020); 
-  } +    for (int a=0; a<​2; ​a++) { 
-   +      ​SnakeFun(20, 0, 2020 20, 0);
-  void OutsideToCenter(byte redbyte greenbyte blueint EyeSizeint SpeedDelayint ReturnDelay{ +
-    for(int ​= 0; i<=((NUM_LEDS-EyeSize)/​2)i++) { +
-      ​setAll(0,0,0); +
-      +
-      setPixel(i0x500x50, 0); +
-      for(int j = 1; j <= EyeSize; j++) { +
-        setPixel(i+j,​ red, green, blue); +
-      } +
-      setPixel(i+EyeSize+1,​ 0x50, 0x50, 0); +
-    +
-      setPixel(NUM_LEDS-i,​ 0x50, 0x50, 0); +
-      for(int j = 1; j <= EyeSize; j++) { +
-        setPixel(NUM_LEDS-i-j,​ red, green, blue); +
-      } +
-      setPixel(NUM_LEDS-i-EyeSize-1,​ 0x50, 0x50, 0); +
-    +
-      showStrip();​ +
-      delay(SpeedDelay);+
     }     }
-    ​delay(ReturnDelay);+    ​MaxFun(20, 0, 20, 20 , 20, 0);
   }   }
   ​   ​
-  void Main1(byte redbyte greenbyte blue, int EyeSize, int SpeedDelay, int ReturnDelay){ +  void TestFun(int MAIN_COLOR_REDint MAIN_COLOR_GREENint MAIN_COLOR_BLUE, int SEC_COLOR_RED, int SEC_COLOR_GREEN 
-    CenterToOutside1(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​ +  ​int SEC_COLOR_BLUE) {
-    OutsideToCenter1(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​ +
-    CenterToOutside1(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​ +
-    OutsideToCenter1(red,​ green, blue, EyeSize, SpeedDelay, ReturnDelay);​+
   }   }
   ​   ​
-  void CenterToOutside1(byte redbyte greenbyte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { +  void SnakeFun(int MAIN_COLOR_REDint MAIN_COLOR_GREENint MAIN_COLOR_BLUE, int SEC_COLOR_RED, int SEC_COLOR_GREEN, int SEC_COLOR_BLUE) { 
-    ​for(int =((NUM_LEDS-EyeSize)/​2);​ i>=0; i--) { +    int RAD_LED_AMOUNT ​random(12,LED_AMOUNT+1); 
-      setAll(0,0,0); +    ​int RAD_MAIN_LENGTH = random(2,10);  
-    ​ +    for (int i=0i<=RAD_LED_AMOUNTi++) { 
-      setPixel(i, 0x50, 00x50); +      setPixel(i-RAD_MAIN_LENGTH-20, 0, 0); 
-      for(int ​1<= EyeSizej++) { +      setPixel(i-RAD_MAIN_LENGTH-1SEC_COLOR_REDSEC_COLOR_GREENSEC_COLOR_BLUE); 
-        setPixel(i+j,​ red, green, blue); +      setPixel(i-1MAIN_COLOR_REDMAIN_COLOR_GREENMAIN_COLOR_BLUE); 
-      } +      setPixel(i, ​SEC_COLOR_REDSEC_COLOR_GREENSEC_COLOR_BLUE);
-      setPixel(i+EyeSize+10x50, 0, 0x50); +
-  ​ +
-      setPixel(NUM_LEDS-i, 0x5000x50); +
-      ​for(int j = 1; j <= EyeSize; j++) { +
-        ​setPixel(NUM_LEDS-i-jredgreenblue); +
-      } +
-      setPixel(NUM_LEDS-i-EyeSize-10x5000x50); +
-    ​+
       showStrip();​       showStrip();​
-      ​delay(SpeedDelay);+    ​delay(PIXEL_SPEED);
     }     }
-    ​delay(ReturnDelay);​ +    for (int i=RAD_LED_AMOUNT; i>=0; i--) { 
-  } +      setPixel(i-RAD_MAIN_LENGTH-2SEC_COLOR_REDSEC_COLOR_GREENSEC_COLOR_BLUE); 
-   +      setPixel(i-RAD_MAIN_LENGTH-1MAIN_COLOR_REDMAIN_COLOR_GREENMAIN_COLOR_BLUE); 
-  void OutsideToCenter1(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { +      setPixel(i-1, SEC_COLOR_REDSEC_COLOR_GREENSEC_COLOR_BLUE); 
-    ​for(int i = 0; i<=((NUM_LEDS-EyeSize)/​2); i++) { +      setPixel(i, ​0, 0, 0);
-      setAll(0,​0,​0);​ +
-    +
-      setPixel(i, ​0x5000x50); +
-      ​for(int j = 1; j <= EyeSize; j++) { +
-        ​setPixel(i+jredgreenblue); +
-      } +
-      setPixel(i+EyeSize+1, 0x5000x50); +
-    +
-      setPixel(NUM_LEDS-i, 0x50, 0, 0x50); +
-      for(int j = 1; j <= EyeSize; j++) { +
-        setPixel(NUM_LEDS-i-j,​ red, green, blue); +
-      } +
-      setPixel(NUM_LEDS-i-EyeSize-1,​ 0x50, 0, 0x50); +
-   +
       showStrip();​       showStrip();​
-      ​delay(SpeedDelay);+    ​delay(PIXEL_SPEED);
     }     }
-    delay(ReturnDelay);​ 
   }   }
   ​   ​
-  void Interrupt(byte redbyte greenbyte blue, int Count, int SpeedDelay) { +  void MaxFun(int MAIN_COLOR_REDint MAIN_COLOR_GREENint MAIN_COLOR_BLUE, int SEC_COLOR_RED, int SEC_COLOR_GREEN,​ int SEC_COLOR_BLUE) { 
-    ​setAll(0,0,0); +    ​int RAD_LED_AMOUNT = random(12,LED_AMOUNT+1);​ 
-    for (int i=0; i<Count; i++) { +    int RAD_MAIN_LENGTH = random(2,10);  
-      setPixel(random(NUM_LEDS),red,green,blue);+    for (int i=0; i<=RAD_LED_AMOUNT; i++) { 
 +      setPixel(i-1, MAIN_COLOR_RED,​ MAIN_COLOR_GREEN,​ MAIN_COLOR_BLUE)
 +      setPixel(iSEC_COLOR_REDSEC_COLOR_GREENSEC_COLOR_BLUE);
       showStrip();​       showStrip();​
-      ​delay(SpeedDelay);+    ​delay(PIXEL_SPEED);
     }     }
-    ​delay(SpeedDelay);​ +    for (int i=RAD_LED_AMOUNT; i>=0; i--) { 
-  } +      setPixel(i-1, SEC_COLOR_REDSEC_COLOR_GREENSEC_COLOR_BLUE); 
-   +      setPixel(i, ​000);
-  void Party(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){ +
-    ​for(int i =((NUM_LEDS-EyeSize)/​2); i>=0; i--) { +
-  ​ +
-      ​for(int j = 1; j <= EyeSize; j++) { +
-        ​setPixel(i+j, red, green, blue); +
-      } +
-      setPixel(i+EyeSize+1, redbluegreen); +
-  ​ +
-      ​for(int j = 1; j <= EyeSize; j++) { +
-        ​setPixel(NUM_LEDS-i-jredgreenblue); +
-      } +
-      setPixel(NUM_LEDS-i-EyeSize-1,​ red, blue, green); +
-    ​+
       showStrip();​       showStrip();​
-      ​delay(SpeedDelay);+    ​delay(PIXEL_SPEED);
     }     }
-    delay(ReturnDelay);​ 
   }   }
   ​   ​
-  void showStrip() { +  void setPixel(int Pixel, int MAIN_COLOR_RED,​ int MAIN_COLOR_GREEN,​ int MAIN_COLOR_BLUE) { 
-    strip.show();+     ​strip.setPixelColor(Pixel, strip.Color(MAIN_COLOR_RED,​ MAIN_COLOR_GREEN,​ MAIN_COLOR_BLUE));
   }   }
   ​   ​
-  void setPixel(int Pixel, byte red, byte green, byte blue) { +  void showStrip() { 
-    strip.setPixelColor(Pixel,​ strip.Color(red,​ green, blue)); +     ​strip.show();
-  } +
-   +
-  void setAll(byte red, byte green, byte blue) { +
-    for(int i = 0; i < NUM_LEDS; i++ ) { +
-      setPixel(i, red, green, blue); +
-    } +
-    showStrip();+
   }   }
  
projects/neopixel-backpack.1575383963.txt.gz · Last modified: 2019/12/03 14:39 by seven