Show Posts
Pages: [1]
1  Using Arduino / Audio / Re: ARDUINO + musical instrument shield to make a Keyboard on: October 29, 2012, 03:41:51 pm
MusicInstrument_Keyboard --   No more Errors

Wow! Thank you very much for all of your suggestions.
The program is finally verified and the program is running with  beautiful sounds.

As "note" is also an array, there should has been a suffix.
I did not notice it.
Once again, thank you very much.

Now I'm trying to make an infrared keyboards.
About 6 Infrared beams(38KHz) are emitted and if a peson blocks a beam, the receiver gives a 5V voltage.
This is the signal for the "inputPins" of this "ARDUINO + musical instrument shield."

I'll post within a few days.

Thank you.
2  Using Arduino / Audio / Re: ARDUINO + musical instrument shield to make a Keyboard on: October 27, 2012, 07:59:22 pm
MusicIntrument_Keyboard Errors

Thank you very much for your comments.

Your suggestion such as declaration of "byte note[ ]" seemed reasonable.
However, there still exist errors.



The line
  noteOn(0,note,100);
is still highlighted and there are messages as
"  invalid conversion from 'byte' to 'byte'   "
"  initializing argument 2 of void 'noteOn(byte,byte,byte)'   "


The full code is as follows.

Code:
//Music Instrument Shield_Keyboard  renew
//MusicIntrument_Keyboard
// Music Instrument Shield_Keyboard

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code

byte inputPins[] = {5,6,7,8,9,10,11,12,13};
byte note[]={72,74,76,77,79,81,83,84,86};
int pinCount = 9;

int buttonState[9];
int lastButtonState[9]; 

byte resetMIDI = 4; //Tied to VS1053 Reset line
int instrument = 13;

void setup() {

  //Setup soft serial for MIDI control
  mySerial.begin(31250);
 
  for(int i=0; i<pinCount; i++){
  pinMode(inputPins[i], OUTPUT);//pinMode(outputPins, OUTPUT);
  digitalWrite(inputPins[i], LOW);// this enables the pull up resistors to reduce noise
  pinMode(inputPins[i], INPUT);
  }


  //Reset the VS1053
  digitalWrite(resetMIDI, LOW);
  delay(100);
  digitalWrite(resetMIDI, HIGH);
  delay(100);
 
  talkMIDI(0xB0, 0x07, 126); //0xB0 is channel message, set channel volume to near max (127)
  talkMIDI(0xB0, 0, 0x79); //Default bank GM1
  talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command

}

void loop() {
 
for (int i=0; i<pinCount; i++){

  buttonState[i] = digitalRead(inputPins[i]);
  delay(1);
 
  if (buttonState[i] != lastButtonState[i]) {       
   
    if (buttonState[i] == HIGH) {                     
    noteOn(0,note,100);                     
    }
   
  }

  lastButtonState[i] = buttonState[i];
 
  }
}

//Send a MIDI note-on message.  Like Pressing a piano key
void noteOn(byte channel, byte note, byte attack_velocity) {
  talkMIDI( (0x90 | channel), note, attack_velocity);
}

//Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte release_velocity) {
  talkMIDI( (0x80 | channel), note, release_velocity);
}

//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2) {
  mySerial.write(cmd);
  mySerial.write(data1);

  //Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes
  //(sort of: http://253.ccarh.org/handout/midiprotocol/)
  if( (cmd & 0xF0) <= 0xB0)
    mySerial.write(data2);

}




It seems difficult but welcomes any suggestions.
3  Using Arduino / Audio / Re: ARDUINO + musical instrument shield to make a Keyboard on: October 26, 2012, 07:52:32 pm
MusicIntrument_Keyboard Errors

Sorry!

I pasted this topic's first contributer's ( Plankton's ) code and added array suffixes to "inputsPins" ,"buttonState"  "lastButtonState"

The full code is as follows.

Code:
//Music Instrument Shield_Keyboard  renew
//MusicIntrument_Keyboard
// Music Instrument Shield_Keyboard

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code

int inputPins[] = {5,6,7,8,9,10,11,12,13};
int note[]={72,74,76,77,79,81,83,84,86};
int pinCount = 9;

int buttonState[9];
int lastButtonState[9]; 

byte resetMIDI = 4; //Tied to VS1053 Reset line
int instrument = 13;

void setup() {

  //Setup soft serial for MIDI control
  mySerial.begin(31250);
 
  for(int i=0; i<pinCount; i++){
  pinMode(inputPins[i], OUTPUT);//pinMode(outputPins, OUTPUT);
  digitalWrite(inputPins[i], LOW);// this enables the pull up resistors to reduce noise
  pinMode(inputPins[i], INPUT);
  }


  //Reset the VS1053
  digitalWrite(resetMIDI, LOW);
  delay(100);
  digitalWrite(resetMIDI, HIGH);
  delay(100);
 
  talkMIDI(0xB0, 0x07, 126); //0xB0 is channel message, set channel volume to near max (127)
  talkMIDI(0xB0, 0, 0x79); //Default bank GM1
  talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command

}

void loop() {
 
for (int i=0; i<pinCount; i++){

  buttonState[i] = digitalRead(inputPins[i]);
  delay(1);
 
  if (buttonState[i] != lastButtonState[i]) {       
   
    if (buttonState[i] == HIGH) {                     
    noteOn(0,note,100);                     
    }
   
  }

  lastButtonState[i] = buttonState[i];
 
  }
}

//Send a MIDI note-on message.  Like Pressing a piano key
void noteOn(byte channel, byte note, byte attack_velocity) {
  talkMIDI( (0x90 | channel), note, attack_velocity);
}

//Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte release_velocity) {
  talkMIDI( (0x80 | channel), note, release_velocity);
}

//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2) {
  mySerial.write(cmd);
  mySerial.write(data1);

  //Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes
  //(sort of: http://253.ccarh.org/handout/midiprotocol/)
  if( (cmd & 0xF0) <= 0xB0)
    mySerial.write(data2);

}




Thank you very much for your comments and am looking forward to them.
4  Using Arduino / Audio / Re: ARDUINO + musical instrument shield to make a Keyboard on: October 25, 2012, 08:00:48 pm
This is a re-post with a code tag.
This time is the first time to use code tags. If I'm wrong, please tell me.

MusicIntrument_Keyboard Errors
Thank you very much for your comment.

I replaced "inputsPins" ,"buttonState"  "lastButtonState" as follows.

Code:
inputPins[i]
Code:
buttonState[i]
Code:
lastButtonState[i]

The number of errors has decreased.
But still there are 3 error messages.


For example,
In the void loop()

Code:
    if (buttonState[i] == HIGH) {                     
    noteOn(0,note,100);

The line
  noteOn(0,note,100);
is highlighted and there are messages as
"  invalid conversion from 'int' to 'byte'   "
"  initializing argument 2 of 'noteOn(byte,byte,byte)'   "

In my understanding, talkMIDI() is a message with 3 bytes.
How do you define the data type of noteOn()?

I feel I'm getting better with your help.

I'm looking forward your reply.
Thank you very much.
5  Using Arduino / Audio / Re: ARDUINO + musical instrument shield to make a Keyboard on: October 24, 2012, 10:45:19 am
Very sorry.  I could not understand how to use the code tag,  # on the menu.
I'll post in a day.
6  Using Arduino / Audio / Re: ARDUINO + musical instrument shield to make a Keyboard on: October 23, 2012, 09:10:28 pm
Thank you very much for your comment.
I replaced inputsPins with  inputsPins.

The number of errors has decreased.
But still there were 6 error messages as I post the image-1 here.

For example,
In the void loop()

The line
  buttonState = digitalRead(inputPins);
is highlighted and there's a message as
"  incompatible types in assignment of 'int' to 'int[9]'   "


So I also added      to all "buttonState" and "lastButtonState"


The number of errors has decreased further.
But still there were 3 error messages as I post the image-2 here.

For example,
In the void loop()

    if (buttonState == HIGH) {                     
    noteOn(0,note,100);

The line
  noteOn(0,note,100);
is highlighted and there's a message as
"  invalid conversion from 'int' to 'byte'   "

In my understanding, talkMIDI() is a message with 3 bytes.
How do you define the data type of noteOn()?

I feel I'm getting better with your help.

I'm looking forward your reply.
Thank you very much.
7  Using Arduino / Audio / Re: ARDUINO + musical instrument shield to make a Keyboard on: October 22, 2012, 07:58:41 pm
MusicIntrument_Keyboard_Error

Hello.
Thank you very much for posting your Arduino Music Instrument_Keyboard.
I pasted your program on Arduino 1.01 and verified it.

Then I get lots of error messages as I post the image here.

For example,
In the void setup() 
The line
"  pinMode(inputPins, OUTPUT);//pinMode(outputPins, OUTPUT);  "
is highlighted and there's a message as
"  invalid conversion from 'int*' to 'uint8_t'  "


I cannot understand the error messages, because your code seems ok.
If I click "Upload" button, the result is the same.

What is wrong?
I'm looking forward your reply.

P.S.
The title name of the file is "MusicIntrument_Keyboard.ino"
I use Arduino Uno R2 and I use Windows XP.
Board and Serial port( Com4 ) is correctly setup on Arduino 1.01.
Pages: [1]