The video explains the problems I am encountering.
the code that I used is :
const int switchPin = 10; // The switch is on Arduino pin 10
const int middleC = 60; // Middle C (MIDI note value 60) is the lowest note we'll play
const int LEDpin = 13; // Indicator LED
// Variables:
byte note = 60; // The MIDI note value to be played
//int AnalogValue = 0; // value from the analog input
int lastNotePlayed = 0; // note turned on when you press the switch
int lastSwitchState = 0; // state of the switch during previous time through the main loop
int currentSwitchState = 0;
void setup() {
// set the states of the I/O pins:
pinMode(switchPin, INPUT);
pinMode(LEDpin, OUTPUT);
// Set MIDI baud rate:
Serial.begin(31250);
blink(3);
}
void loop() {
// My potentiometer gave a range from 0 to 1023:
//AnalogValue = analogRead(0);
// convert to a range from 0 to 127:
//note = AnalogValue/8;
currentSwitchState = digitalRead(switchPin);
// Check to see that the switch is pressed:
if (currentSwitchState == 1) {
// check to see that the switch wasn't pressed last time
// through the main loop:
if (lastSwitchState == 0) {
// set the note value based on the analog value, plus a couple octaves:
// note = note + 60;
// start a note playing:
noteOn(0x90, note, 0x40);
// save the note we played, so we can turn it off:
lastNotePlayed = note;
digitalWrite(LEDpin, HIGH);
note ++;
if (note == 72)
note = 60;
}
}
else { // if the switch is not pressed:
// but the switch was pressed last time through the main loop:
if (lastSwitchState == 1) {
// stop the last note played:
noteOn(0x90, lastNotePlayed, 0x00);
digitalWrite(LEDpin, LOW);
}
}
// save the state of the switch for next time
// through the main loop:
lastSwitchState = currentSwitchState;
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(byte cmd, byte data1, byte data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}
// Blinks an LED 3 times
void blink(int howManyTimes) {
int i;
for (i=0; i< howManyTimes; i++) {
digitalWrite(LEDpin, HIGH);
delay(500);
digitalWrite(LEDpin, LOW);
delay(500);
}
}
Since you are using an UNO, why not make it into a USB MIDI device instead of using serial? You just need to program the ATMega8u2 with USB device firmware and then you can send MIDI commands using Serial.write() commands. Then the UNO will appear to be a USB MIDI device and you won't need the MIDI to serial software.
Yes, I am aware of that option, but I am a total noob, I got this Arduino like 3 days back, and I just have very rudimentary knowledge about embedded systems, so I was afraid that I might end up doing something bad which is irreversible.
I searched for tutorials which are like beginners guide. but didn't find any good guides(I agree that due to time constraints my search wasn't exhaustive ), and over that I am not a rich dude, so didn't wanted to take any risk.
BTW the link that you have posted isn't working, and thanks for your response.
I fixed the link (typo missing s). Replacing the atmega8u2 using DFU mode is quite safe, you can always reprogram it with Arduino-usbserial.hex to recover the normal Arduino operation. I'm suggesting trying the MIDI firmware because I think its simpler to use than the serial solution. If you run into problems just drop me an email on darran [at] hunt [dot] net [dot] nz.
hi Darren,
if you want to print the MIDI message to an LCD what should the command be - lcd.print(midiMsg); ?
This is my sketch to do program change via usb-
void SendMIDI(byte number)
{
t_midiMsg midiMsg;
midiMsg.msg.command = MIDI_COMMAND_PROGRAM_CHANGE;
midiMsg.msg.channel = number; // Data 1
midiMsg.msg.data2 = 0; // Data 2
midiMsg.msg.data3 = 0;
lcd.clear();
lcd.print(midiMsg);
Serial.write(midiMsg.raw, sizeof(midiMsg)); /* Send MIDI Message */
}
hi dhunt,
i am working on a midi keyboard using arduino uno,thinking of how to add usb midi to it, am new to it,
only experience is midi music programing,some how wrote the code for midi keys (4) and uploaded into arduino
now wants to check it but no way to connect through usb...i amusing a mac mini os siera version 10.12.6
really need help.... i have checked your links but its not opening..
here is the program i wrote #include <MIDI.h>