// MIDI byte channel = 1; byte instrument = 0; byte velo = 127; //velocity of MIDI notes, must be between 0 and 127 // random notes byte Rnote = 0; // note by random int Rlow = 50; // random range low for notes int Rhigh = 80; // random range high for notes // play timing int TNON =950; // time play note ON int TNOFF =50; // time play note OFF // midi commands byte MCMD = 0; // midi command called status byte = command + channel static byte basis = 127; static byte NOFF = basis; static byte NON = basis + 16; static byte PAT = basis + 32; static byte CMC = basis + 48; static byte PCR = basis + 64; // program change request = 191 + channel static byte CAT = basis + 80; // + channel static byte PBC = basis + 96; // + channel Pitch Bend Control //____________________________________________________________________ // send MIDI message ( USB ) void MIDImessage(byte Mcommand, byte Mnote, byte Mvelo) { Serial.write(Mcommand); //send note on or note off command Serial.write(Mnote); //send pitch data Serial.write(Mvelo); //send velocity data Serial.println(); // we write only pseudo MIDI } //____________________________________________________________________ // SETUP void setup() { Serial.begin(115200); } //____________________________________________________________________ // MAIN void loop() { Rnote = byte(random(Rlow,Rhigh)); MCMD=NOFF + channel; MIDImessage(MCMD,Rnote,velo); delay(TNON); MCMD=NON + channel; MIDImessage(MCMD,Rnote,velo); delay(TNOFF); }