PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

50 lines
1.4KB

  1. #include <MIDI.h>
  2. MIDI_CREATE_DEFAULT_INSTANCE();
  3. // -----------------------------------------------------------------------------
  4. // This example shows the old way of checking for input messages.
  5. // It's simpler to use the callbacks now, check out the dedicated example.
  6. #define LED 13 // LED pin on Arduino Uno
  7. // -----------------------------------------------------------------------------
  8. void BlinkLed(byte num) // Basic blink function
  9. {
  10. for (byte i=0;i<num;i++)
  11. {
  12. digitalWrite(LED,HIGH);
  13. delay(50);
  14. digitalWrite(LED,LOW);
  15. delay(50);
  16. }
  17. }
  18. // -----------------------------------------------------------------------------
  19. void setup()
  20. {
  21. pinMode(LED, OUTPUT);
  22. MIDI.begin(); // Launch MIDI, by default listening to channel 1.
  23. }
  24. void loop()
  25. {
  26. if (MIDI.read()) // Is there a MIDI message incoming ?
  27. {
  28. switch(MIDI.getType()) // Get the type of the message we caught
  29. {
  30. case midi::ProgramChange: // If it is a Program Change,
  31. BlinkLed(MIDI.getData1()); // blink the LED a number of times
  32. // correponding to the program number
  33. // (0 to 127, it can last a while..)
  34. break;
  35. // See the online reference for other message types
  36. default:
  37. break;
  38. }
  39. }
  40. }