// This program is written using the following components // PIR (Passive Infrared) Sensor connected to Analog Pin 4 to detect motion. // // Radio Shack Tricolor LED Strip, Model: 2760339, Catalog#2760339 // uses TM1803 chip. 10 banks of 3 LEDs each // // Arduino Uno // // For the following instructable: // http:// #include #define DATA_1 (PORTC |= 0X01) // DATA 1 // for UNO #define DATA_0 (PORTC &= 0XFE) // DATA 0 // for UNO #define STRIP_PINOUT (DDRC=0xFF) // for UNO //The color format of the strip is RBG, here are some //common colors #define RED 0xff0000 #define BLUE 0x00ff00 #define GREEN 0x0000ff #define ORANGE 0Xfa0ae2 #define YELLOW 0xff00ff #define INDIGO 0x4b8200 #define PURPLE 0xffff00 #define PINK 0xffcbc0 #define CYAN 0x00ffff #define WHITE 0xffffff #define STRIP_SIZE 10 //This structure stores the color of each segment of the strip unsigned long colors[STRIP_SIZE+1]; //This structure stores the illumination/intensity of each segment. // 0.0 = OFF 1.0 = Fully Illuminated float illum[STRIP_SIZE+1]; // *********************************************************************************************************** // setup - runs at arduino power-up void setup() { (DDRC=0xFF); // for Arduino UNO reset_strip(); } /****************************************************************/ void C_rainbow() { colors[0] = RED; colors[1] = RED; colors[2] = ORANGE; colors[3] = YELLOW; colors[4] = GREEN; colors[5] = GREEN; colors[6] = BLUE; colors[7] = INDIGO; colors[8] = PURPLE; colors[9] = PURPLE; } /****************************************************************/ void C_green_bow() { colors[0] = YELLOW; colors[1] = YELLOW; colors[2] = 0xccff33; colors[3] = 0xccff33; colors[4] = GREEN; colors[5] = GREEN; colors[6] = 0Xccff33; colors[7] = 0xccff33; colors[8] = YELLOW; colors[9] = YELLOW; } /****************************************************************/ void C_blue_bow() { colors[0] = INDIGO; colors[1] = INDIGO; colors[2] = CYAN; colors[3] = CYAN; colors[4] = BLUE; colors[5] = BLUE; colors[6] = CYAN; colors[7] = CYAN; colors[8] = INDIGO; colors[9] = INDIGO; } /****************************************************************/ void C_red_to_purple() { colors[9] = RED; colors[8] = RED; colors[7] = RED; colors[6] = INDIGO; colors[5] = INDIGO; colors[4] = INDIGO; colors[3] = INDIGO; colors[2] = PURPLE; colors[1] = PURPLE; colors[0] = PURPLE; } /****************************************************************/ void C_blue_to_purple() { colors[0] = BLUE; colors[1] = BLUE; colors[2] = BLUE; colors[3] = INDIGO; colors[4] = INDIGO; colors[5] = INDIGO; colors[6] = INDIGO; colors[7] = PURPLE; colors[8] = PURPLE; colors[9] = PURPLE; } /****************************************************************/ void C_alt(unsigned long c, unsigned long d) { int i = 0; for(i=0;i=0;i--) //Loop over intensities from 1.0 to 0.0 { for(j=0;j i) {illum[k] = 0;} } light_strip(); delay(10); } } } /****************************************************************/ void M_slide_left() { int i,j,k; //Initialize the intensities for(j=0;j i) {illum[STRIP_SIZE-k] = 0;} } light_strip(); delay(10); } } } /****************************************************************/ /****************************************************************/ /****************************************************************/ void block_until_motion() { while (true) { delay(1000); if (analogRead(4) > 0) //Motion is detected, wait 100ms { delay(100); // and make sure it isn't a false alarm if (analogRead(4)) { return; } } } } /****************************************************************/ // This is the main loop entered after setup void loop() { // Routines available /*********************/ // Color // C_rainbow - rainbow // C_solid(c) - all colors are set to c // C_alt(c,d) - alternating segments of c and d colors // C_red_to_putple - from left to right, RED, INDIGO, PURPLE // C_blue_to_purple - from left to right, BLUE, INDIGO, PURPLE // C_green_bow - yellow to green to yellow // C_blue_bow - cyan to indigo to cyan // Movement // M_slide_left - light up from right to the left // M_slide_right - light up from the left to the right // M_center_out - light up from the center outwards // M_fadein - fade in the entire strip // M_fadeout - fade out the entire strip // M_fadein_alt - fade in odd segments, then fade in the remaining // M_fade_center_in - fade out, but from the outside in int i; //Wait until motion is detected block_until_motion(); //Always start with this pattern C_rainbow(); M_center_out(); delay(10000); M_fadeout(); //Run 20 more patterns, and then stop and wait i = 20; while (i-- > 0) { switch ( i % 13) //replace with random for a randomized selection { /***************************************************/ case 0: switch ( random(8) ) { case 0: C_solid(RED); break; case 1: C_solid(PINK); break; case 2: C_solid(BLUE); break; case 3: C_solid(PURPLE); break; case 4: C_solid(ORANGE); break; case 5: C_solid(YELLOW); break; case 6: C_solid(INDIGO); break; case 7: C_solid(CYAN); break; } M_fadein(); delay(8000); M_fadeout(); break; /***************************************************/ case 1: switch ( random(8) ) { case 0: C_solid(RED); break; case 1: C_solid(PINK); break; case 2: C_solid(BLUE); break; case 3: C_solid(PURPLE); break; case 4: C_solid(ORANGE); break; case 5: C_solid(YELLOW); break; case 6: C_solid(INDIGO); break; case 7: C_solid(CYAN); break; } switch (random(3)) { case 0: M_slide_left(); break; case 1: M_slide_right(); break; case 2: M_center_out(); break; } delay(8000); M_fadeout(); break; /***************************************************/ case 2: C_rainbow(); M_slide_left(); delay(8000); M_fadeout(); break; /***************************************************/ case 3: C_blue_to_purple(); M_center_out(); delay(8000); M_fadeout(); break; /***************************************************/ case 4: C_red_to_purple(); M_center_out(); delay(8000); M_fadeout(); break; /***************************************************/ case 5: C_alt(BLUE,RED); M_fadein_alt(); delay(8000); M_fadeout(); break; /***************************************************/ case 6: C_alt(GREEN,BLUE); M_fadein_alt(); delay(8000); M_fadeout(); break; /***************************************************/ case 7: C_alt(ORANGE,BLUE); M_fadein_alt(); delay(8000); M_fadeout(); break; /***************************************************/ case 8: C_alt(GREEN,RED); M_fadein_alt(); delay(8000); M_fadeout(); break; /***************************************************/ case 9: C_alt(INDIGO,PURPLE); M_fadein_alt(); delay(8000); M_fadeout(); break; /***************************************************/ case 10: C_green_bow(); M_center_out(); delay(8000); M_fade_center_in(); break; /***************************************************/ case 11: C_alt(RED,PURPLE); M_center_out(); delay(8000); M_fadeout(); break; /***************************************************/ case 12: C_blue_bow(); M_center_out(); delay(8000); M_fade_center_in(); break; /***************************************************/ } } //Wait for motion again. M_fadeout(); reset_strip(); block_until_motion(); return; //Restart the program } /****************************************************************/ // This routine combines the colors and intensities to determine what // to send to the strip void light_strip() { int i=0; uint32_t temp_data[STRIP_SIZE]; //The calculated values to the strip unsigned char calc; for(i=0;i> 16)); temp_data[i] = ((uint32_t)calc) << 16; calc = (unsigned char)(illum[i] * float((colors[i] & 0x0000ff00) >> 8)); temp_data[i] += ((uint32_t)calc) << 8; calc = (unsigned char)(illum[i] * float((colors[i] & 0x000000ff))); temp_data[i] += (uint32_t)calc; } noInterrupts(); for (i=0;i>=1; } } /*****************************************************************/ void reset_strip() { DATA_0; delayMicroseconds(20); }