talofer99

midi example

Oct 14th, 2019
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. int sensorPin = A0;
  2. int sensorValue = 0;
  3.  
  4. int channel = 0 // this is the midi channel
  5.  
  6. void setup() {
  7. Serial.begin(9600);
  8. }
  9.  
  10. void loop() {
  11. midiNoteOn(0,127); // turn note ZERO at pitch 127 (max)
  12. delay(1000);
  13. midiNoteOff(0); // turn off note ZERO
  14. delay(1000);
  15. }
  16.  
  17.  
  18. void midiNoteOn(byte note, byte midiVelocity)
  19. {
  20. Serial.write(144 + channel); //NOTE_ON_CMD (its base + channel # starting at ZERO!)
  21. Serial.write(note);
  22. Serial.write(midiVelocity);
  23. }
  24. void midiNoteOff(byte note, byte midiVelocity)
  25. {
  26. Serial.write(128 + channel); // NOTE_OFF_CMD (its base + channel # starting at ZERO!)
  27. Serial.write(note);
  28. Serial.write(midiVelocity);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment