<はじめに>
M5ATOMとSYNTHのドラムパッドキー製作で、作ったパッドキーを大型のキーパッドに改造し打ち易くすると同時にキーパッドが光るようにしました。
<もくじ>
①はじめに
②もくじ
③部品表
④回路図
⑤コード
⑥終わりに
<部品表>
| 部品名 | 型式 | メーカー | 数量 |
|---|---|---|---|
| マイコン | M5AtomS3 | M5STACK | 1 |
| シンセユニット | M5Stack用MIDIシンセサイザーユニット | M5STACK | 1 |
| キースイッチ | キーボード用スイッチ | 不明 | 8 |
| スピーカー | 5cm | 不明 | 1 |
| LEDプッシュライト | 大型 | 100均 | 2 |
| LEDプッシュライト | 小型 | 100均 | 4 |
| プッシュスイッチ | 2回路×2接点 | 不明 | 6 |
<回路図>
<コード>
M5Synth_Durm.ino
#include <M5AtomS3.h>
#include "M5UnitSynth.h"
M5UnitSynth synth;
// --- 設定:ボタンのピン番号(6個) ---
const int buttonPins[] = {39, 38, 8, 5, 6, 7};
const int numButtons = 6;
// --- 設定:割り当てるドラム音(MIDIノート番号) ---
// 36:バスドラ, 38:スネア, 42:ハイハット閉, 46:ハイハット開, 48:タム, 49:シンバル
const int drumNotes[] = {36, 38, 42, 46, 48, 49};
const char* drumNames[] = {"KICK", "SNARE", "H.H.C", "H.H.O", "TOM", "CYMBAL"};
// ボタンの状態管理用
bool lastState[numButtons];
void setup() {
auto cfg = M5.config();
M5.begin(cfg);
// Synthユニットの初期化 (Port.A: G1, G2)
// チャンネル9はMIDI規格でドラム専用チャンネルです
synth.begin(&Serial2, UNIT_SYNTH_BAUD, 1, 2);
synth.setInstrument(0, 9, SynthDrum);
// ピンモード設定(内蔵プルアップを使用)
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
lastState[i] = HIGH; // 初期状態はHIGH(押されていない)
}
// 画面表示
M5.Display.setRotation(1);
M5.Display.setTextColor(YELLOW);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::Font4);
M5.Display.drawString("DRUM PAD", M5.Display.width() / 2, M5.Display.height() / 2);
}
void loop() {
M5.update();
for (int i = 0; i < numButtons; i++) {
bool currentState = digitalRead(buttonPins[i]);
// ボタンが「押された瞬間(HIGHからLOWになった時)」だけ実行
if (currentState == LOW && lastState[i] == HIGH) {
// ドラム音を鳴らす (チャンネル9, ノート番号, 音量127)
synth.setNoteOn(9, drumNotes[i], 127);
// 画面に楽器名を表示
M5.Display.clear();
M5.Display.setTextColor(CYAN);
M5.Display.drawString(drumNames[i], M5.Display.width() / 2, M5.Display.height() / 2);
Serial.printf("Play: %s (Note %d)\n", drumNames[i], drumNotes[i]);
delay(10); // チャタリング防止用の短い待機
}
// 状態を保存
lastState[i] = currentState;
}
// 数秒後に画面表示を戻す処理を入れるとより使いやすくなります
}
<終わりに>
大型のLEDプッシュライトにパッドキーに改造したことで、たたいた時にパッドが光るようになり、めっちゃテンションが上がります。
LEDプッシュライトは、内部のスイッチがオルタネイトスイッチなので、同サイズの2回路2接点のプッシュスイッチに交換しました。
投稿者の人気記事





-
nakkyi
さんが
2026/05/22
に
編集
をしました。
(メッセージ: 初版)
-
nakkyi
さんが
2026/05/23
に
編集
をしました。
-
nakkyi
さんが
2026/05/23
に
編集
をしました。
-
nakkyi
さんが
2026/05/23
に
編集
をしました。
-
nakkyi
さんが
2026/05/23
に
編集
をしました。
-
nakkyi
さんが
2026/05/23
に
編集
をしました。
-
nakkyi
さんが
2026/05/23
に
編集
をしました。
-
nakkyi
さんが
前の水曜日の12:34
に
編集
をしました。
ログインしてコメントを投稿する