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,
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…
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.
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.
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)); } } }