Go Down

Topic: Midi Footcontroller switch problem (Read 8294 times) previous topic - next topic

Grumpy_Mike


gregchill


Grumpy_Mike

So why did you clear out the bit where something could be done?

As it is I can't see where this extra switch is and how it get activated.

gregchill

oh i thought by putting a new switch in with a different name and it own individual switch state it would work, but your saying i was on the right track to start with. the new switch entry is up with the include statements and the switch activation is at the end of the void loop but to be honest i'm not sure if this is right.

Grumpy_Mike

Quote
oh i thought by putting a new switch in with a different name and it own individual switch state it would work,
Yes but you have to do three things:-
1) Read the switch in that convoluted background task / debounce function.
2) Detect the switch has been changed.
3) Action those changes.

Quote
your saying i was on the right track to start with.
From what I saw yes. I had assumed that you were doing 1) but I didn't check. I saw you were doing 2) and I saw what you were doing for 3) and it was wrong.

gregchill

I have put a int buttonstate = 0 at the top of the sketch and the following code in
Code: [Select]
if (ButId == S3){ buttonState = digitalRead(S3);
  if (buttonState == HIGH); {
  sendControlChange(89, 127);
}

  if (buttonState == LOW);{

  sendControlChange(89, 0);
  }


But i cant manage to get an else statement in there. so far it compiles and debugs as working but it only switches off the effect and flickers as if its turning it back on.

Grumpy_Mike

#36
Jan 28, 2016, 03:05 pm Last Edit: Jan 28, 2016, 07:25 pm by Grumpy_Mike
You need to post all of that function at least so we can see the context.

Now that code you did post. Why test twice? If the button state is not high then it is low, there is no need to test for it so just use an else:-
Code: [Select]

if (ButId == S3){
  buttonState = digitalRead(S3);
  if (buttonState == HIGH) {
  sendControlChange(89, 127);
}
  else {
  sendControlChange(89, 0);
  }


You had a colon after the if low statement so that means it will do nothing.

Quote
But i cant manage to get an else statement in there.
Yes you had a colon after the if:-
Code: [Select]
if (buttonState == LOW);{
and when this wasn't followed by an else the if is finished, so putting an else in later confuses the compiler because it is not in a conditional if.

gregchill

Thanks for that

The else statement still wont compile i don,t know what im doing wrong
Code: [Select]

if (ButId == S3){
  buttonState = digitalRead(S3);
  if (buttonState == HIGH); {
  sendControlChange(89, 127);
}
  else {
  sendControlChange(89, 0);
  }
even when i copy and paste it.

Grumpy_Mike

#38
Jan 28, 2016, 07:24 pm Last Edit: Jan 28, 2016, 07:26 pm by Grumpy_Mike
You are STILL putting a ; on the end of  your if statement !

You are still not posting all your function.

gregchill

 :) Cheeers Mike that worked. Thanks for all the help (again)

Greg

gregchill

i have put 4 buttons to send midi cc messages but ran out of i/o on the nano can you recommend the best way to get around this, which would be better.

Put a resistor tree into one of the audio pins is it possible to transfer midi cc messages this way. or hook up a shift register and put the leds on that, or put the extra butttons on the shift register.
I got a Teensy 3.2 for the extra pins but this code has incompatibility with it.

Grumpy_Mike

Quote
I got a Teensy 3.2 for the extra pins but this code has incompatibility with it.
I find that odd, why?

The simplest way would be to use resistors and an analogue input.

gregchill

Hi Mike,

with the Teensy i haven't managed to get the midi working yet even though i have changed the midi send to Serial1 it changes the display normally.
The bank down selection goes from something mad like five million down to one instead of 16 back to 1, and the internal menu only lets you select options as far as bankmax then it freezes and has to be rebooted.All these worked fine with the nano.

Grumpy_Mike

That doesn't sound right. While the tinsy is a lot faster it should work in exactly the same way. Can you post the code that is fine on a nano but doesn't work on the teensy.

gregchill

Hi Mike,

Teensy stopped working last night (think it fried) so its back to the Nano.

Can you recommend a tutorial for detecting a button press on a two resistors into an analog input to send a midi cc value?
i have a piece of code  i am working that on and i know to to analog read the resistors and put them in if and if else statements ,when it comes to sending the midi its transmitting(TX) a low value all the time, is there a way to only send a cc message when a button press is detected.

Go Up