<div dir="ltr"><div><div>anyway, will this work?<br><br><br>/*<br></div> 4 channel dmx ac dimmer<br></div> with AC Light Control & DMXSerialRecv<br><div><div> AC Light Control<br> Ryan McLaughlin <<a href="mailto:ryanjmclaughlin@gmail.com">ryanjmclaughlin@gmail.com</a>><br> with slight modifications<br></div><div> DMXSerialRecv<br></div><div> mathertel <a href="https://github.com/mathertel/DMXSerial/tree/master/examples/DmxSerialRecv">https://github.com/mathertel/DMXSerial/tree/master/examples/DmxSerialRecv</a><br></div><div> with modifications<br></div><div>*/<br><br>#include <DMXSerial.h> // <a href="https://github.com/mathertel/DMXSerial/blob/master/src/DMXSerial.h">https://github.com/mathertel/DMXSerial/blob/master/src/DMXSerial.h</a><br>#include <TimerOne.h> // <a href="http://www.arduino.cc/playground/Code/Timer1">http://www.arduino.cc/playground/Code/Timer1</a><br>#define PINS 4<br>volatile int pinCount[PINS]; // make volatile to make available in interrupt<br>volatile boolean zero_cross=0; // Boolean to store a "switch" to tell us if we have crossed zero<br>int AC_pins[] = {3,4,5,6}; // Stup the pin numbers<br>int AC_dim[PINS]; // Holds Dimming levels (0-128) 0 = on, 128 = 0ff<br>int freqStep = 65; // Set the delay for the frequency of power (65 for 60Hz, 78 for 50Hz) per step (using 128 steps)<br> // freqStep may need some adjustment depending on your power the formula <br> // you need to us is (500000/AC_freq)/NumSteps = freqStep<br><br>void setup() {<br> DMXSerial.init(DMXReceiver); // Setup external mode signal, Hardware & Enable receiver and Receive interrupt<br> <br> for(int a=0; a < PINS; a++) { //set the pins to output<br> pinMode(AC_pins[a],OUTPUT);<br> pinCount[a] = 0; // keeps track of the time in the cycle <br> AC_dim[a] = 0; // dimming level set to zero<br> }<br> attachInterrupt(0, zero_cross_detect, FALLING); // Attach Interrupt to Pin 2 (interrupt 0) for Zero Cross Detection<br> Serial.begin(9600);<br> Timer1.initialize(freqStep); // Initialize TimerOne library for the freq we need<br> Timer1.attachInterrupt(dim_check, freqStep); // Use the TimerOne Library to attach an interrupt<br> // to the function we use to check to see if it is <br> // the right time to fire the triac. This function <br> // will now run every freqStep in microseconds. <br>}<br><br>void zero_cross_detect() { // function to be fired at the zero crossing <br> zero_cross = 1; // set flag to tell dimming function zero cross has occured<br>} // End zero_cross_detect<br><br>void dim_check() { // Function will fire the triac at the proper time<br> if(zero_cross == 1) { // First check to make sure the zero-cross has happened else do nothing<br> for(int a=0; a < PINS; a++) {<br> if(pinCount[a] >= AC_dim[a]) { // Check and see if i has reached the dimming value we want<br> digitalWrite(AC_pins[a], HIGH); // Fire the Triac <br> delayMicroseconds(5); // Pause briefly to ensure the triac turned on<br> digitalWrite(AC_pins[a], LOW); // Turn off the Triac gate (Triac will turn off at the next zero cross)<br> pinCount[a] = 0; // Reset the accumulator<br> zero_cross = 0; // Reset the zero_cross so it may be turned on again at the next zero_cross_detect <br> } else {<br> pinCount[a]++; // If the dimming value has not been reached, incriment the counter<br> } <br> }<br> }<br>}<br><br>void loop() {<br> // Calculate how long no data backet was received<br> unsigned long lastPacket = DMXSerial.noDataSince();<br> <br> if (lastPacket < 5000) {<br> // read recent DMX values and set dimmer levels <br> analogWrite(AC_pins[a],, DMXSerial.read[a]);<br><br> // *This is simply making all outputs cycle through bright-dark, out of time with each other.<br> for(int i=0; i<127; i ++) {<br> for(int a=0; a < PINS; a++) {<br> int ii = i+42; //this is the bit that puts the blinking lights out of sync with one another<br> if(ii > 127) ii -= 127;<br> AC_dim[a] = ii;<br> }<br> delay(50);<br> }*//<br>}<br><br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 25, 2016 at 8:57 AM, robb <span dir="ltr"><<a href="mailto:sf99er@gmail.com" target="_blank">sf99er@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">using an esp8266 w/it's <a href="http://www.instructables.com/id/ESP8266-NodeMCU-CPU-Speed-Test/" target="_blank">80 or 160mhz</a> clock might be the way to go tho<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 25, 2016 at 8:33 AM, robb <span dir="ltr"><<a href="mailto:sf99er@gmail.com" target="_blank">sf99er@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><a href="http://danfredell.com/df/Projects/Entries/2013/1/6_DMX_Dimmer.html" target="_blank">Dan Fredell's</a> 4 channel design uses a 20mhz clock<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 25, 2016 at 1:01 AM, Jake <span dir="ltr"><<a href="mailto:jake@spaz.org" target="_blank">jake@spaz.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">send links along with claims like this<div><div><br>
<br>
On Wed, 24 Aug 2016, robb wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
and<br>
why do you need a 20MHz crystal?<br>
apparently you need 20mhz for 4 stable channels when using the timer method<br>
<br>
</blockquote>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>