Hardware files
This is all public domain, so enjoy!- Schematic for LED plate in PNG format
- Schematic and layout for LED plate in EagleCAD format
The LEDs originally used are CREE Xlamp 7090 but any 1+ Watt LEDs work OK. The balancing resistors are about 1 ohm, but can be adjusted. Use 2 sets of 6 LEDs for full tri-color (more versatile). Or 3 sets of 6 LEDs for green/blue only (more effective).
The arduino (or compatible) is hooked up to the LEDs via logic-level N-channel FETs. The diagram shows 2 groups of 3 colors but can be easily changed for 2 colors. If red LEDs are used, a 0.5 ohm, 5W led should be placed in series with the wire to the LED plate.
// Bedazzler! A good multiple LED PWM project, by Limor Fried // Public domain 2009 #include <util/delay.h> int value; int redpin1 = 5, redpin2 = 6; int greenpin1 = 3, greenpin2 = 11; int bluepin1 = 9, bluepin2 = 10; int ledmax; #define GLITTER 0 #define SWIRL 1 #define DAZZLE 2 volatile int mode = DAZZLE; // we use a button on pin 2 (interrupt pin) to detect mode changes void modechange(void) { // debounce it if (digitalRead(2) == LOW) { _delay_ms(10); if (digitalRead(2) != LOW) return; Serial.println("button"); mode++; if (mode > 2) mode = 0; Serial.print("new mode! "); Serial.println(mode, DEC); } } void setup() { pinMode(2, INPUT); digitalWrite(2, HIGH); // pullup on mode button attachInterrupt(0, modechange, CHANGE); Serial.begin(9600); randomSeed(analogRead(0)); // nothing for setup analogWrite(redpin1, 0); analogWrite(redpin2, 0); analogWrite(greenpin1, 0); analogWrite(greenpin2, 0); analogWrite(bluepin1, 0); analogWrite(bluepin2, 0); ledmax = 250; // change this value to adjust the maximum brightness } void loop() { switch(mode) { case SWIRL: //Serial.println("swirl"); ckswirl(ledmax, 10); break; case GLITTER: //Serial.println("glimmer"); glimmertest(ledmax, ledmax/10, 30); break; case DAZZLE: //Serial.println("dazzle"); bedazzle(ledmax, 10, 7, 11); break; } } void bedazzle(int ledmax, int pulselensec, int freqmin, int freqmax) { long pulses; analogWrite(redpin1, 0); analogWrite(redpin2, 0); analogWrite(greenpin1, 0); analogWrite(greenpin2, 0); analogWrite(bluepin1, 0); analogWrite(bluepin2, 0); // note we dont use red LEDs in this int freq = random(freqmin, freqmax+1); int pulsedelay = 1000/freq; pulsedelay /= 2; pulses = pulselensec; pulses *= 1000; pulses /= 2*pulsedelay; /* Serial.print("pulsing at "); Serial.print(freq, DEC); Serial.print(" Hz ("); Serial.print(pulsedelay, DEC); Serial.println(" ms on/off)"); Serial.print(pulses); Serial.println(" pulses"); */ while (pulses--) { analogWrite(greenpin1, ledmax); analogWrite(greenpin2, ledmax); analogWrite(bluepin1, ledmax); analogWrite(bluepin2, ledmax); _delay_ms(pulsedelay); analogWrite(greenpin1, 0); analogWrite(greenpin2, 0); analogWrite(bluepin1, 0); analogWrite(bluepin2, 0); _delay_ms(pulsedelay); if (mode != DAZZLE) return; } } void ckswirl(int ledmax, uint8_t z) { int r, g, b; // fade from red to orange to yellow to green for (g=0; g<255; g++) { // turn red down analogWrite(redpin1, ledmax-g); analogWrite(redpin2, ledmax-g); analogWrite(greenpin1, g); // sets the value (range from 0 to 255) analogWrite(greenpin2, g); // sets the value (range from 0 to 255) delay(z); if (mode != SWIRL) return; } // fade from green to blue for (b=0; b<255; b++) { // turn red down analogWrite(bluepin1, b); analogWrite(bluepin2, b); analogWrite(greenpin1, ledmax-b); // sets the value (range from 0 to 255) analogWrite(greenpin2, ledmax-b); // sets the value (range from 0 to 255) delay(z); if (mode != SWIRL) return; } // from blue to red for (r=0; r<255; r++) { // turn red down analogWrite(redpin1, r); analogWrite(redpin2, r); analogWrite(bluepin1, ledmax-r); // sets the value (range from 0 to 255) analogWrite(bluepin2, ledmax-r); // sets the value (range from 0 to 255) delay(z); if (mode != SWIRL) return; } } void glimmertest(int maxvalue, int incr, int z) { for(value = 0 ; value <= maxvalue; value+=incr) { analogWrite(greenpin1, value); // sets the value (range from 0 to 255) analogWrite(greenpin2, maxvalue-value); // sets the value (range from 0 to 255) analogWrite(bluepin1, value); analogWrite(bluepin2, maxvalue-value); // sets the value (range from 0 to 255) analogWrite(redpin1, value); analogWrite(redpin2, maxvalue-value); // sets the value (range from 0 to 255) delay(z); // waits for 30 milli seconds to see the dimming effect if (mode != GLITTER) return; } for(value = maxvalue; value >=0; value-=incr) // fade out (from max to min) { analogWrite(greenpin1, value); analogWrite(greenpin2 , maxvalue-value); // sets the value (range from 0 to 255) analogWrite(bluepin1, value); analogWrite(bluepin2, maxvalue-value); // sets the value (range from 0 to 255) analogWrite(redpin1, value); analogWrite(redpin2, maxvalue-value); // sets the value (range from 0 to 255) delay(z); if (mode != GLITTER) return; } }
Text editor powered by tinymce.