Created
April 27, 2015 19:23
-
-
Save antimodular/e4fcc31a1aa951a4b514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DmxReceiver.h> | |
DmxReceiver DMX2 = DmxReceiver(); | |
#define NUM_LEDS_USED 20 | |
//---------------------------------------DMX------------------------------------- | |
volatile unsigned char dmx_data[NUM_LEDS_USED]; | |
volatile unsigned char data; | |
unsigned long last_dmx_update; | |
unsigned long dura; | |
int dmxStartAddress = 1; | |
//---------------------------------------DIMMER------------------------------------- | |
#define timer0_duration 30 | |
int zeroCrossPin = 2; | |
int AC_LOAD[NUM_LEDS_USED] = { | |
3,4,5,6, 9,10, 20,21,22,23, 7,8, 11,12,13, 24,25,26,27 }; //20,21,13,14,15,16,17}; // Output to Opto Triac pin | |
elapsedMicros sinceInterrupt; | |
IntervalTimer timer0; | |
int fadeValues[NUM_LEDS_USED]; | |
void setup(){ | |
pinMode(zeroCrossPin, INPUT); | |
attachInterrupt(zeroCrossPin, zero_crosss_int, RISING); | |
//attachInterrupt(zeroCrossPin, zero_crosss_int, FALLING); | |
timer0.begin(timerFire0, timer0_duration); | |
for(int i=0; i <NUM_LEDS_USED;i++){ | |
pinMode(AC_LOAD[i], OUTPUT); // Set the AC Load as output | |
fadeValues[i] = 8333; // for 50HZ power ->6500; | |
} | |
DMX2.begin(); | |
} | |
void loop(){ | |
DMX2.bufferService(); | |
if (DMX2.newFrame()) { | |
dura = millis()- last_dmx_update; | |
last_dmx_update = millis(); | |
for(int i=0; i<NUM_LEDS_USED; i++){ | |
dmx_data[i] = DMX2.getDimmer(dmxStartAddress + i+1); | |
fadeValues[i] = map(dmx_data[i], 0, 255,8333,0); | |
} | |
} | |
} | |
void zero_crosss_int(){ | |
// Ignore spuriously short interrupts | |
if (sinceInterrupt < 2000){ | |
return; | |
} | |
sinceInterrupt = 0; | |
for(int i=0; i<NUM_LEDS_USED;i++){ | |
digitalWrite(AC_LOAD[i], LOW); | |
} | |
} | |
void timerFire0(void){ | |
for(int i=0; i<NUM_LEDS_USED;i++){ | |
if(sinceInterrupt >= fadeValues[i]){ | |
if(digitalRead(AC_LOAD[i]) == LOW) { | |
digitalWrite(AC_LOAD[i], HIGH); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment