Arduino做midi键盘出现问题

2020-04-251.2万
AI 快速预览详细 收起
本文介绍了使用Arduino制作MIDI键盘时遇到的串口收发不稳定问题。通过调整串口波特率和优化noteOn函数,解决了MIDI消息发送不完整的问题。示例程序中,通过设置串口波特率为31250,并在noteOn函数中正确发送MIDI命令、音符值和速度值,确保了MIDI信号的稳定传输。
Arduino做的midi键盘,然后用loopmidi来生成port口,然后再用hairlessMidi来转换,但是出现问题,求大神解决!

+0.89 - Warning: got a status byte when we were expecting 1 more data bytes, sending possibly incomplete MIDI message 0x80


可能是串口的收发不稳定?


void setup() {
  // Set MIDI baud rate:
  Serial.begin(31250);
}

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):

    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, 0x3C, 0x45);
    delay(100);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, 0x3C, 0x00);
    delay(100);
    Serial.write(cmd, ,pitch, ,velocity);
}

// 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(int cmd, int pitch, int velocity) {
  Serial.write(cmd);

  Serial.write(pitch);

  Serial.write(velocity);
}
这是上面的示例程序

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(2)
gada888
gada888
arduino leonardo性价比高
帅猫
帅猫
Arduino只有ATMega32U4,ATMega8U4(如Pro mini,Pro micro,Leonardo)才支持USB MIDI哦
- 没有更多了 -