Last active
December 12, 2015 10:09
-
-
Save r1b4z01d/4757278 to your computer and use it in GitHub Desktop.
Arduino Powered IALEDPants 0.1b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /////////////////////////////////////////////////////////////////////////// | |
| ////////////////////////// IALEDPants 0.1b //////////////////////////// | |
| ////////////////////////// By Bryan Ribas //////////////////////////// | |
| ////////////////////////// 2/2/2013 //////////////////////////// | |
| ////////////////////////// HTTP://R1B4Z01D.COM //////////////////////////// | |
| /////////////////////////////////////////////////////////////////////////// | |
| /////////////////////////////////////////////////////////////////////////// | |
| /////////////////////////////////includes////////////////////////////////// | |
| /////////////////////////////////////////////////////////////////////////// | |
| #include "SPI.h" | |
| /////http://code.google.com/p/arduino/source/browse/trunk/libraries/SPI/SPI.h?r=1066 | |
| #include "WS2801.h" | |
| /////https://github.com/neophob/WS2801-Library/blob/master/WS2801.h | |
| /////////////////////////////////////////////////////////////////////////// | |
| ////////////////////////////////////PINS/////////////////////////////////// | |
| /////////////////////////////////////////////////////////////////////////// | |
| int dataPin = 3; // Data Pin for WS2801 Strip | |
| int clockPin = 2; // Clock Pin for WS2801 Strip | |
| const int buttonPin = 4; // The pin that the pushbutton is attached to | |
| /////////////////////////////////////////////////////////////////////////// | |
| ////////////////////////////////Veriables////////////////////////////////// | |
| /////////////////////////////////////////////////////////////////////////// | |
| int buttonPushCounter = 0; // Counter for the number of button presses | |
| WS2801 strip = WS2801(160, dataPin, clockPin); | |
| /////////////////////////////////////////////////////////////////////////// | |
| ///////////////////////////////////Setup/////////////////////////////////// | |
| /////////////////////////////////////////////////////////////////////////// | |
| void setup() { | |
| strip.begin(); | |
| Serial.begin(9600); // initialize serial communication for testing | |
| colorWipe(Color(255, 255, 255), 1); ///White Swipe | |
| pinMode(buttonPin, INPUT); | |
| } | |
| /////////////////////////////////////////////////////////////////////////// | |
| ///////////////////////////////Main Loop/////////////////////////////////// | |
| /////////////////////////////////////////////////////////////////////////// | |
| void loop() { | |
| Serial.println(buttonPushCounter); | |
| if(buttonPushCounter >= 13 ){ | |
| buttonPushCounter =0; | |
| } | |
| if(buttonPushCounter == 0){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| } | |
| } | |
| if(buttonPushCounter == 1){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RandomRGBRandomPixel(1); | |
| } | |
| } | |
| if(buttonPushCounter == 2){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| rainbow(1); | |
| } | |
| } | |
| if(buttonPushCounter == 3){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RGBYOPBounce(1); | |
| } | |
| } | |
| if(buttonPushCounter == 4){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RBGRoll(1); | |
| } | |
| } | |
| if(buttonPushCounter == 5){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RGBBounce(1); | |
| } | |
| } | |
| if(buttonPushCounter == 6){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RandomColors(1); | |
| } | |
| } | |
| if(buttonPushCounter == 7){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RBBounce(1); | |
| } | |
| } | |
| if(buttonPushCounter == 8){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RBColumnBounce(1); | |
| } | |
| } | |
| if(buttonPushCounter == 9){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RandomColumnBounce(1); | |
| } | |
| } | |
| if(buttonPushCounter == 10){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RGBYOPBounce(1); | |
| } | |
| } | |
| if(buttonPushCounter == 11){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RandomRGBYOPRandomPixel(1); | |
| } | |
| } | |
| if(buttonPushCounter == 12){ | |
| while (digitalRead(buttonPin) == LOW) { | |
| RandomColorsRandomPixel(1); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void rainbow(uint8_t wait) { | |
| int i, j; | |
| for (j=0; j < 256; j++) { // 3 cycles of all 256 colors in the wheel | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=0; i < strip.numPixels(); i++) { | |
| strip.setPixelColor(i, Wheel( (i + j) % 255)); | |
| } | |
| strip.show(); // write all the pixels out | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void colorWipe(uint32_t c, uint8_t wait) { | |
| int i; | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i, c); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RandomRGBRandomPixel( uint8_t wait) { | |
| int i; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(random(0,160), 200,0,0); | |
| strip.setPixelColor(random(0,160), 0,0,200); | |
| strip.setPixelColor(random(0,160), 0,200,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RBGRoll(uint8_t wait) { | |
| int i=0; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i, 200,0,0); | |
| strip.setPixelColor(i++, 0,0,200); | |
| strip.setPixelColor(i, 0,200,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=160; i >=1; i--) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i, 0,200,0); | |
| strip.setPixelColor(i--, 0,0,200); | |
| strip.setPixelColor(i, 200,0,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RGBBounce(uint8_t wait) { | |
| int i=0; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i++, 200,0,0); | |
| strip.setPixelColor(i++, 0,0,200); | |
| strip.setPixelColor(i, 0,200,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=160; i >=1; i--) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i--, 0,200,0); | |
| strip.setPixelColor(i--, 0,0,200); | |
| strip.setPixelColor(i, 200,0,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RBBounce(uint8_t wait) { | |
| int i=0; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i++, 200,0,0); | |
| strip.setPixelColor(i, 0,0,200); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=160; i >=1; i--) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i--, 0,0,200); | |
| strip.setPixelColor(i, 200,0,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RBColumnBounce(uint8_t wait) { | |
| int i=0; | |
| for (i=0; i < 32; i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i++, 200,0,0); | |
| strip.setPixelColor(i, 0,0,200); | |
| strip.setPixelColor(i+32, 200,0,0); | |
| strip.setPixelColor(i+33, 0,0,200); | |
| strip.setPixelColor(i+64, 200,0,0); | |
| strip.setPixelColor(i+65, 0,0,200); | |
| strip.setPixelColor(i+96, 200,0,0); | |
| strip.setPixelColor(i+97, 0,0,200); | |
| strip.setPixelColor(i+128, 200,0,0); | |
| strip.setPixelColor(i+129, 0,0,200); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=32; i >=0 ; i--) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i--, 0,0,200); | |
| strip.setPixelColor(i, 200,0,0); | |
| strip.setPixelColor(i+32, 0,0,200); | |
| strip.setPixelColor(i+33, 200,0,0); | |
| strip.setPixelColor(i+64, 0,0,200); | |
| strip.setPixelColor(i+65, 200,0,0); | |
| strip.setPixelColor(i+96, 0,0,200); | |
| strip.setPixelColor(i+97, 200,0,0); | |
| strip.setPixelColor(i+128, 0,0,200); | |
| strip.setPixelColor(i+129, 200,0,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RandomColumnBounce( uint8_t wait) { | |
| int i=0; | |
| for (i=0; i < 32; i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i++, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+32, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+33, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+64, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+65, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+96, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+97, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+128, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+129, random(0,200),random(0,200),random(0,200)); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=32; i >=0 ; i--) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i--, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+32, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+33, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+64, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+65, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+96, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+97, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+128, random(0,200),random(0,200),random(0,200)); | |
| strip.setPixelColor(i+129, random(0,200),random(0,200),random(0,200)); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RGBYOPBounce( uint8_t wait) { | |
| int i=0; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i++, 200,0,0); | |
| strip.setPixelColor(i++, 0,0,200); | |
| strip.setPixelColor(i++, 0,200,0); | |
| strip.setPixelColor(i++, 200,200,0); | |
| strip.setPixelColor(i++, 200,0,200); | |
| strip.setPixelColor(i, 0,200,200); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| if (digitalRead(buttonPin) == LOW){ | |
| for (i=160; i >=1; i--) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i--, 0,200,200); | |
| strip.setPixelColor(i--, 200,0,200); | |
| strip.setPixelColor(i--, 200,200,0); | |
| strip.setPixelColor(i, 0,200,0); | |
| strip.setPixelColor(i--, 0,0,200); | |
| strip.setPixelColor(i--, 200,0,0); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RandomRGBYOPRandomPixel(uint8_t wait) { | |
| int i; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(random(0,160), 200,0,0); | |
| strip.setPixelColor(random(0,160), 0,0,200); | |
| strip.setPixelColor(random(0,160), 0,200,0); | |
| strip.setPixelColor(random(0,160), 200,200,0); | |
| strip.setPixelColor(random(0,160), 200,0,200); | |
| strip.setPixelColor(random(0,160), 0,200,200); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| void RandomColors(uint8_t wait) { | |
| int i; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter++; | |
| break; | |
| } | |
| strip.setPixelColor(i, random(0,200),random(0,200),random(0,200)); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| ///////////////////////////////////////////////////////////////////////// | |
| void RandomColorsRandomPixel(uint8_t wait) { | |
| int i; | |
| for (i=0; i < strip.numPixels(); i++) { | |
| if (digitalRead(buttonPin) == HIGH){ | |
| buttonPushCounter =0; | |
| break; | |
| } | |
| strip.setPixelColor(random(0,160), random(0,200),random(0,200),random(0,200)); | |
| strip.show(); | |
| delay(wait); | |
| } | |
| } | |
| // Create a 24 bit color value from R,G,B | |
| uint32_t Color(byte r, byte g, byte b) | |
| { | |
| uint32_t c; | |
| c = r; | |
| c <<= 8; | |
| c |= g; | |
| c <<= 8; | |
| c |= b; | |
| return c; | |
| } | |
| //Input a value 0 to 255 to get a color value. | |
| //The colours are a transition r - g -b - back to r | |
| uint32_t Wheel(byte WheelPos) | |
| { | |
| if (WheelPos < 85) { | |
| return Color(WheelPos * 3, 255 - WheelPos * 3, 0); | |
| } | |
| else if (WheelPos < 170) { | |
| WheelPos -= 85; | |
| return Color(255 - WheelPos * 3, 0, WheelPos * 3); | |
| } | |
| else { | |
| WheelPos -= 170; | |
| return Color(0, WheelPos * 3, 255 - WheelPos * 3); | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added some notes in this revision.