Implementiere USB-MIDI-Controller für Arduino Pro Micro mit Hardware- und Software-Architektur, einschließlich Button- und LED-Steuerung, Multiplexer-Integration und MIDI-Kommunikation.

This commit is contained in:
2025-07-19 15:46:14 +02:00
parent f6cbffe217
commit e64048e99b
13 changed files with 820 additions and 11 deletions

25
include/button_handler.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef BUTTON_HANDLER_H
#define BUTTON_HANDLER_H
#include <Arduino.h>
#include <Adafruit_MCP23X17.h>
class ButtonHandler {
private:
Adafruit_MCP23X17* mcp1;
Adafruit_MCP23X17* mcp2;
bool buttonStates[20];
bool lastButtonStates[20];
unsigned long lastDebounceTime[20];
public:
ButtonHandler(Adafruit_MCP23X17* mcp1, Adafruit_MCP23X17* mcp2);
void init();
void update();
bool isPressed(uint8_t buttonIndex);
bool wasPressed(uint8_t buttonIndex);
bool wasReleased(uint8_t buttonIndex);
};
#endif

41
include/config.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef CONFIG_H
#define CONFIG_H
// Hardware-Konfiguration
#define NUM_POTIS 8
#define NUM_SLIDERS 4
#define NUM_BUTTONS 20
#define NUM_LEDS 20
#define NUM_ANALOG_CONTROLS (NUM_POTIS + NUM_SLIDERS)
// MCP23017 I2C Adressen
#define MCP1_ADDRESS 0x20 // Erste MCP23017 (Buttons 0-15 & LEDs 0-15)
#define MCP2_ADDRESS 0x21 // Zweite MCP23017 (Buttons 16-19 & LEDs 16-19)
// CD74HC4067 Multiplexer Pins
#define MUX_S0 2
#define MUX_S1 3
#define MUX_S2 4
#define MUX_S3 5
#define MUX_ANALOG_PIN A0
// MIDI-Konfiguration
#define MIDI_CHANNEL 1
// CC-Mapping für analoge Regler (12 Regler total)
const uint8_t ANALOG_CC_MAP[NUM_ANALOG_CONTROLS] = {
1, 2, 3, 4, 5, 6, 7, 8, // Potis (CC1-CC8)
9, 10, 11, 12 // Schieberegler (CC9-CC12)
};
// Note-Mapping für Buttons (20 Buttons)
const uint8_t BUTTON_NOTE_MAP[NUM_BUTTONS] = {
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, // Buttons 0-9 (C2-A2)
46, 47, 48, 49, 50, 51, 52, 53, 54, 55 // Buttons 10-19 (A#2-G3)
};
// Debounce-Konfiguration
#define DEBOUNCE_TIME 50 // ms
#define ANALOG_THRESHOLD 4 // Mindeständerung für MIDI-CC
#endif

22
include/led_controller.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef LED_CONTROLLER_H
#define LED_CONTROLLER_H
#include <Arduino.h>
#include <Adafruit_MCP23X17.h>
class LEDController {
private:
Adafruit_MCP23X17* mcp1;
Adafruit_MCP23X17* mcp2;
bool ledStates[20];
public:
LEDController(Adafruit_MCP23X17* mcp1, Adafruit_MCP23X17* mcp2);
void init();
void setLED(uint8_t ledIndex, bool state);
void toggleLED(uint8_t ledIndex);
bool getLEDState(uint8_t ledIndex);
void updateHardware();
};
#endif

23
include/midi_handler.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef MIDI_HANDLER_H
#define MIDI_HANDLER_H
#include <Arduino.h>
#include <MIDIUSB.h>
class MIDIHandler {
private:
static void noteOn(byte channel, byte pitch, byte velocity);
static void noteOff(byte channel, byte pitch, byte velocity);
static void controlChange(byte channel, byte control, byte value);
public:
static void init();
static void sendNoteOn(uint8_t note, uint8_t velocity);
static void sendNoteOff(uint8_t note, uint8_t velocity);
static void sendControlChange(uint8_t controller, uint8_t value);
static void processIncomingMIDI();
static void (*onNoteOnCallback)(uint8_t note, uint8_t velocity);
static void (*onNoteOffCallback)(uint8_t note, uint8_t velocity);
};
#endif

21
include/multiplexer.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef MULTIPLEXER_H
#define MULTIPLEXER_H
#include <Arduino.h>
class Multiplexer {
private:
uint8_t s0, s1, s2, s3;
uint8_t analogPin;
int lastValues[16];
unsigned long lastReadTime[16];
public:
Multiplexer(uint8_t s0Pin, uint8_t s1Pin, uint8_t s2Pin, uint8_t s3Pin, uint8_t analogPin);
void init();
int readChannel(uint8_t channel);
bool hasChanged(uint8_t channel, int threshold = 4);
void selectChannel(uint8_t channel);
};
#endif