├── DMX_LED_Strips.ino ├── README.md └── output_test.ino /DMX_LED_Strips.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | DMX_LED_Strips 4 | Copyright (c) 2015, Matthew Tong 5 | https://github.com/mtongnz/DMX_LED_Strips 6 | http://www.instructables.com/id/DMX-LED-Strips/ 7 | 8 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public 9 | License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any 10 | later version. 11 | 12 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 13 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along with this program. 16 | If not, see http://www.gnu.org/licenses/ 17 | 18 | 19 | This sketch takes the DMX input and controls 5 RGB LED strips. 20 | 21 | Channel allocation is red, green, blue, strobe for each output (20 channels total). 22 | 23 | Strobe: 0-19 off 24 | 20 - 189 slow - fast 25 | 190 - 205 slow random 26 | 206 - 219 fast random 27 | 220 - 255 off 28 | 29 | Libraries Used: 30 | ShiftPWM by Elco Jacobs. www.elcojacobs.com 31 | DMXSerial by Mat Hertel. www.mathertel.de 32 | */ 33 | 34 | // ShiftPWM settings 35 | const int ShiftPWM_latchPin=8; 36 | const bool ShiftPWM_invertOutputs = false; 37 | const bool ShiftPWM_balanceLoad = true; 38 | 39 | #include 40 | #include 41 | 42 | // ShiftPWM settings 43 | unsigned char maxBrightness = 255; 44 | unsigned char pwmFrequency = 125; 45 | unsigned int numRegisters = 2; 46 | unsigned int numOutputs = numRegisters*8; 47 | 48 | // Status LED pin 49 | const int statusLEDPin = 5; 50 | 51 | // Output settings 52 | const int numRGBS = 5; 53 | const int dmxNumChan = numRGBS * 4; 54 | 55 | // DMX address. 56 | const int dmxStartAddr = 1; // unit 1 & 2 = 61, unit 3 & 4 = 81 57 | 58 | // Counter variables 59 | int strobeCount[numRGBS]; 60 | int randStrobeCount[numRGBS]; 61 | int timerCount; 62 | 63 | void setup(){ 64 | int x; 65 | 66 | // Random Seed 67 | randomSeed(analogRead(0)); 68 | 69 | // Setup DMX receiver 70 | DMXSerial.init(DMXReceiver); 71 | 72 | // Setup PWM output 73 | ShiftPWM.SetAmountOfRegisters(numRegisters); 74 | ShiftPWM.Start(pwmFrequency,maxBrightness); 75 | 76 | // set all channels to 0 default 77 | ShiftPWM.SetAll(0); 78 | 79 | // Setup status LED 80 | pinMode(statusLEDPin, OUTPUT); 81 | digitalWrite(statusLEDPin, 1); 82 | 83 | // Set counters to zero 84 | for (x = 0; x < numRGBS; x++) { 85 | strobeCount[x] = 0; 86 | randStrobeCount[x] = random(5, 200); 87 | } 88 | timerCount = 0; 89 | 90 | //set timer0 interrupt at 200Hz 91 | cli(); // disable interupts 92 | TCCR0A = 0; // set entire TCCR0A register to 0 93 | TCCR0B = 0; // same for TCCR0B 94 | TCNT0 = 0; // initialize counter value to 0 95 | OCR0A = 78; // set compare match register for 200hz increments 96 | TCCR0A |= (1 << WGM01); // turn on CTC mode 97 | TCCR0B |= (1 << CS02) | (1 << CS00); // Set CS02 and CS00 bits for 1024 prescaler 98 | TIMSK0 |= (1 << OCIE0A); // enable timer compare interrupt 99 | sei(); // enable interupts 100 | } 101 | 102 | // Timer0 interupt handler. Increments all the counters. 103 | ISR(TIMER0_COMPA_vect){ 104 | int x; 105 | 106 | for (x = 0; x < numRGBS; x++) 107 | strobeCount[x]++; 108 | 109 | timerCount++; 110 | } 111 | 112 | void loop() { 113 | int x, y, s; 114 | 115 | if (timerCount >= 100) { 116 | // Blink status LED if DMX receiving 117 | if (DMXSerial.noDataSince() < 1000) { 118 | digitalWrite(statusLEDPin, digitalRead(statusLEDPin) ^ 1); 119 | 120 | // Turn status LED red if no DMX received 121 | }else 122 | digitalWrite(statusLEDPin, 1); 123 | timerCount = 0; 124 | } 125 | 126 | // Turn off all outputs if we haven't received DMX in 10 seconds 127 | if (DMXSerial.noDataSince() > 10000) 128 | ShiftPWM.SetAll(0); 129 | else { 130 | // loop through each of the 'y' RGB leds 131 | for (y = 0; y < numRGBS; y++) { 132 | s = DMXSerial.read(dmxStartAddr + (y * 4)); 133 | 134 | // strobe mode 135 | if (s > 20 && s <= 220) { 136 | int t; 137 | 138 | // random strobe 139 | if (s > 190) { 140 | t = (40 - (s - 190)) * 10; 141 | s = randStrobeCount[y]; 142 | } 143 | 144 | 145 | // strobe on 146 | if (strobeCount[y] >= ( (192 - s) + 5) && strobeCount[y] < 500) { 147 | for (x = 0; x < 3; x++) 148 | ShiftPWM.SetOne((y*3) + x, DMXSerial.read(dmxStartAddr + (y * 4) + x + 1)); 149 | strobeCount[y] = 500; 150 | TCNT0 = 0; //clear timer 151 | } 152 | 153 | // strobe off 154 | if (strobeCount[y] >= 501 ) { 155 | for (x = 0; x < 3; x++) 156 | ShiftPWM.SetOne((y*3) + x, 0); 157 | strobeCount[y] = 0; 158 | 159 | randStrobeCount[y] = random(1, t); 160 | } 161 | 162 | 163 | // non strobe mode 164 | } else { 165 | strobeCount[y] = 0; 166 | 167 | // Get DMX values and set outputs 168 | for (x = 0; x < 3; x++) 169 | ShiftPWM.SetOne((y*3) + x, DMXSerial.read(dmxStartAddr + (y * 4) + x + 1)); 170 | } 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DMX_LED_Strips 2 | This sketch takes the DMX input and controls 5 RGB LED strips. 3 | 4 | Visit http://www.instructables.com/id/DMX-LED-Strips/ for instructions, schematics and video. 5 | 6 | If this project is helpful and you're feeling generous, why not shout me a beer: https://www.paypal.me/mtongnz 7 | 8 | Outputs are handled by shift registers as the atMega328 doesn't have enough PWM outputs. The number of channels can easily be increased by adding more shift registers. For my purposes, 4 boxes with 5 LED strips each was the most effiecient for cable management. 9 | 10 | Channel allocation for each output (20 channels total): 11 | ``` 12 | (1) red 13 | (2) green 14 | (3) blue 15 | (4) strobe 16 | ``` 17 | Strobe: 18 | ``` 19 | 0-19 off 20 | 20 - 189 slow - fast 21 | 190 - 205 slow random 22 | 206 - 219 fast random 23 | 220 - 255 off 24 | ``` 25 | Libraries Used: 26 | ``` 27 | - ShiftPWM by Elco Jacobs. www.elcojacobs.com 28 | - DMXSerial by Mat Hertel. www.mathertel.de 29 | ``` 30 | -------------------------------------------------------------------------------- /output_test.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | DMX_LED_Strips - Output Test 4 | Copyright (c) 2015, Matthew Tong 5 | https://github.com/mtongnz/DMX_LED_Strips 6 | http://www.instructables.com/id/DMX-LED-Strips/ 7 | 8 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public 9 | License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any 10 | later version. 11 | 12 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 13 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along with this program. 16 | If not, see http://www.gnu.org/licenses/ 17 | 18 | 19 | This sketch tests the RGB outputs. 20 | It sets all red for 1 second, blue 1 second, green 1 second. Finally white for 3 seconds and repeat. 21 | 22 | Library Used: 23 | ShiftPWM by Elco Jacobs. www.elcojacobs.com 24 | */ 25 | 26 | const int ShiftPWM_latchPin=8; 27 | const bool ShiftPWM_invertOutputs = false; 28 | const bool ShiftPWM_balanceLoad = true; 29 | 30 | #include 31 | 32 | unsigned char maxBrightness = 255; 33 | unsigned char pwmFrequency = 125; 34 | unsigned int numRegisters = 2; 35 | unsigned int numOutputs = numRegisters*8; 36 | 37 | const int numRGB = 5; 38 | 39 | void setup(){ 40 | int x; 41 | 42 | // Setup PWM output 43 | ShiftPWM.SetAmountOfRegisters(numRegisters); 44 | ShiftPWM.Start(pwmFrequency,maxBrightness); 45 | 46 | // set all channels to 0 default 47 | ShiftPWM.SetAll(0); 48 | } 49 | 50 | void loop() { 51 | int x, y, z; 52 | 53 | ShiftPWM.SetAll(0); 54 | 55 | 56 | //delay(1000); 57 | 58 | for (y = 0; y < 3; y++) { 59 | for (x = 0; x <= 255; x++) { 60 | //ShiftPWM.SetAll(x); 61 | for (z = 0; z < numRGB; z++) 62 | ShiftPWM.SetOne((z*3) + y, x); 63 | delay(3); 64 | } 65 | 66 | for (x = 255; x >= 0; x--) { 67 | //ShiftPWM.SetAll(x); 68 | for (z = 0; z < numRGB; z++) 69 | ShiftPWM.SetOne((z*3) + y, x); 70 | delay(2); 71 | } 72 | } 73 | return; 74 | 75 | 76 | for (x = 0; x < 3; x++) { 77 | for (y = 0; y< numRGB; y++) 78 | ShiftPWM.SetOne((y*3) +x, 255); 79 | delay(1000); 80 | ShiftPWM.SetAll(0); 81 | } 82 | 83 | ShiftPWM.SetAll(255); 84 | delay(3000); 85 | 86 | } 87 | --------------------------------------------------------------------------------