I am trying to create a DMX strobe light at precise frequencies around 10hz or 30hz.
My attempt below kind of works but I am hoping for a better way to set the ON/OFF period and the duty cycle. My light starts working but then stops after a while (1min?). I suspect this is because the rate info is being sent to DMX eventually drifts out of sync and the signal is no longer recognizable to the fixture.
I have commented out my Timer1 examples. Currently testing on an Uno but likely will switch to a Teensy 3.6.
I have red lots of examples that are similar but am having issues implementing it.
Thanks
#include <DmxSimple.h>
#include <FastLED.h>
#include <TimerOne.h>
//DMX Colors
CHSV color1 = CHSV(120, 255, 255); //200-50 gd
CHSV color2 = CHSV(250, 255, 20);
//CRGB color_current; //dmx color
CRGB DMXColor;
//int perc;
long intervalMillis = 10;
int prevMillis = 0;
//int hue = 0; //lightbar hue
void setup() {
DmxSimple.usePin(3);
DmxSimple.maxChannel(21);
DmxSimple.write(1, 255);
// Timer1.initialize(100000); // set a timer of length 100000 microseconds
// Timer1.pwm(13, 512);
// Timer1.attachInterrupt(callback);
}
void loop() {
//Test ON
// DmxSimple.write(1, 255);
// DmxSimple.write(2, 255);
// DmxSimple.write(3, 255);
// DmxSimple.write(4, 255);
//
// perc = beatsin8(20, 1, 100); //speed, start steps, end steps
if (millis() - prevMillis <= (intervalMillis/2)){
DMXColor = color1;
sendDMX(2, DMXColor); // ON
}
else if ((millis() - prevMillis) > (intervalMillis/2) && (millis() - prevMillis) < (intervalMillis)){
DMXColor = color2;
sendDMX(2, DMXColor); // OFF
}
else {
prevMillis = millis();
}
}
void sendDMX(int theUnit, CRGB & DMXColor) {
DmxSimple.write(1, 255);
for(int z=0; z<3; z++) {
DmxSimple.write(theUnit+z, DMXColor[z]);
}
}
//Timer1 Attempt
//void callback()
//{
// sendDMX(2, DMXColor);
// digitalWrite(13, digitalRead(13) ^ 1);
//}
/*
* 10hz freq
* 100ms cycle
* 50ms on / off // Duty cycle to be determined
*/