Hallo miteinander,
ich möchte mir einen Midi Controller bauen, und habe dafür mehrere Rotary Encoder hier, einen PCF8574A Expander mit Breakoutboard, und ein kleines OLED SSD1306 Display.
Leider beschränken sich meine Programmierfähigkeiten auf ein absolutes Anfängerniveau, und ich versuche mir deshalb aus verschiedenen Bibliotheken und Codeschnipseln bedarfsmäßig zu behelfen.
Hier ein Code aus Control Surface Library mit Hilfe ich ohne Expander einen Encoder ansteuern konnte:
/**
* This is an example that demonstrates the use of a rotary encoder that can
* be used for scrolling through a song list, tuning effects, etc.
*
* ### Connections
*
* - 2: pin A of the rotary encoder
* - 3: pin B of the rotary encoder
*
* The internal pull-up resistors will be enabled automatically.
* Connect the common (C) pin of the rotary encoder to ground.
*
* ### Behavior
*
* If the encoder is rotated clockwise, a MIDI CC increment message is sent,
* if the encoder is rotated counter-clockwise, a MIDI CC decrement message is
* sent.
* The controller number `MCU::V_POT_1` will be used.
*
* To change the encoding of the MIDI CC increment and decrement messages, use
* `RelativeCCSender::setMode`.
*
* Map the Arduino as a Mackie Control Universal (MCU) or equivalent in your
* audio software.
*
* Written by PieterP, 2019-02-16
* https://github.com/tttapa/Control-Surface
*/
#include <Encoder.h> // Include the encoder library
// This has to be done before including the Control Surface library
#include <Control_Surface.h> // Include the Control Surface library
// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;
// Instantiate a CCRotaryEncoder object that reads a rotary encoder,
// connected to pins 2 and 3.
// The CC controller is MCU::V_POT_1, the multiplier is 1,
// and the encoder sends out 4 pulses per step/click.
CCRotaryEncoder enc = {
{2, 3},
MCU::V_POT_1,
1,
4,
};
void setup() {
// Use the Mackie Control protocol for sending relative MIDI CC messages.
RelativeCCSender::setMode(MACKIE_CONTROL_RELATIVE);
Control_Surface.begin(); // Initialize Control Surface
}
void loop() {
// Update the control surface
Control_Surface.loop();
}
Hier ein Code mit welchem ich erfolgreich mit Expander 2 Glühbirnen blinken ließ:
#include "Arduino.h"
#include <Wire.h>
void setup()
{
// Serial Window (debugging)
Serial.begin(9600);
// I2C Two Wire initialisation
Wire.begin();
// PCF8574N is 'reverse' logic inasmuch it SINKS current
// so HIGH is OFF and LOW is ON (will we remember this?)
// Turn OFF all pins by sending a high byte (1 bit per byte)
Wire.beginTransmission(0x027);
Wire.write(0xF);
Wire.endTransmission();
}
void loop()
{
// Addressing the PCF8574N via I2C is easy:
/*
* I 7 6 5 4 3 2 1 0
* | | | | | | | | |
* | P7 P0
* Interrupt
*
* So to make P0 HIGH we set the bit to LOW (yes, confusing)
* eg 0b1111110 where 0b means we're specify a binary value
*/
//Simple LED blink! Turn ON P0 bit by setting LOW (to zero)
Wire.beginTransmission(0x027);
Wire.write(0b11111110);
Wire.endTransmission();
delay (500);
Wire.beginTransmission(0x038);
Wire.write(0b11111101);
Wire.endTransmission();
delay (500);
}
Jetzt würde ich gerne verstehen, wie ich diese beiden Codes zusammenbringe.
Erste versuche haben leider über nicht so richtig funktioniert..
#include "Arduino.h"
#include <Wire.h>
#include <Encoder.h> // Include the encoder library
// This has to be done before including the Control Surface library
#include <Control_Surface.h> // Include the Control Surface library
// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;
// Instantiate a CCRotaryEncoder object that reads a rotary encoder,
// connected to pins 2 and 3.
// The CC controller is MCU::V_POT_1, the multiplier is 1,
// and the encoder sends out 4 pulses per step/click.
CCRotaryEncoder enc = {
{0b11111110, 0b11111101},
MCU::V_POT_1,
1,
4,
};
void setup()
{
// Serial Window (debugging)
Serial.begin(9600);
// I2C Two Wire initialisation
Wire.begin();
// PCF8574N is 'reverse' logic inasmuch it SINKS current
// so HIGH is OFF and LOW is ON (will we remember this?)
// Turn OFF all pins by sending a high byte (1 bit per byte)
Wire.beginTransmission(0x038);
Wire.write(0xF);
Wire.endTransmission();
Wire.requestFrom(0b11111110, 0b11111101); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
// Use the Mackie Control protocol for sending relative MIDI CC messages.
RelativeCCSender::setMode(MACKIE_CONTROL_RELATIVE);
Control_Surface.begin(); // Initialize Control Surface
}
void loop()
{
// Update the control surface
Control_Surface.loop();
}
Freue mich über jede hilfreiche Unterstützung, bzw einen Ratschlag, falls ein ähnliches Projekt schon irgendwo realisiert wurde.
Danke und viele Grüße raus!