PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AltPinSerial.ino 1.2KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <MIDI.h>
  2. // Simple tutorial on how to receive and send MIDI messages
  3. // on a different serial port, using SoftwareSerial.
  4. // Here, when receiving any message on channel 4, the Arduino
  5. // will blink a led and play back a note for 1 second.
  6. #if defined(ARDUINO_SAM_DUE) || defined(SAMD_SERIES)
  7. /* example not relevant for this hardware (SoftwareSerial not supported) */
  8. MIDI_CREATE_DEFAULT_INSTANCE();
  9. #else
  10. #include <SoftwareSerial.h>
  11. using Transport = MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>;
  12. int rxPin = 18;
  13. int txPin = 19;
  14. SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
  15. Transport serialMIDI(mySerial);
  16. MIDI_NAMESPACE::MidiInterface<Transport> MIDI((Transport&)serialMIDI);
  17. #endif
  18. void setup()
  19. {
  20. pinMode(LED_BUILTIN, OUTPUT);
  21. MIDI.begin(4); // Launch MIDI and listen to channel 4
  22. }
  23. void loop()
  24. {
  25. if (MIDI.read()) // If we have received a message
  26. {
  27. digitalWrite(LED_BUILTIN, HIGH);
  28. MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
  29. delay(1000); // Wait for a second
  30. MIDI.sendNoteOff(42, 0, 1); // Stop the note
  31. digitalWrite(LED_BUILTIN, LOW);
  32. }
  33. }