ranger930 Posted March 25 Report Posted March 25 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 Quote
jrp Posted May 15 Report Posted May 15 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; } Quote
ranger930 Posted May 23 Author Report Posted May 23 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 Quote
jrp Posted May 26 Report Posted May 26 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. Quote
jrp Posted May 26 Report Posted May 26 s32 MIOS32_DIN_PinGet (u32 pin) With this function you gen poll the state of a din pin, eg when using switches in your setup. Quote
jrp Posted May 26 Report Posted May 26 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. Quote
jrp Posted May 27 Report Posted May 27 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)); } } } Quote
ranger930 Posted May 27 Author Report Posted May 27 thank you for your numerous answers, i will try to get it right when i find the time, br ranger930 Quote
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.