Components and supplies
Arduino Nano R3
Project description
Code
Base DMX Arduino code
arduino
1/* 2 This sketch acts as basic DMX lights controller, 5 channels, RGB and STROBO, by Marco Zonca, 2/2021 3 Arduino Nano as 5V MPU, C25B TTL/RS485 rtx board, 4 x 10k slider potentiometers, 4 one button, 10k potentiometer, RGB led, 3 x LED and a few resistors; 5 6 Channels: 1=brightness 7 2=Red 8 3=Green 9 4=Blue 10 5=STROBO (0-7 none, 8-255 rate) 11 */ 12 13#include <DmxSimple.h> 14 15#define IS_DEBUG false 16 17byte MaxChannel = 5; 18bool isSTROBO = false; 19bool ledStroboOn = false; 20 21const byte TTL485Pin = 3; 22const byte TrimStroboPin = 15; 23const byte TrimRedPin = 16; 24const byte TrimGreenPin = 17; 25const byte TrimBluePin = 18; 26const byte TrimBrightnessPin = 19; 27const byte LedRPin = 11; 28const byte LedGPin = 10; 29const byte LedBPin = 9; 30const byte ButtonRSPin = 7; 31 32const unsigned long refreshRate = 200; // millis, lower this for a quicker response at changes 33const unsigned long ledStroboRate = 250; // millis, change this for a different led blinking rate 34const byte antiBouncing = 1; // units, change this to 0 for a better granularity of changes 35 // but more rtx traffic, or increase to 2 if you experience jumping values 36const byte chStrobo=5; 37const byte chBrightness=1; 38const byte chRed=2; 39const byte chGreen=3; 40const byte chBlue=4; 41 42 43int ValStrobo=0; 44int ValRed=0; 45int ValGreen=0; 46int ValBlue=0; 47int ValBrightness=0; 48int prevValStrobo=0; 49int prevValRed=0; 50int prevValGreen=0; 51int prevValBlue=0; 52int prevValBrightness=0; 53 54unsigned long lastRefresh = 0; // millis 55unsigned long lastStrobo = 0; // millis 56 57void setup() { 58 if (IS_DEBUG) Serial.begin(38400); 59 DmxSimple.usePin(TTL485Pin); 60 DmxSimple.maxChannel(MaxChannel); 61 pinMode(LedRPin, OUTPUT); 62 pinMode(LedGPin, OUTPUT); 63 pinMode(LedBPin, OUTPUT); 64 pinMode(ButtonRSPin, INPUT); 65 pinMode(TrimStroboPin, INPUT); 66 pinMode(TrimRedPin, INPUT); 67 pinMode(TrimGreenPin, INPUT); 68 pinMode(TrimBluePin, INPUT); 69 pinMode(TrimBrightnessPin, INPUT); 70}//setup() 71 72 73void loop() { 74 readButtons(); 75 readTrimmers(); 76 if ((lastRefresh+refreshRate) < millis()) { 77 if (isSTROBO==true) { 78 if ((ValStrobo < (prevValStrobo-antiBouncing)) || (ValStrobo > (prevValStrobo+antiBouncing))) { 79 writeDMX(chStrobo, ValStrobo); 80 if (IS_DEBUG) Serial.print("STROBO="); 81 if (IS_DEBUG) Serial.println(ValStrobo); 82 prevValStrobo=ValStrobo; 83 } 84 } 85 if ((ValRed < (prevValRed-antiBouncing)) || (ValRed > (prevValRed+antiBouncing))) { 86 writeDMX(chRed, ValRed); 87 analogWrite(LedRPin,ValRed/4); 88 if (IS_DEBUG) Serial.print("Red="); 89 if (IS_DEBUG) Serial.println(ValRed); 90 prevValRed=ValRed; 91 } 92 if ((ValGreen < (prevValGreen-antiBouncing)) || (ValGreen > (prevValGreen+antiBouncing))) { 93 writeDMX(chGreen, ValGreen); 94 analogWrite(LedGPin,ValGreen/4); 95 if (IS_DEBUG) Serial.print("Green="); 96 if (IS_DEBUG) Serial.println(ValGreen); 97 prevValGreen=ValGreen; 98 } 99 if ((ValBlue < (prevValBlue-antiBouncing)) || (ValBlue > (prevValBlue+antiBouncing))) { 100 writeDMX(chBlue, ValBlue); 101 analogWrite(LedBPin,ValBlue/4); 102 if (IS_DEBUG) Serial.print("Blue="); 103 if (IS_DEBUG) Serial.println(ValBlue); 104 prevValBlue=ValBlue; 105 } 106 if ((ValBrightness < (prevValBrightness-antiBouncing)) || (ValBrightness > (prevValBrightness+antiBouncing))) { 107 writeDMX(chBrightness, ValBrightness); 108 if (IS_DEBUG) Serial.print("Brightness="); 109 if (IS_DEBUG) Serial.println(ValBrightness); 110 prevValBrightness=ValBrightness; 111 } 112 lastRefresh=millis(); 113 } 114 if (isSTROBO==true && (lastStrobo+ledStroboRate) < millis()) blinkLed(); 115}//loop() 116 117void blinkLed() { // led blinking 118 if (ledStroboOn==false) { 119 analogWrite(LedRPin,ValRed/4); 120 analogWrite(LedGPin,ValGreen/4); 121 analogWrite(LedBPin,ValBlue/4); 122 ledStroboOn=true; 123 } else { 124 analogWrite(LedRPin,0); 125 analogWrite(LedGPin,0); 126 analogWrite(LedBPin,0); 127 ledStroboOn=false; 128 } 129 lastStrobo=millis(); 130}//blinkLed() 131 132void readButtons(){ 133 if (digitalRead(ButtonRSPin) == LOW) { 134 if (isSTROBO==false){ 135 prevValStrobo=0; 136 isSTROBO=true; 137 } else { 138 writeDMX(chStrobo, 0); // stop Strobo 139 if (IS_DEBUG) Serial.print("STROBO="); 140 if (IS_DEBUG) Serial.println(ValStrobo); 141 analogWrite(LedRPin,ValRed/4); 142 analogWrite(LedGPin,ValGreen/4); 143 analogWrite(LedBPin,ValBlue/4); 144 ledStroboOn=false; 145 isSTROBO=false; 146 } 147 if (IS_DEBUG) Serial.print("isSTROBO="); 148 if (IS_DEBUG) Serial.println(isSTROBO); 149 delay(250); 150 } 151}//readButtons() 152 153void readTrimmers(){ 154 // instead of mapping 0-1023 I use 10-1013 to reach limits 0-255 easily 155 ValStrobo=map(analogRead(TrimStroboPin),10,1013,8,255); 156 if (ValStrobo < 8) ValStrobo=8; 157 if (ValStrobo > 255) ValStrobo=255; 158 ValRed=map(analogRead(TrimRedPin),10,1013,0,255); 159 if (ValRed < 0) ValRed=0; 160 if (ValRed > 255) ValRed=255; 161 ValGreen=map(analogRead(TrimGreenPin),10,1013,0,255); 162 if (ValGreen < 0) ValGreen=0; 163 if (ValGreen > 255) ValGreen=255; 164 ValBlue=map(analogRead(TrimBluePin),10,1013,0,255); 165 if (ValBlue < 0) ValBlue=0; 166 if (ValBlue > 255) ValBlue=255; 167 ValBrightness=map(analogRead(TrimBrightnessPin),10,1013,0,255); 168 if (ValBrightness < 0) ValBrightness=0; 169 if (ValBrightness > 255) ValBrightness=255; 170}//readTrimmers() 171 172void writeDMX(const byte ch, const byte val) { 173 if (ch > 0 && ch <= MaxChannel ) DmxSimple.write(ch, val); 174 if (IS_DEBUG) Serial.print("sent "); 175 if (IS_DEBUG) Serial.print(ch); 176 if (IS_DEBUG) Serial.print(" "); 177 if (IS_DEBUG) Serial.println(val); 178}//writeDMX() 179
Base DMX Arduino code
arduino
1/* 2 This sketch acts as basic DMX lights controller, 5 channels, RGB 3 and STROBO, by Marco Zonca, 2/2021 4 Arduino Nano as 5V MPU, C25B TTL/RS485 rtx 5 board, 4 x 10k slider potentiometers, 6 one button, 10k potentiometer, RGB led, 7 3 x LED and a few resistors; 8 9 Channels: 1=brightness 10 2=Red 11 12 3=Green 13 4=Blue 14 5=STROBO (0-7 none, 8-255 15 rate) 16 */ 17 18#include <DmxSimple.h> 19 20#define IS_DEBUG false 21 22byte 23 MaxChannel = 5; 24bool isSTROBO = false; 25bool ledStroboOn = false; 26 27const 28 byte TTL485Pin = 3; 29const byte TrimStroboPin = 15; 30const byte TrimRedPin 31 = 16; 32const byte TrimGreenPin = 17; 33const byte TrimBluePin = 18; 34const 35 byte TrimBrightnessPin = 19; 36const byte LedRPin = 11; 37const byte LedGPin 38 = 10; 39const byte LedBPin = 9; 40const byte ButtonRSPin = 7; 41 42const unsigned 43 long refreshRate = 200; // millis, lower this for a quicker response at changes 44const 45 unsigned long ledStroboRate = 250; // millis, change this for a different led blinking 46 rate 47const byte antiBouncing = 1; // units, change this to 0 for a better granularity 48 of changes 49 // but more rtx traffic, or increase 50 to 2 if you experience jumping values 51const byte chStrobo=5; 52const byte chBrightness=1; 53const 54 byte chRed=2; 55const byte chGreen=3; 56const byte chBlue=4; 57 58 59int ValStrobo=0; 60int 61 ValRed=0; 62int ValGreen=0; 63int ValBlue=0; 64int ValBrightness=0; 65int prevValStrobo=0; 66int 67 prevValRed=0; 68int prevValGreen=0; 69int prevValBlue=0; 70int prevValBrightness=0; 71 72unsigned 73 long lastRefresh = 0; // millis 74unsigned long lastStrobo = 0; // millis 75 76void 77 setup() { 78 if (IS_DEBUG) Serial.begin(38400); 79 DmxSimple.usePin(TTL485Pin); 80 81 DmxSimple.maxChannel(MaxChannel); 82 pinMode(LedRPin, OUTPUT); 83 pinMode(LedGPin, 84 OUTPUT); 85 pinMode(LedBPin, OUTPUT); 86 pinMode(ButtonRSPin, INPUT); 87 pinMode(TrimStroboPin, 88 INPUT); 89 pinMode(TrimRedPin, INPUT); 90 pinMode(TrimGreenPin, INPUT); 91 92 pinMode(TrimBluePin, INPUT); 93 pinMode(TrimBrightnessPin, INPUT); 94}//setup() 95 96 97void 98 loop() { 99 readButtons(); 100 readTrimmers(); 101 if ((lastRefresh+refreshRate) 102 < millis()) { 103 if (isSTROBO==true) { 104 if ((ValStrobo < (prevValStrobo-antiBouncing)) 105 || (ValStrobo > (prevValStrobo+antiBouncing))) { 106 writeDMX(chStrobo, 107 ValStrobo); 108 if (IS_DEBUG) Serial.print("STROBO="); 109 if 110 (IS_DEBUG) Serial.println(ValStrobo); 111 prevValStrobo=ValStrobo; 112 113 } 114 } 115 if ((ValRed < (prevValRed-antiBouncing)) || (ValRed > 116 (prevValRed+antiBouncing))) { 117 writeDMX(chRed, ValRed); 118 analogWrite(LedRPin,ValRed/4); 119 120 if (IS_DEBUG) Serial.print("Red="); 121 if (IS_DEBUG) Serial.println(ValRed); 122 123 prevValRed=ValRed; 124 } 125 if ((ValGreen < (prevValGreen-antiBouncing)) 126 || (ValGreen > (prevValGreen+antiBouncing))) { 127 writeDMX(chGreen, ValGreen); 128 129 analogWrite(LedGPin,ValGreen/4); 130 if (IS_DEBUG) Serial.print("Green="); 131 132 if (IS_DEBUG) Serial.println(ValGreen); 133 prevValGreen=ValGreen; 134 135 } 136 if ((ValBlue < (prevValBlue-antiBouncing)) || (ValBlue > (prevValBlue+antiBouncing))) 137 { 138 writeDMX(chBlue, ValBlue); 139 analogWrite(LedBPin,ValBlue/4); 140 141 if (IS_DEBUG) Serial.print("Blue="); 142 if (IS_DEBUG) Serial.println(ValBlue); 143 144 prevValBlue=ValBlue; 145 } 146 if ((ValBrightness < (prevValBrightness-antiBouncing)) 147 || (ValBrightness > (prevValBrightness+antiBouncing))) { 148 writeDMX(chBrightness, 149 ValBrightness); 150 if (IS_DEBUG) Serial.print("Brightness="); 151 if 152 (IS_DEBUG) Serial.println(ValBrightness); 153 prevValBrightness=ValBrightness; 154 155 } 156 lastRefresh=millis(); 157 } 158 if (isSTROBO==true && (lastStrobo+ledStroboRate) 159 < millis()) blinkLed(); 160}//loop() 161 162void blinkLed() { // led blinking 163 164 if (ledStroboOn==false) { 165 analogWrite(LedRPin,ValRed/4); 166 analogWrite(LedGPin,ValGreen/4); 167 168 analogWrite(LedBPin,ValBlue/4); 169 ledStroboOn=true; 170 } else { 171 172 analogWrite(LedRPin,0); 173 analogWrite(LedGPin,0); 174 analogWrite(LedBPin,0); 175 176 ledStroboOn=false; 177 } 178 lastStrobo=millis(); 179}//blinkLed() 180 181void 182 readButtons(){ 183 if (digitalRead(ButtonRSPin) == LOW) { 184 if (isSTROBO==false){ 185 186 prevValStrobo=0; 187 isSTROBO=true; 188 } else { 189 writeDMX(chStrobo, 190 0); // stop Strobo 191 if (IS_DEBUG) Serial.print("STROBO="); 192 if 193 (IS_DEBUG) Serial.println(ValStrobo); 194 analogWrite(LedRPin,ValRed/4); 195 196 analogWrite(LedGPin,ValGreen/4); 197 analogWrite(LedBPin,ValBlue/4); 198 199 ledStroboOn=false; 200 isSTROBO=false; 201 } 202 if (IS_DEBUG) 203 Serial.print("isSTROBO="); 204 if (IS_DEBUG) Serial.println(isSTROBO); 205 206 delay(250); 207 } 208}//readButtons() 209 210void readTrimmers(){ 211 // instead 212 of mapping 0-1023 I use 10-1013 to reach limits 0-255 easily 213 ValStrobo=map(analogRead(TrimStroboPin),10,1013,8,255); 214 215 if (ValStrobo < 8) ValStrobo=8; 216 if (ValStrobo > 255) ValStrobo=255; 217 ValRed=map(analogRead(TrimRedPin),10,1013,0,255); 218 219 if (ValRed < 0) ValRed=0; 220 if (ValRed > 255) ValRed=255; 221 ValGreen=map(analogRead(TrimGreenPin),10,1013,0,255); 222 223 if (ValGreen < 0) ValGreen=0; 224 if (ValGreen > 255) ValGreen=255; 225 ValBlue=map(analogRead(TrimBluePin),10,1013,0,255); 226 227 if (ValBlue < 0) ValBlue=0; 228 if (ValBlue > 255) ValBlue=255; 229 ValBrightness=map(analogRead(TrimBrightnessPin),10,1013,0,255); 230 231 if (ValBrightness < 0) ValBrightness=0; 232 if (ValBrightness > 255) ValBrightness=255; 233}//readTrimmers() 234 235void 236 writeDMX(const byte ch, const byte val) { 237 if (ch > 0 && ch <= MaxChannel ) 238 DmxSimple.write(ch, val); 239 if (IS_DEBUG) Serial.print("sent "); 240 if (IS_DEBUG) 241 Serial.print(ch); 242 if (IS_DEBUG) Serial.print(" "); 243 if (IS_DEBUG) Serial.println(val); 244 245}//writeDMX() 246
Downloadable files
PCB bottom copper (main solder face)
PCB bottom copper (main solder face)
PCB overview
PCB overview
PCB bottom components
PCB bottom components
PCB top components
PCB top components
Schematic diagram (Fritzing)
Schematic diagram (Fritzing)
PCB bottom copper (main solder face)
PCB bottom copper (main solder face)
PCB bottom components
PCB bottom components
PCB top components
PCB top components
Schematic diagram (Fritzing)
Schematic diagram (Fritzing)
PCB overview
PCB overview
PCB top copper
PCB top copper
Comments
Only logged in users can leave comments
marcozonca
0 Followers
•0 Projects
Table of contents
Intro
4
0