May 18, 2024, 03:21:21 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


PWM LED Codes Via DMX

Started by michilson, November 05, 2014, 08:08:54 AM

Previous topic - Next topic

michilson

Guys need help with a little code work. Below is DMX Channels 3-5 controls Red, Green, Blue Leds.

I need help adding Ch6 (Brightness control of those 3 channels) I need this to read Ch 3,4,5 then equally move the brightness of these 3 channels to maintain preset color. 0 = Off 255 = Full On (% of the current value)

I also need CH7 to control the Strobe (Blink Rate) from the 3 Channels 0=Slow 20Hz - 250= 260hz 255=Full on (No Strobe)

    ' set rgb levels
     
    outs.set(0, addr+3)                                         ' red    OUT4
    outs.set(1, addr+4)                                         ' green  OUT5
    outs.set(2, addr+5)                                         ' blue   OUT6

    check := dmx.read(addr+6)                                   ' read Brightness index


    check := dmx.read(addr+7)                                   ' read strobe index


Thanks guys! for the help with this.

JonnyMac

Get the value from channel 6 first, then apply it to the other three -- like this:

  brightness := dmx.read(addr+6)

  repeat ch from 0 to 2
    level := dmx.read(addr+ch+3)
    level := level * brightness / 255
    outs.set(ch, level)



Adding the strobe feature takes a lot more work. You need to add a timer object to your code to keep track of the strobe phase if it's in use. Then that has to be applied to the channels. So... start with strobe. If it's in use and the outputs are off, ingnore reading the color channels this cycle. Keep tracking things until the strobe is in an "on" phase, and then do what I described above.

BTW... I wouldn't consider 20Hz "slow" and think that going much higher than that is going to affect brightness without looking like strobing.

Jon McPhalen
EFX-TEK Hollywood Office

michilson

I am having a hard time with the strobe function can someone give me a hand writing the Code. I'm not familiar with this code to get it.

Quote

Channel 7 should control the Strobe (Blink Rate) from the 3 Channels 0=Slow 20Hz - 250= 260hz 255=Full on (No Strobe)

The Blink Cycle in Hz is just a example of blink per Cycle.

    ' set rgb levels
     
    outs.set(0, addr+3)                                         ' red    OUT4
    outs.set(1, addr+4)                                         ' green  OUT5
    outs.set(2, addr+5)                                         ' blue   OUT6


I also want the Strobe function to respond to Channel 7 to respond to the Brightness control of Channel 6.

Here's a Example of how Channels 3 - 7 should function.

DMX CH 3 Controls Brightness of Red LEDS
DMX CH 4 Controls Brightness of Green LEDS
DMX CH 5 Controls Brightness of Blue LEDS

DMX CH 6 is a Summed Brightness Controlling Channels 3-5 Equally

DMX CH 7 is a Strobe control to blink active levels of Chanel 3-5


I hope that someone can help me code this. This is the remaining request for the product I am developing. I can then start testing.

Thanks Guys!

JonnyMac

December 11, 2014, 04:12:48 PM #3 Last Edit: December 13, 2014, 04:49:14 PM by JonnyMac
Have a look at this. It uses channel 7 to flash (50% duty) the LEDs -- note, though the that value from DMX channel 7 is in flashes per minute, not flashes per second (Hz). The trick is keeping track of time -- you can't simply hold the loop for the strobe time as other DMX channels would be delayed and this could create other problems. Luckily, I created a timer object for an EFX-TEK client project that works really well in applications like this. It's attached and you'll need to add it to your project.

Here's what the main code loop might look like.

  time.start

  repeat
    strobe := dmx.read(base+7)                          ' read strobe control
    if (strobe > 250)                                   ' always on?
      state := 1                                        ' set state bit
      time.start                                        ' reset timer
    elseif (strobe < 20)                                ' always off?
      state := 0                                        ' clear state bit
      time.start                                        ' reset timee
    else
      ms := 30_000 / strobe                             ' calc strobe rate (50% duty)
      if (time.millis => ms)                            ' time to toggle?
        state ^= 1                                      ' toggle state bit
        time.adjust(-ms)                                ' adjust timer

    repeat ch from 0 to 2                               ' loop through output channels
      if (state & 1)                                    ' okay to be on?
        level := dmx.read(base+3)                       ' read dmx color channel
        level := level * dmx.read(base+6) / 255         ' apply master level
        outs.set(ch, level)                             ' update output channel
      else
        outs.set(ch, $00)                               ' turn off



In the OBJ section of your program you'll need this line:

  time : "jm_time"
Jon McPhalen
EFX-TEK Hollywood Office