Hi
I am new to Arduino and I need some help with a project of piano.
I am using instrument music shield and arduino bord and I want to make simple 8 key piano for special need school. I have all components and some basic code with is not working. No errors but no sound to.
Sorce code :
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code
byte note = 0; //The MIDI note value to be played
byte resetMIDI = 4; //Tied to VS1053 Reset line
byte ledPin = 13; //MIDI traffic indicator
int instrument = 0;
const int buttonPin = 7; //pushbutton @ pin 7
const int buttonPin2 = 8; //pushbutton2 @ pin 8
const int buttonPin3 = 9; //pushbutton3 @ pin 9
const int buttonPin4 = 10; //pushbutton4 @ pin 10
//variables will change:
int buttonState = 0; //variable for reading the pushbutton status
int buttonState2 = 0; //variable for reading the pushbutton2 status
int buttonState3 = 0; //variable for reading the pushbutton3 status
int buttonState4 = 0; //variable for reading the pushbutton4 status
void setup() {
//Setup soft serial for me serial monitor (useful for debugging)
Serial.begin(57600);
//Setup soft serial for MIDI control
mySerial.begin(31250);
//Reset the VS1053 chip
pinMode(resetMIDI, OUTPUT);
digitalWrite(resetMIDI, LOW);
delay(100);
digitalWrite(resetMIDI, HIGH);
delay(100);
//Initialize the pushbutton pins as an input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
}
void loop(){
//0xB0 is channel message, set channel volume to (127)
talkMIDI(0xB0, 0, 0x79);
//Bank select drums
talkMIDI(0xB0, 0, 0x78);
//read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
//check if the pushbutton is pressed.
//if (buttonState is HIGH);
if (buttonState == HIGH)
{
talkMIDI(0xC0, instrument, 0);
Serial.print("N:");
Serial.println(41, DEC); //41 = high floor tom
noteOn(0, note, 127);
delay(000);
noteOff(0, note, 60);
delay(50);
}
else
{
}
if (buttonState2 == HIGH)
{
talkMIDI(0xC0, instrument, 0);
Serial.print("N:");
Serial.println(44, DEC); //44 = pedal hi-hat
noteOn(0, note, 127);
delay(50);
noteOff(0, note, 60);
delay(50);
}
else
{
}
if (buttonState3 == HIGH)
{
talkMIDI(0xC0, instrument, 0);
Serial.print("N:");
Serial.println(51, DEC); //51 = ride cumbal
noteOn(0, note, 127);
delay(50);
noteOff(0, note, 60);
delay(50);
}
else
{
}
if (buttonState4 == HIGH)
{
talkMIDI(0xC0, instrument, 0);
Serial.print("N:");
Serial.println(56); //56 = cowbell
noteOn(0, note, 127);
delay(50);
noteOff(0, note, 60);
delay(50);
}
else
{
}
}
//Declare the noteOn(), noteOff(), and talkMIDI() functions. No need to modify.
//Send a MIDI note-on message. Like pressing a piano key.
//channel ranges from 0-15.
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);
//Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes
//(sort of: MIDI Communication Protocol)
if( (cmd & 0xF0) <= 0xB0)
mySerial.write(data2);
digitalWrite(ledPin, LOW);
}
Please help me with this .
Thankd