Jump to content

Recommended Posts

Posted

good evening everyone,

after switching on my stm32f4 board, I would like to query all inputs ( DIN and AIN ) once under mios32 and send the values obtained once via midi in order to update my software ( Traktor ). 

Unfortunately I have no idea where I have to insert the necessary code e.g. in NG or midio128, querying buttons and pots already works so far, can someone please enlighten me, thanks for your support,

 

greetings ranger930

 

  • 1 month later...
Posted

i am also wondering about running a function once. I was under the impression that this could be done within the init function, but that does not seem to work.

What does work (please tell us if this is not the way to do this) is defining a variable like:

 

u8 has_run = 0;

 

then in the background task you can check for has run == 0, do your stuff, set has_run to something different than 0. Your code inside the if statement will never run again... 

 

if (has_run==0){

 

do everything you want;

has_run = 1;

}

 

 

  • 2 weeks later...
Posted

I would like to ask my question more specifically:

How can I get Mios to start the program sequence with which all inputs ( analog and digital ) are read ( without having pressed a button or turned a potentiometer ) ?

This is only necessary once after the program start.

Where should I insert a program code?

I have already searched the entire forum and the repository for help, but have found nothing. Please help me.

I have a test setup with buttons, potentiometers and LEDs and the respective inputs are read after pressing a button or turning a potentiometer.

Mfg ranger930

Posted

The thing is: With all digital inputs you cannot get any state UNLESS a button is pressed. It would be different with actual switches that hold their state low or high.

But a button or encoder has no permanent state. When you press or turn it you get a pulse that will trigger the mios callback routine. Thats it.

 

So the direction you should be looking is to save the last state of all buttons and encoders in your code, and load it on startup.

 

Unfortunately i am still a noob, so i cannot really tell you how to do that.

But there is some example code for sd cards and bancsticks. 

Posted

it´s in the manual under din

 

http://midibox.org/mios32/manual/

 

I cannot try this right now, but i would assume something like

 

int my_button = MIOS32_DIN-PinGet(0);

 

will save 1 or 0 to the variable my_button.

But again, if you have a normal "digital" push button this will only work while the button is actually pressed.

Posted

i jst saw that tk answered the same question regarding mios8. The same should apply here.

It works alsmost like the code i suggested above, with one big difference: I was suggesting a global variable. That does work, but is usually a good idea to avoid.

The neat thing i just learned, and since we are both learning i like to share this::

What is a static variable? It is a variable that will be created once and not change over function calls.

So if the code below would read "unsigned char ain_sent = 0;" without the static keyword, the variable would be recreated every tick and midi would be sent every ms.

With static, this variable will be created once inside the function block (so it is not polluting the global namespace). Next time it will be 1 and the condition in the if statement will fail.

 

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS in the mainloop when nothing else is to do
/////////////////////////////////////////////////////////////////////////////
void Tick(void) __wparam
{
  static unsigned char ain_sent = 0;

  if( ain_sent == 0 ) {
    unsigned char pin;
    unsigned char num_ain = MIOS_AIN_NumberGet();

    ain_sent = 1; // only sent once after startup

    for(pin=0; pin < num_ain; ++pin) {
      MIOS_MIDI_TxBufferPut(0xb0); // CC at channel 1
      MIOS_MIDI_TxBufferPut(pin);  // pin number corresponds to CC number
      MIOS_MIDI_TxBufferPut(MIOS_AIN_Pin7bitGet(pin));
    }
  }
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...