Skip to content

Commit f4560f8

Browse files
authored
Rev 3.0
Current In use revision. No RDM & no WDMX module SPI control. Signal Will hold after loss forever.
1 parent ce744a0 commit f4560f8

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

fastLED_DMX_3.ino

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//Written by Alex Woodmansey using Version 1.6.8
2+
#include "lib_dmx.h" //4 Universe DMX Library http://www.deskontrol.net/blog/arduino-four-universes-dmx-512-library/
3+
#include "FastLED.h" //Fast LED Library https://github.com/FastLED/FastLED
4+
#include <EEPROM.h>
5+
#define DMX512 (0) // (250 kbaud - 2 to 512 channels) Standard USITT DMX-512
6+
#define NUM_LEDS 64 //Number of LED Pixels connected
7+
#define DATA_PIN 6 //Data Pin for LED Pixels
8+
CRGB leds[NUM_LEDS]; //Define LED Array
9+
#define COLOUR_ORDER GRB // LED colour order
10+
11+
const int ledPin = 5; // LED Pin 5 for DMX reception yes/no
12+
const int testPin = 3; // Switch Pin for Testing battery and panel
13+
const int disconnectPin = 2; // switch pin to disconnect wdmx
14+
const int WDMX_button = A5; // WDMX Button Pin
15+
unsigned long now = 0; //current time value
16+
const byte channelwidth = 3; //3 DMX channels per pixel
17+
byte channel; //channel number for each pixel RGB
18+
volatile byte currentcounter = 0; //counter for DMX reception
19+
byte previouscounter = 0; //counter for DMX reception
20+
byte current_hue; //hue value for rainbow effect
21+
byte ledNumber; //current led Pixel being used
22+
volatile int val; //analog voltage from
23+
24+
25+
26+
void setup()
27+
{
28+
// EEPROM.write(0, 1);
29+
// EEPROM.write(1, 64);
30+
ArduinoDmx0.attachRXInterrupt (frame_received); //set function called when all channels received
31+
ArduinoDmx0.set_control_pin (A2); // control pin for max485
32+
ArduinoDmx0.set_rx_address(1); // set rx0 dmx start address
33+
ArduinoDmx0.set_rx_channels(NUM_LEDS*channelwidth); // number of DMX channel to receive
34+
ArduinoDmx0.init_rx(DMX512); // starts universe 0 as rx, NEW Parameter DMX mode
35+
pinMode (ledPin, OUTPUT); //status LED set to Output
36+
pinMode (testPin, INPUT_PULLUP); //Test Mode Switch
37+
pinMode (WDMX_button, OUTPUT); //WDMX control button
38+
pinMode (disconnectPin, INPUT_PULLUP); //Disconnect interrupt switch
39+
digitalWrite(WDMX_button, HIGH); //WDMX control pin left high
40+
LEDS.setBrightness(255); //Set overall LED brightness
41+
FastLED.addLeds<WS2812, DATA_PIN, COLOUR_ORDER>(leds, NUM_LEDS); //initialize LED Pixel output
42+
attachInterrupt(digitalPinToInterrupt(disconnectPin), disconect, LOW);
43+
FastLED.setMaxPowerInVoltsAndMilliamps(5,2700); //#experiemental# sets max power at 13.5w for LEDS
44+
45+
46+
post(); //run power on self test function each time board resets
47+
SYS_TEST();
48+
} //end setup()
49+
50+
void loop()
51+
{
52+
if(currentcounter != previouscounter) //has the value changed?
53+
{
54+
now = millis(); //store the time since the value has increased
55+
previouscounter = currentcounter; //set the previous value equal to the current value
56+
}
57+
58+
if((millis() - now) > 5000) //is the time since the value changed greater than 5 seconds?
59+
{
60+
//digitalWrite(ledPin, LOW); //turn status LED off. We are no longer receiving the DMX signal.
61+
noDMX(); //run no DMX function
62+
}
63+
else
64+
{
65+
digitalWrite(ledPin, HIGH); //turn status LED on. We are receiving the DMX signal.
66+
DMXProcess(); //run DMX function
67+
}
68+
69+
} //end loop()
70+
71+
// Custom ISR: fired when all DMX channels in one universe are received
72+
void frame_received(uint8_t universe)
73+
{
74+
static uint8_t led;
75+
76+
if (universe == 0) // USART0
77+
{
78+
currentcounter++; //increase counter by 1 each time through
79+
}
80+
} // end of ISR
81+
82+
83+
void DMXProcess() //Function to process DMX data
84+
{
85+
channel = 0; //reset DMX channel assignment to 0 each time through loop.
86+
for(ledNumber = 0; ledNumber < NUM_LEDS; ledNumber++) //Counter for pixel number
87+
{
88+
leds[ledNumber]= CRGB(ArduinoDmx0.RxBuffer[channel], ArduinoDmx0.RxBuffer[channel +1], ArduinoDmx0.RxBuffer[channel +2]); //assign DMX channels to RGB channel of each pixel
89+
channel +=channelwidth; //increase last DMX channel number by channel width
90+
}
91+
FastLED.show(); //Send data to pixels
92+
delay(60); //delay 60 miliseconds for DMX to catch up.
93+
}
94+
95+
void noDMX() //Function to run when no DMX signal is present
96+
{
97+
digitalWrite(ledPin, LOW); //turn status LED off. We are no longer receiving the DMX signal.
98+
delay(500);
99+
100+
101+
} //End noDMX
102+
103+
void SYS_TEST() //Will show battery voltage on a scale of 0-1023 over 0-NUM_LEDs [requires calabration]
104+
{
105+
FastLED.clear(); //take all LEDs to 0
106+
fill_solid( leds, NUM_LEDS, CRGB(255,255,255));
107+
FastLED.show();
108+
delay(300);
109+
int val = analogRead(0); //reads battery Voltage
110+
float numLedsToLight = val /3.487 ;
111+
FastLED.clear(); //take all LEDs to 0
112+
for(int led = 0; led < numLedsToLight; led++) {
113+
leds[led] = CRGB::Green;
114+
}
115+
FastLED.show();
116+
delay(10000);
117+
}
118+
119+
void post() //power on self test function. Make sure all pixels are working and run through colors.
120+
{
121+
LEDS.showColor(CRGB(255, 0, 0)); //turn all pixels on red
122+
delay(1000);
123+
LEDS.showColor(CRGB(0, 255, 0)); //turn all pixels on green
124+
delay(1000);
125+
LEDS.showColor(CRGB(0, 0, 255)); //turn all pixels on blue
126+
delay(1000);
127+
LEDS.showColor(CRGB(0, 0, 0)); //turn all pixels off
128+
129+
}
130+
131+
void disconect() //Disconnects WDMX module, runs within ISR - could be nicer.
132+
{
133+
digitalWrite(WDMX_button,LOW);
134+
delayMicroseconds(30000);
135+
delayMicroseconds(30000);
136+
delayMicroseconds(30000);
137+
delayMicroseconds(30000);
138+
digitalWrite(WDMX_button,HIGH);
139+
}

0 commit comments

Comments
 (0)