This is my code for 12 button midi with 2 extra buttons for octave Up and Down. the code compiles well but when i upload the code to my board the TX led lights up and gives random signals to my daw. i am struck here guys Help!
The pin 14 and 15 stamds for analog A0 and A1. I read this over this forum. I been searching for Answers from a long time. I need to know where am I going wrong. And if anyone spots any mistake do point it out. Help appreciated
So what should be a correct way to make this code work. If the oct up is pressed once it should C5 to C6 and if you press it again C6 to C7. No I am not ignoring anyone I am new to this programming though but thought to try something out maybe. By the way Thanks for your response. But do let me know how can I write this code.
GKA:
So what should be a correct way to make this code work. If the oct up is pressed once it should C5 to C6 and if you press it again C6 to C7. No I am not ignoring anyone I am new to this programming though but thought to try something out maybe. By the way Thanks for your response. But do let me know how can I write this code.
If we say something you don't understand then ask. We'd like you to learn something. If we just give you working code all you will have learned is that you can get away without bothering to learn how to write your own programs.
You need to define the PINS used for the two octave buttons.
Currently you are adding 12 to MIDI note only if the octave button is being held on at the exact time that the message is sent. What you need to do is remember (in a variable) when each button is pressed and how often they have been pressed to decide what the offset is i.e. +12 for C5, +24 for C6, 0 for C4 (MIDI note 60 = C4) etc.
When you've done those we can look at the rest of it.
Yeah just guide me. I will definitely try my best. Slipstick what u mean to say is I need to define the pins right. so my question is do I need to change the arrary of 13 ? Is digitalread is good idea for analog pins? Because I am connecting a button to pin A0 and the other end to gnd.
Is digitalread is good idea for analog pins? Because I am connecting a button to pin A0 and the other end to gnd.
A0 is the name of the first analog pin being used as a digital pin. The pin is NOT being used as an analog pin.
So, are octaveUp and octaveDown pin numbers or pin states? If they are pin numbers, they need default values other than false. If they are pin states, they do not get used in pinMode() calls.
Actually the definition of octaveUp and down is like this I made a mistake there. And as u said paul the A0 is same as digital pin. So the ocatve variable can be assigned the different value as other languages right.
Incidentally why are you reading pins in setup() - that's for setup, not actually running of the sketch,
so keep the pinMode calls there and do the pin reads from loop() or a function that loop() calls.
I mean the conditions I wrote in code are they correct??
No. You need to post your code again, after using Tools + Auto Format, so we can see that you understand the difference between pin numbers and pin states.
Variables that are of type boolean should be used to hold true or false. HIGH and LOW values should be stored in variables of type byte or uint8_t.
It really does not make sense to put the { on the same line as the function and/or statement, to save real estate, and then put all those blank lines in the function.
Put blank lines BETWEEN functions. Put every { on a line BY ITSELF. Put every } on a line BY ITSELF.
#define octaveUp 14
if (octaveUp == HIGH){
I'm reasonably confident that 14 is NOT equal to HIGH, and never will be. I'm pretty sure that 15 is not HIGH, either.
Now, can you see why we recommend that you use Pin in the name of all variables (or constants) that hold pin numbers?
Why is that Soo Paul. What I changes I made to codes are I define the octave up and down to 14 and 15 and I removed the digitalread from the setup() and wrote the condition like this
If (digitalRead(octaveUp)==HIGH){
And compiled it and it do get compiled and when I try to upload code to board the TX light up constantly so what it seems like it the signal are generated infinitely because somewhere the code is wrong maybe the for loop as u said or the condition
So, you made some code changes, without posting the new code. It does something, but that something is not what you want, but we don't know what either one of the things are.
How ARE the octave up and octave down switches wired? Why are those pins INPUT, while the bts pins are INPUT_PULLUP?
It sounds like you might be having floating pin problems.