This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
projects:neopixel-backpack [2019-12-03 14:37] – seven | projects:neopixel-backpack [2019-12-05 14:27] (current) – [Current Arduino Code] seven | ||
---|---|---|---|
Line 26: | Line 26: | ||
#include < | #include < | ||
#define PIN 15 | #define PIN 15 | ||
- | # | + | # |
- | 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(); | + | strip.show(); |
} | } | ||
| | ||
void loop() { | void loop() { | ||
- | | + | |
- | Party(0x50, 0x50, 0, 2, 100, 100); | + | for (int a=0; a<2; a++) { |
- | Interrupt(0x50, 0, 0x50, 25, 100); | + | |
- | Main1(0x50, 0x50, 0, 4, 60, 0); | + | |
- | Party(0x50, 0, 0x50, 2, 100, 100); | + | |
- | Interrupt(0x50, | + | |
- | } | + | |
- | + | ||
- | void Main(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){ | + | |
- | CenterToOutside(red, | + | |
- | OutsideToCenter(red, | + | |
- | CenterToOutside(red, | + | |
- | OutsideToCenter(red, | + | |
- | } | + | |
- | + | ||
- | void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { | + | |
- | for(int | + | |
- | setAll(0, | + | |
- | + | ||
- | setPixel(i, 0x50, 0x50, 0); | + | |
- | for(int j = 1; j <= EyeSize; j++) { | + | |
- | setPixel(i+j, | + | |
- | | + | |
- | setPixel(i+EyeSize+1, | + | |
- | + | ||
- | 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, | + | |
- | + | ||
- | showStrip(); | + | |
- | delay(SpeedDelay); | + | |
} | } | ||
- | | + | |
- | } | + | for (int a=0; a< |
- | + | | |
- | void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { | + | |
- | for(int | + | |
- | | + | |
- | + | ||
- | setPixel(i, 0x50, 0x50, 0); | + | |
- | for(int j = 1; j <= EyeSize; j++) { | + | |
- | setPixel(i+j, | + | |
- | } | + | |
- | setPixel(i+EyeSize+1, | + | |
- | + | ||
- | setPixel(NUM_LEDS-i, | + | |
- | for(int j = 1; j <= EyeSize; j++) { | + | |
- | setPixel(NUM_LEDS-i-j, | + | |
- | } | + | |
- | setPixel(NUM_LEDS-i-EyeSize-1, | + | |
- | + | ||
- | showStrip(); | + | |
- | delay(SpeedDelay); | + | |
} | } | ||
- | | + | |
} | } | ||
| | ||
- | void Main1(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){ | + | void TestFun(int MAIN_COLOR_RED, int MAIN_COLOR_GREEN, int MAIN_COLOR_BLUE, int SEC_COLOR_RED, int SEC_COLOR_GREEN, |
- | CenterToOutside1(red, | + | |
- | OutsideToCenter1(red, | + | |
- | CenterToOutside1(red, | + | |
- | OutsideToCenter1(red, | + | |
} | } | ||
| | ||
- | void CenterToOutside1(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { | + | void SnakeFun(int MAIN_COLOR_RED, int MAIN_COLOR_GREEN, int MAIN_COLOR_BLUE, int SEC_COLOR_RED, int SEC_COLOR_GREEN, int SEC_COLOR_BLUE) { |
- | | + | int RAD_LED_AMOUNT |
- | setAll(0,0,0); | + | |
- | | + | for (int i=0; i<=RAD_LED_AMOUNT; i++) { |
- | setPixel(i, 0x50, 0, 0x50); | + | setPixel(i-RAD_MAIN_LENGTH-2, 0, 0, 0); |
- | for(int | + | setPixel(i-RAD_MAIN_LENGTH-1, SEC_COLOR_RED, SEC_COLOR_GREEN, SEC_COLOR_BLUE); |
- | setPixel(i+j, | + | setPixel(i-1, MAIN_COLOR_RED, MAIN_COLOR_GREEN, MAIN_COLOR_BLUE); |
- | } | + | setPixel(i, |
- | setPixel(i+EyeSize+1, 0x50, 0, 0x50); | + | |
- | | + | |
- | setPixel(NUM_LEDS-i, 0x50, 0, 0x50); | + | |
- | | + | |
- | | + | |
- | } | + | |
- | setPixel(NUM_LEDS-i-EyeSize-1, 0x50, 0, 0x50); | + | |
- | | + | |
showStrip(); | showStrip(); | ||
- | | + | |
} | } | ||
- | | + | for (int i=RAD_LED_AMOUNT; i>=0; i--) { |
- | } | + | setPixel(i-RAD_MAIN_LENGTH-2, SEC_COLOR_RED, SEC_COLOR_GREEN, SEC_COLOR_BLUE); |
- | + | setPixel(i-RAD_MAIN_LENGTH-1, MAIN_COLOR_RED, MAIN_COLOR_GREEN, MAIN_COLOR_BLUE); | |
- | void OutsideToCenter1(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) { | + | setPixel(i-1, SEC_COLOR_RED, SEC_COLOR_GREEN, SEC_COLOR_BLUE); |
- | | + | setPixel(i, |
- | setAll(0, | + | |
- | + | ||
- | setPixel(i, | + | |
- | | + | |
- | | + | |
- | } | + | |
- | setPixel(i+EyeSize+1, 0x50, 0, 0x50); | + | |
- | + | ||
- | setPixel(NUM_LEDS-i, 0x50, 0, 0x50); | + | |
- | for(int j = 1; j <= EyeSize; j++) { | + | |
- | setPixel(NUM_LEDS-i-j, | + | |
- | } | + | |
- | setPixel(NUM_LEDS-i-EyeSize-1, | + | |
- | + | ||
showStrip(); | showStrip(); | ||
- | | + | |
} | } | ||
- | delay(ReturnDelay); | ||
} | } | ||
| | ||
- | void Interrupt(byte red, byte green, byte blue, int Count, int SpeedDelay) { | + | void MaxFun(int MAIN_COLOR_RED, int MAIN_COLOR_GREEN, int MAIN_COLOR_BLUE, int SEC_COLOR_RED, int SEC_COLOR_GREEN, |
- | | + | |
- | 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, | ||
+ | setPixel(i, SEC_COLOR_RED, SEC_COLOR_GREEN, SEC_COLOR_BLUE); | ||
showStrip(); | showStrip(); | ||
- | | + | |
} | } | ||
- | | + | for (int i=RAD_LED_AMOUNT; i>=0; i--) { |
- | } | + | setPixel(i-1, SEC_COLOR_RED, SEC_COLOR_GREEN, SEC_COLOR_BLUE); |
- | + | setPixel(i, | |
- | void Party(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){ | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
- | setPixel(i+EyeSize+1, red, blue, green); | + | |
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
- | setPixel(NUM_LEDS-i-EyeSize-1, | + | |
- | | + | |
showStrip(); | showStrip(); | ||
- | | + | |
} | } | ||
- | delay(ReturnDelay); | ||
} | } | ||
| | ||
- | void showStrip() { | + | void setPixel(int Pixel, int MAIN_COLOR_RED, |
- | strip.show(); | + | |
} | } | ||
| | ||
- | void setPixel(int Pixel, byte red, byte green, byte blue) { | + | void showStrip() { |
- | strip.setPixelColor(Pixel, | + | |
- | } | + | |
- | + | ||
- | void setAll(byte red, byte green, byte blue) { | + | |
- | for(int i = 0; i < NUM_LEDS; i++ ) { | + | |
- | setPixel(i, red, green, blue); | + | |
- | } | + | |
- | showStrip(); | + | |
} | } | ||