Analog midi instrument

Hello, the whole society !!!

I plan to build a midi instrument based on the Teensy 2.0 board.
Assumptions:
Six analog inputs and eighteen digital ones.
All inputs are to send midi notes.
Analog inputs: 1-6 velocity notes depending on the potentiometer setting
Digital inputs: notes 7-24

In the examples I found, there is no one that changes the velocity of the notes analog :frowning:

I found only an example of the digital input of a note with constant vleocity and it works well:

int pin [10] = {0,1,2,3,4,5,6,7,8,9};
int on [10];
int flag [10] = {0.0,0,0,0,0,0,0,0,0};
int i = 0;

void setup ()
{for (int a = 0; a <10; a ++) {
digitalWrite (pin [a] HIGH)};

}
void loop ()
{
  on [i] =! digitalRead (pin [i]);
  if (on [i] == 1 && flag [i] == 0)
  {
    usbMIDI.sendNoteOn (7 + i, 127.1);
    flag [i] = 1;
}
else if (on [i] == 0 && flag [i] == 1)
{
usbMIDI.sendNoteOff (7 + i, 127.1);
flag [i] = 0;
}
if (and <9)
{
i = i + 1;
}
else {i = 0};
}

Will anyone help in programming the project?

Try reposting the code in </> code tags so it’s not in italics.

How do you expect the analog inputs to work? If the analog level controls the velocity when do you decide to send a NoteOn with that velocity? Every time the input changes? By how much? Or what?

Steve

I found only an example of the digital input of a note with constant vleocity and it works well:

Not that code I hope. Their is lots wrong with what you posted. Basically it uses pins 0&1 which should be left for the serial communications. You should be using the pinMode statement in the setup function to enable the internal pull ups.
Notes 7 to 24 are way too low for most MIDI sound generators, and you have no include statements to pull in the libiary.

And that is just for a start.

Grumpy_Mike:
Not that code I hope. Their is lots wrong with what you posted. Basically it uses pins 0&1 which should be left for the serial communications. You should be using the pinMode statement in the setup function to enable the internal pull ups.
Notes 7 to 24 are way too low for most MIDI sound generators, and you have no include statements to pull in the libiary.

And that is just for a start.

I've uploaded this code to teensy 2.0 and it works
The buttons connect the next pins to ground

GND B0 B1 B2 ...

\ \ \
![

slipstick:
Try reposting the code in </> code tags so it’s not in italics.

How do you expect the analog inputs to work? If the analog level controls the velocity when do you decide to send a NoteOn with that velocity? Every time the input changes? By how much? Or what?

Steve

I want the first analog input to send a note (any, because the program I use accepts even as low notes as 1, but can be any)
If fader 1-6 is in the “zero” position, a NoteOff signal is sent.
When I raise the fader above the threshold, it will switch to NoteOn and will change the velocity of this note linearly from 0 to 127.

Digital inputs - simply:
open - NoteOff
closed - NoteOn and holds
released - NoteOff

Does this explain my intentions?

I’ve uploaded this code to teensy 2.0 and it works

Liar!

No it doesn’t, it does not even compile!

digitalWrite (pin [a] HIGH)};

Gives the error:-

Forum_midi: In function 'void setup()':
/Applications/Arduino Old/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy/core_pins.h:24:14: error: expected ')' before numeric constant
 #define HIGH 0x1
              ^
/Users/mikecook/Desktop/Forum_midi/Forum_midi.ino:9:23: note: in expansion of macro 'HIGH'
 digitalWrite (pin [a] HIGH)};
                       ^
Forum_midi:9: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
 digitalWrite (pin [a] HIGH)};
                           ^

The error message continues to say

Forum_midi:17: error: 'usbMIDI' was not declared in this scope
To make a USB MIDI device, use the Tools > USB Type menu
     usbMIDI.sendNoteOn (7 + i, 127.1);
     ^
Forum_midi:22: error: 'usbMIDI' was not declared in this scope
To make a USB MIDI device, use the Tools > USB Type menu
 usbMIDI.sendNoteOff (7 + i, 127.1);
 ^
Forum_midi:25: error: expected identifier before '<' token
 if (and <9)
         ^
Forum_midi:29: error: expected ';' before '}' token
 else {i = 0};
            ^
too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'

Now if you can’t be trusted to tell the truth how can you expect anyone to help you?

Does this explain my intentions?

From where I sit your intentions is to jerk us about.

:frowning:

int pin[10]={0,1,2,3,4,5,6,7,8,9};
int on[10];
int flag[10]={0,0,0,0,0,0,0,0,0,0};
int i=0;

void setup()
{ for(int a=0;a<10;a++){
digitalWrite(pin[a],HIGH);}

}
void loop()
{
  on[i] = !digitalRead(pin[i]);
  if(on[i]==1 && flag[i]==0)
  {
    usbMIDI.sendNoteOn(1+i,127,1);
    flag[i]=1;
}
else if(on[i]==0 && flag[i]==1)
{
usbMIDI.sendNoteOff(1+i,127,1);
flag[i]=0;
}
if (i<9)
{
i=i+1;
}
else{i=0;}
}

Grumpy_Mike:
Liar!

No it doesn’t, it does not even compile!

digitalWrite (pin [a] HIGH)};

Gives the error:-

digitalWrite(pin[a],HIGH);}

Forum_midi: In function 'void setup()':

/Applications/Arduino Old/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy/core_pins.h:24:14: error: expected ‘)’ before numeric constant
#define HIGH 0x1
             ^
/Users/mikecook/Desktop/Forum_midi/Forum_midi.ino:9:23: note: in expansion of macro ‘HIGH’
digitalWrite (pin [a] HIGH)};
                      ^
Forum_midi:9: error: too few arguments to function ‘void digitalWrite(uint8_t, uint8_t)’
digitalWrite (pin [a] HIGH)};
                          ^
digitalWrite(pin[a],HIGH);}




The error message continues to say


Forum_midi:17: error: ‘usbMIDI’ was not declared in this scope
To make a USB MIDI device, use the Tools > USB Type menu
    usbMIDI.sendNoteOn (7 + i, 127.1);
    ^
Forum_midi:22: error: ‘usbMIDI’ was not declared in this scope
To make a USB MIDI device, use the Tools > USB Type menu
usbMIDI.sendNoteOff (7 + i, 127.1);
^
Forum_midi:25: error: expected identifier before ‘<’ token
if (and <9)
        ^
Forum_midi:29: error: expected ‘;’ before ‘}’ token
else {i = 0};
           ^
too few arguments to function ‘void digitalWrite(uint8_t, uint8_t)’




usbMIDI.sendNoteOff(1+i,127,1);

Now if you can't be trusted to tell the truth how can you expect anyone to help you?
From where I sit your intentions is to jerk us about.

no comma …
error when copying and pasting on the forum is not a LIE

error when copying and pasting on the forum is not a LIE

I fail to see how:-

  1. Select all the code in the IDE
  2. Press the copy key combination
  3. Click on the code icon in the Forum's web site
  4. Pressing the post key combination

Can result in not only a missing comma, but all that nonsense with the "if" statement

I also notice that you have changed the code in the original post to make it look like I am the lyer. This is a blatant disregard for the forum rules, which tells you what you are permitted to do to a first post in a thread.

Read them some time How to use this forum preferably before you post again on this forum.

Grumpy_Mike:
I also notice that you have changed the code in the original post to make it look like I am the lyer. This is a blatant disregard for the forum rules, which tells you what you are permitted to do to a first post in a thread.

I have edited the post only to place the code in the table.
I did not change the code from the first post.
The copied code has been changed by the Google translator.

The copied code has been changed by the Google translator.

You put code through google translate!!?