Trigger -> Timer -> LED on/off

red33mer

2008-10-29 23:25:39

Hey guys,

I have a button that is my trigger, and a LED next to the button i want to flash as long as the button is pressed again.

LED ON is achieved via Note On, Value 01
LED OFF is achieved via Note Off, Value 00

My Pseudo Code is as follows:

Code: Select all

Press Button: 90 22 01
LED ON: 90 4F 01, duration 500ms
LED OFF: 80 4F 00, duration 500ms
LED ON: 90 4F 01, duration 500ms
LED OFF: 80 4F 00, duratio 500ms
.
repeat that indefinetely till button is pressed again.
How can i do that with the timerfeature?

Code: Select all


Translator 90 22 01 -> "LED Timer", 500ms, indefinetely
Translator "LED Timer" -> 90 4F 01
???
How do i implement the LED OFF ?


Thanks for helping a N00B :-)
Alex

metastatik

2008-10-30 16:59:53

Something like this…

Code: Select all

Translator 1 (set global)
Options: Stop=False
Incoming:  MIDI 90 22 01 
Rules:
    ga = 1 – ga
Outgoing: (none)
This turns your button into a toggle. The first time you press the button, ga will increase to 1 because 0=1-0. Second press, it will revert to 0 because 0=1-1.

Code: Select all

Translator 2 (set timer 1)
Options: Stop=False
Incoming: MIDI 90 22 01 
Rules:
    If ga != 1 then exit rules, skip Outgoing Action
Outgoing: Periodic timer “T1”: 250 ms (initial delay: 0 ms)
   
Translator 3 (set timer 2)
Options: Stop=False
Incoming: MIDI 90 22 01 
Rules:
    If ga != 1 then exit rules, skip Outgoing Action
Outgoing: Periodic timer “T2”: 500 ms (initial delay: 0 ms)
These 2 actions will only occur if ga=1. They will trigger the timers to flash the LED.

Code: Select all

Translator 4 (kill timer 1)
Options: Stop=False
Incoming: MIDI 90 22 01 
Rules:
    If ga != 0 then exit rules, skip Outgoing Action
Outgoing: Kill timer “T1”

Translator 5 (kill timer 2)
Options: Stop=False
Incoming: MIDI 90 22 01 
Rules:
    If ga != 0 then exit rules, skip Outgoing Action
Outgoing: Kill timer “T2”
These 2 actions will only occur if ga=0. They will kill the timers to stop the LED from flashing.

Code: Select all

Translator 6 (LED Flash On)
Options: Stop=False
Incoming: On timer “T1” 
Outgoing: MIDI 90 4F 01

Translator 7 (LED Flash Off)
Options: Stop=False
Incoming: On timer “T2” 
Outgoing: MIDI 80 4F 00
These are the actions that make the LED flash.

It’s possible to only use one timer for this by using more rules, but I thought this way would be easier to understand.

red33mer

2008-10-30 20:24:23

Hi Metastatik,

thank you so much! Works like a charm.
After looking at the solution it seems so easy :oops:


If you have the time i would be very interested in the more elegant way with
one timer as well, since i have a lot of LEDs and i could save some lines of code...but just in case you want to. Really interested in learning though.



Thanks again!! ;)
Alex

metastatik

2008-10-30 21:00:43

Sure, here’s a much more elegant way.

Code: Select all

Translator 1 (set global/set timer) 
Options: Stop=False 
Incoming: MIDI 90 22 01 
Rules: 
ga = 1 – ga 
If ga != 1 then exit rules, skip Outgoing Action 
Outgoing: Periodic timer “T1”: 250 ms (initial delay: 0 ms) 

Translator 2 (kill timer) 
Options: Stop=False 
Incoming: MIDI 90 22 01 
Rules: 
If ga != 0 then exit rules, skip Outgoing Action 
Outgoing: Kill timer “T1”

Translator 1 is now a combination of the original Translators 1 and 2.

Code: Select all

Translator 3 (LED) 
Options: Stop=False 
Incoming: On timer “T1” 
Rules:
gb = 1 - gb
If gb = 1 then pp = 144
If gb = 0 then pp = 128
Outgoing: MIDI pp 4F gb
Each time the timer is triggered, the value of "gb" will toggle between 1 and 0. The value of "gb" determines the value of "pp".

144 in decimal = 90 in hex…for your LED on message.
128 in decimal = 80 in hex…for your LED off message.

It’s very convenient because the velocity of your LED on/off messages (01/00) match the value of “gb” (1/0) so we just use “gb” in place of the velocity in the outgoing message.

Let me know if any of that isn't clear.

metastatik

2008-10-30 21:09:00

Forgot to mention something. I’m assuming you want the light to flash when pressed once and then stop flashing (and turn off) on second press, right? If so, you need to add another translator because right now the second press will simply stop the flashing…which could leave the light remaining on.

Code: Select all

Translator 4 (LED off) 
Options: Stop=False 
Incoming: MIDI 90 22 01 
Rules: 
If ga != 0 then exit rules, skip Outgoing Action 
Outgoing: MIDI 80 4F 00

red33mer

2008-10-30 22:08:13

Thanks! Same result but way better...:-)
Indeed, i had the problem with the status of the led when pressing again but could already handle that myself :D

cant thank you enough...highly appreciated.
alex

red33mer

2008-11-09 19:36:58

Hello..me again with a new problem related to the above discussion.
I am stuck. Gotta explain the setup first.

my controller has a touchpad consisting of 8 fields. each of them outputs its own midimessage p.e. 90 4F 01 when pressing and 90 4F 00 when releasing.

when pressing a field a timer is triggered in the above way (toggle in the rules). The timer controlls LEDs next to the fields and is killed when pressing a field again.

Additionaly i merge two fields to one midi output, means that pressing field 1 or field 2 outputs the same midi message.
This is done via rules and if condition:

Code: Select all


Translator 1 (set_toggle_set_timer)
Incoming:  MIDI 90 xx 01
Rules:
  if xx==79 then Goto "Merge"
  if xx==81 then Goto "Merge"
  exit rules, skip outgoing Action
  Label "Merge"    
  ga = 1 – ga
  if ga!=1 then exit rules, skip Outgoing Action
Outgoing: Timer T1


Translator 2 (Kill Timer)
Incoming: MIDI 90 xx 01
if ga!=0 then exit rules, skip Outgoing Action
if xx==79 then exit rules, execute Outgoing Action
if xx==81 then exit rules, execute Outgoing Action
exit rules, skip Outgoing Action

Outgoing: Kill Timer T1

Everything is working fine so far BUT (here comes the problem)
when Djing it happens that both fields are pressed simultaneously with one finger due to the fact that they have a very short distance. In this case the timer doesnt start. In my opinion this results from the toggle rule..the first midi message sets the toggle to 1 while the second one arrives a few milliseconds later and sets it to 0 again. That means that the timer is not executed...

How can i solve this? When using two translators with two different toggle variables the killing isnt working anymore...
i am stuck...

thank you very much for helping me
alex

red33mer

2008-11-11 16:12:52

anybody able to help?

florian

2008-11-24 17:04:17

I would think you need one toggle timer per button then. They should have different names.

Florian