dizzu Posted May 21, 2007 Report Share Posted May 21, 2007 How should i program the leds so that for each different midi note coming from the pc a different led lights? I have 128 leds connected to core.I tested ain64_din128_dout128 and works fine, so I would like to do the same from the pc nowBasically i want to build a software ( hope that I find one free :-) ), to trigger an led according to outputs selected, from 0-127Thanks a lot Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 21, 2007 Report Share Posted May 21, 2007 Have you looked at the function reference and C skeleton? MPROC_NotifyReceivedEventMIOS_DOUT_PinSetThat's all ya need Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 21, 2007 Author Report Share Posted May 21, 2007 thanks, working nearly as i want it but....I wrote the following;/////////////////////////////////////////////////////////////////////////////// This function is called by MIOS after startup to initialize the // application/////////////////////////////////////////////////////////////////////////////void Init(void) __wparam{ // set shift register update frequency MIOS_SRIO_UpdateFrqSet(1); // ms // only one DOUTX4 module is connected // the maximum value is 16 (-> 128 digital outputs) MIOS_SRIO_NumberSet(16);}/////////////////////////////////////////////////////////////////////////////// This function is called by MIOS when a complete MIDI event has been received/////////////////////////////////////////////////////////////////////////////void MPROC_NotifyReceivedEvnt( unsigned char evnt0, unsigned char evnt1, unsigned char evnt2, unsigned char pin, unsigned char value) __wparam{ // a note event provides 128 different note values (0..127) // in this simple example, each note sets an individual pin // for DOUT pin numbers, see also this documentation: // http://www.ucapps.de/mios/mios_pin_list.txt if( evnt0 == 0x80 || evnt0 == 0x90 ) { // 90 xx 00 is the same like a note off event! // (-> http://www.borg.com/~jglatt/tech/midispec.htm) if( evnt0 == 0x80 || evnt2 == 0x00 ) { // Note Off MIOS_DOUT_PinSet(pin, 0); } else { // Note On MIOS_DOUT_PinSet(pin, 1); } }}and every note I send I get the same first led to light only. Can I modify the code so that each led corresponds to a different note?Thanks Quote Link to comment Share on other sites More sharing options...
stefstabilizer Posted May 21, 2007 Report Share Posted May 21, 2007 I've hardly started on the programming side but the bit where you turn on the LED..-> MIOS_DOUT_PinSet(pin, 1);You don't seem to have set the 'pin' variable from the note number? Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 21, 2007 Author Report Share Posted May 21, 2007 most probably i need to write code for each led to correspond to each note. Still got no idea haw to do it, but will try.Thanks Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 21, 2007 Report Share Posted May 21, 2007 void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2, unsigned char pin, unsigned char value) __wparam Hah where did ya get that from? should look like this: void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam then do: MIOS_DOUT_PinSet(evnt1, 1) Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 21, 2007 Author Report Share Posted May 21, 2007 not working............ now no led's light if( evnt0 == 0x80 || evnt0 == 0x90 ) { // 90 xx 00 is the same like a note off event! // (-> http://www.borg.com/~jglatt/tech/midispec.htm) if( evnt0 == 0x80 || evnt2 == 0x00 ) { // Note Off MIOS_DOUT_PinSet(evnt1, 0); } else { // Note On MIOS_DOUT_PinSet(evnt1, 1);No idea how or what's happening :-( Quote Link to comment Share on other sites More sharing options...
DavidBanner Posted May 21, 2007 Report Share Posted May 21, 2007 how many leds do you have attached?i.e. if you have all 128 outputs attached via the DOUTX4s try moving the cable to the various outputsand isn't that code exactly what's in ain64_din128_dout128_v2_0.zip anyway? Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 21, 2007 Report Share Posted May 21, 2007 Well, posting in year-old threads may not help, especially when they already put the answer there ;)Cross-posting like that is generally considered bad netiquette, it just creates confusion...Maybe you should try some troubleshooting... Try hardcoding a value in there...MIOS_DOUT_PinSet(32, 1); Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 21, 2007 Author Report Share Posted May 21, 2007 sorry about posting.. i deleted it.Yes I already tried hardcoding before like this // Note Off MIOS_DOUT_PinSet(2, 0); } else { // Note On MIOS_DOUT_PinSet(2, 1);It works when I send a midi note, turns on led 3 and off straightaway.I am sending midi notes from the keyboard on MIOS studio, that's ok to test? Quote Link to comment Share on other sites More sharing options...
Jidis Posted May 21, 2007 Report Share Posted May 21, 2007 You don't seem to have set the 'pin' variable from the note number?Speaking of which- I was looking at some of Thorsten's "Programming Examples" from the bottom of the MIOS C interface page the other night, and there's an example which seems to do the same thing (I couldn't find the link between the incoming note # and the "pin" variable used for the DOUT call). IIRC, I had seen the missing part in one of his other apps or examples, so maybe the example snippet was pulled from one of them.Take Care Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 21, 2007 Author Report Share Posted May 21, 2007 When I program this line MIOS_DOUT_PinSet(pin, 0); exactly as in the programming example it gives an error when compiling. Is the programming example incomplete? or am I missing something?I will try to modify ain64_din128_dout128 as someone posted in this thread [tt]http://www.midibox.org/forum/index.php?topic=5034.15[/tt]Will let you knowThanks Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 21, 2007 Report Share Posted May 21, 2007 or am I missing something?Yeh, you forgot to put the error in your post ;) Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 22, 2007 Author Report Share Posted May 22, 2007 When trying to code this ' Controlling 128 LEDs VIA midi ' example///////////////////////////////////////////////////////////////////////////// // This function is called by MIOS after startup to initialize the // application ///////////////////////////////////////////////////////////////////////////// void Init(void) __wparam { // set shift register update frequency MIOS_SRIO_UpdateFrqSet(1); // ms // only one DOUTX4 module is connected // the maximum value is 16 (-> 128 digital outputs) MIOS_SRIO_NumberSet(16); } ///////////////////////////////////////////////////////////////////////////// // This function is called by MIOS when a complete MIDI event has been received ///////////////////////////////////////////////////////////////////////////// void MPROC_NotifyReceivedEvnt( unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam { // a note event provides 128 different note values (0..127) // in this simple example, each note sets an individual pin // for DOUT pin numbers, see also this documentation: // http://www.ucapps.de/mios/mios_pin_list.txt if( evnt0 == 0x80 || evnt0 == 0x90 ) { // 90 xx 00 is the same like a note off event! // (-> http://www.borg.com/~jglatt/tech/midispec.htm) if( evnt0 == 0x80 || evnt2 == 0x00 ) { // Note Off MIOS_DOUT_PinSet(pin, 0); } else { // Note On MIOS_DOUT_PinSet(pin, 1); } } } I get main.c:83: error 20: Undefined identifier 'pin'main.c:83: error 20: Undefined identifier 'pin'main.c:88: error 20: Undefined identifier 'pin'main.c:88: error 20: Undefined identifier 'pin'Thanks Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 22, 2007 Report Share Posted May 22, 2007 Wel that'll be because it's not defined.This is the same answer that you have been given before in this thread and that you saw in the other thread.Use evnt1 like instructed before, or try this: ///////////////////////////////////////////////////////////////////////////// // This function is called by MIOS when a complete MIDI event has been received ///////////////////////////////////////////////////////////////////////////// void MPROC_NotifyReceivedEvnt( unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam { unsigned char pin; pin = evnt1; // a note event provides 128 different note values (0..127) // in this simple example, each note sets an individual pin // for DOUT pin numbers, see also this documentation: // http://www.ucapps.de/mios/mios_pin_list.txt if( evnt0 == 0x80 || evnt0 == 0x90 ) { // 90 xx 00 is the same like a note off event! // (-> http://www.borg.com/~jglatt/tech/midispec.htm) if( evnt0 == 0x80 || evnt2 == 0x00 ) { // Note Off MIOS_DOUT_PinSet(pin, 0); } else { // Note On MIOS_DOUT_PinSet(pin, 1); } } } I would also recommend that you read The C Book, you can find it with a search of the forums here. Quote Link to comment Share on other sites More sharing options...
DavidBanner Posted May 22, 2007 Report Share Posted May 22, 2007 Stryd,is the new SDCC release allowing you declare vars properly now, rather than just at the top? Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 22, 2007 Author Report Share Posted May 22, 2007 THANKS stryd_one... I got something working at last!!!!!Now the led's are following the velocity setting. Now I need to set them to turn off and not stay ON.I will do as you're suggesting and read more in detail.Somehow my final project is to connect 12 cores with 128leds each at a distance between them so that I could fire a show. You think that's possible? THANKS, thanks Quote Link to comment Share on other sites More sharing options...
stryd_one Posted May 22, 2007 Report Share Posted May 22, 2007 Wicked :) If it works for velocity, then it will be using evnt2, so just replace that with for evnt1, and it will be using the note number :)Dave: Nope :( I'm still wanting to find time to try --extended ;) ... and find a version of the doc old enough to tell me what --fstack was before they removed it hehehe Quote Link to comment Share on other sites More sharing options...
MTE Posted May 22, 2007 Report Share Posted May 22, 2007 Can you post your working Code here ?Im very interested in it :)Regards Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 22, 2007 Author Report Share Posted May 22, 2007 My DOUT is wired to core J8, correct?tried evnt0, evnt1, evnt2 but all i can get is velocity to trigger led'sThis code turns ON led 0 and OFF // a note event provides 128 different note values (0..127) // in this simple example, each note sets an individual pin // for DOUT pin numbers, see also this documentation: // http://www.ucapps.de/mios/mios_pin_list.txt if( evnt0 == 0x80 || evnt0 == 0x90 ) { // 90 xx 00 is the same like a note off event! // (-> http://www.borg.com/~jglatt/tech/midispec.htm) if( evnt0 == 0x80 || evnt2 == 0x00 ) { // Note Off MIOS_DOUT_PinSet0(evnt0); } else { // Note On MIOS_DOUT_PinSet1(evnt0); } } } and this turns ON but never OFF the corresponding led with velocity... // Note Off MIOS_DOUT_PinSet0(evnt2); } else { // Note On MIOS_DOUT_PinSet1(evnt2); Quote Link to comment Share on other sites More sharing options...
DavidBanner Posted May 22, 2007 Report Share Posted May 22, 2007 this is getting painful - please go and read up on Cthe way to use the function is thus:MIOS_DOUT_PinSet(pin, 0);have a look at your code - if you can't work out why it's not working I can't help you, you simply need to learn more about C or one of us is gonna end up coding your app for you, one line at a time Quote Link to comment Share on other sites More sharing options...
Jidis Posted May 22, 2007 Report Share Posted May 22, 2007 Dizzu,You should look further into the MIDI note formatting and where MIOS stores the different parts when it receives a note event (pretty well documented in TK's apps). There's a decent description about halfway down the page here:http://www.mibac.com/Pages/MIDIReference.htmlThe three bytes you'll likely be interested in will get dumped into evnt0,evnt1, and evnt2. The first will be the status, which should be a hexadecimal 9x or 8x for note on and off, where "x" is the channel number, 0-15 (0toF hex) for the 16 MIDI channels. As Thorsten has noted, sometimes a note-off will be handled by a note "on" message with a velocity value of zero (9x xx 00). So with evnt0 being passed to the pinset call, you'll effectively be trying to activate some pin way up in the #150 range (hex 90 = dec 144), and probably the same pin each time, even if the note number changes (don't know how the app handles something out of DOUT range).The part of the message you probably want to send to the DOUT call will be the second byte (evnt1), which holds the incoming note number. Not sure what range you'll be working with, but by default, I guess they'll be triggered by notes 00 and up (pretty low). You may need to subtract something from that evnt1 argument when you use it, if you can't alter the notes you're sending the box.Also, make sure you incorporate something to turn 'off' the lights, or they'll stay on forever. For instance: if( evnt0 == 0x80 || evnt2 == 0x00 ) MIOS_DOUT_PinSet0(evnt1);should take anything that's a "note off" or "note on with a velocity (3rd byte/evnt2) of zero" and trigger a DOUT "off" message mapping the incoming note# to the pin you want to disable.Hope that helps, :)George (fellow C newbie) -- BTW, if you haven't already noticed, there's also the call David mentioned, where you specify pin on/off with the second argument you pass to it. I guess either way is OK. Quote Link to comment Share on other sites More sharing options...
dizzu Posted May 23, 2007 Author Report Share Posted May 23, 2007 Yes I am reading some tutorials now.I am testing notes from midi keyboard on MIOS Studio. Till now only with velocity I managed to trigger led's.I ask a question; My final project is to build a 12 core system all with different addresses (electronic pyro firing system), so that I can use/write a software that will send specified notes from a cue list so that I turn on for ex: led 13 on core address 6; at least that's what I intend to do.Do you think midi is the way, or is there a more reliable protocol?Thanks Quote Link to comment Share on other sites More sharing options...
DavidBanner Posted May 23, 2007 Report Share Posted May 23, 2007 oooops - I just reread your question and the functions list - my apologies, I completely missed the MIOS_DOUT_PinSet0 funciton - my bad, I shouldn't assume...so that I can use/write a software that will send specified notes from a cue list so that I turn on for ex: led 13 on core address 6; at least that's what I intend to do.Do you think midi is the way, or is there a more reliable protocol?1st question - why midi? I.e. are you going to sync to a performance that is running midi anyway, like a band or PA so you can trigger the pyros on say for instance a drum roll?if not, then i'd say DMX might be a better way to go, as you can intergrate with the lighting desk and there are lots of cool lighting programs around. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.