Pages: [1]   Go Down
Author Topic: Talk MIDI command  (Read 638 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to have a switch trigger notes that will be produced by a wave shield and then have a servo move about 20 degrees..... i have a code and have gotten my music code to work and the switch and servo to work... but I can't seem to get the switch to trigger the music... can anyone help?
 this is my code thus far


#include <SoftwareSerial.h>



#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3);

#include <Servo.h>

 Servo myservo;



byte note = 0;
byte resetMIDI = 4;
int SwitchPin = 0; //switchpin on pin 7
int pos = 70;
int instrument = 0;
int LedPin = 13;



void setup()
{
 pinMode(SwitchPin, INPUT);
 pinMode(LedPin, OUTPUT);
 myservo.attach(9);

 Serial.begin(57600);
 mySerial.begin(31250);

 pinMode(resetMIDI,OUTPUT);
 digitalWrite(resetMIDI, LOW);
 delay(100);
 digitalWrite(resetMIDI, HIGH);
 delay(100);
 talkMIDI(0xB0,0x07,120);
 }


void loop()
{
 SwitchPin=digitalRead(7); //read pin 7
 myservo.write(pos); //puts servo to position 70 degrees
 delay(5);
 pos=constrain(pos,0,180);



if(SwitchPin==1)

{
  delay(500);
 //Serial.printIn(instrument,"Demo Fancy Sounds");
 talkMIDI(0xB0, 71, 0x79);
 Serial.print("Instrument:");
 //Serial.printIn(instrument, DEC);
 
 talkMIDI(0xC0, 71, 0);
 
 noteOn(0, 50, 60);
 delay(200);
 noteOff(0, 50, 60);
 delay(100);
 
 noteOn(0, 53, 60);
 delay(200);
 noteOff(0, 53, 60);
 delay(100);
 
 noteOn(0, 52, 60);
 delay(400);
 noteOff(0, 52, 60);
 delay(100);
 
 noteOn(0, 53, 60);
 delay(400);
 noteOff(0, 53, 60);
 delay(100);
 
  noteOn(0, 55, 60);
 delay(400);
 noteOff(0, 55, 60);
 delay(200);
 
  noteOn(0, 58, 60);
 delay(300);
 noteOff(0, 53, 60);
 delay(100);
}

myservo.write(pos=90);
}
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) {
  digitalWrite(LedPin, HIGH);
  mySerial.write(cmd);
  mySerial.write(data1);
}
 
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How to use this forum


Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1258
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you expect it to do and what is it doing that does not work?
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
//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) {
  digitalWrite(LedPin, HIGH);
  mySerial.write(cmd);
  mySerial.write(data1);
}

You are not doing anything with data2.

Code:
//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) {
  digitalWrite(LedPin, HIGH);
  mySerial.write(cmd);
  mySerial.write(data1);
  mySerial.write(data2);
}
Logged

Pages: [1]   Go Up
Jump to: