Add OLED support
This commit is contained in:
@@ -1,11 +1,30 @@
|
||||
#define FW_VER 1.0
|
||||
#define USE_OLED true // LEDC68 (Gotek alphanumeric displays)
|
||||
#define USE_ENCODER false
|
||||
|
||||
// include libraries
|
||||
#include <Adafruit_MCP23X17.h>
|
||||
#include <MIDI.h>
|
||||
|
||||
#if USE_OLED
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include "font.h"
|
||||
#include "gfx.h"
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 32
|
||||
Adafruit_SSD1306 oled(SCREEN_WIDTH,SCREEN_HEIGHT,&Wire,-1);
|
||||
#endif
|
||||
|
||||
#if USE_ENCODER
|
||||
|
||||
#endif
|
||||
|
||||
// Instantiate libraries
|
||||
Adafruit_MCP23X17 mcp1; // First MCP23017
|
||||
Adafruit_MCP23X17 mcp2; // Second MCP23017
|
||||
|
||||
// Default hardware MIDI. SoftwareSerial is too slow...
|
||||
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||
// A7 A6 A5 A4 A3 A2 A1 A0 <-- GPIO A
|
||||
@@ -17,7 +36,7 @@ MIDI_CREATE_DEFAULT_INSTANCE();
|
||||
// B0 B1 B2 B3 B4 B5 B6 B7 <-- GPIO B
|
||||
|
||||
// Default MIDI channel
|
||||
byte currentMidiChannel = 8; // Default MIDI channel
|
||||
byte currentMidiChannel = MIDI_CHANNEL_OMNI; //8; // Default MIDI channel
|
||||
|
||||
// Struct for 2 MCP chips.
|
||||
struct MCPOutput {
|
||||
@@ -71,15 +90,46 @@ MCPOutput noteToMCP[32] = {
|
||||
};
|
||||
|
||||
|
||||
void updateOLED() {
|
||||
#if USE_OLED
|
||||
oled.clearDisplay();
|
||||
oled.drawBitmap(0, 0, midich, MIDICH_WIDTH, MIDICH_HEIGHT, 1);
|
||||
oled.setCursor(88, 18);
|
||||
oled.setTextColor(SSD1306_WHITE);
|
||||
oled.setTextSize(1);
|
||||
if (currentMidiChannel == MIDI_CHANNEL_OMNI) {
|
||||
oled.print("ALL");
|
||||
} else {
|
||||
oled.print(currentMidiChannel);
|
||||
}
|
||||
oled.display();
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// LED debug
|
||||
#if USE_OLED
|
||||
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // I2C addr 0x3C
|
||||
// Don't halt if missing, just skip display
|
||||
} else {
|
||||
oled.clearDisplay();
|
||||
oled.drawBitmap(0, 0, bootuplogo, BOOTLOGO_WIDTH, BOOTLOGO_HEIGHT, 1);
|
||||
oled.setCursor(62, 18);
|
||||
oled.setTextColor(SSD1306_WHITE);
|
||||
oled.print("FW ver. " + String(FW_VER));
|
||||
oled.display();
|
||||
delay(2500);
|
||||
oled.setFont(&UiFont);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Midi Activity LED on Pin 13 (aka LED_BUILTIN)
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
// Initialize MCP23017s
|
||||
mcp1.begin_I2C(0x20);
|
||||
mcp2.begin_I2C(0x21);
|
||||
// Initialize MIDI
|
||||
MIDI.begin(MIDI_CHANNEL_OMNI);
|
||||
MIDI.begin(currentMidiChannel);
|
||||
MIDI.setHandleNoteOn(handleNoteOn);
|
||||
MIDI.setHandleNoteOff(handleNoteOff);
|
||||
|
||||
@@ -90,6 +140,7 @@ void setup() {
|
||||
mcp2.pinMode(i, OUTPUT);
|
||||
mcp2.digitalWrite(i, LOW);
|
||||
}
|
||||
updateOLED();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -100,16 +151,11 @@ void loop() {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
ledActive = false;
|
||||
}
|
||||
// if (MIDI.read()) {
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
// delay(50);
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void handleNoteOn(byte channel, byte pitch, byte velocity) {
|
||||
if (channel == currentMidiChannel) {
|
||||
if (currentMidiChannel == MIDI_CHANNEL_OMNI || channel == currentMidiChannel) {
|
||||
|
||||
if (pitch >= 57 && pitch <= 88) {
|
||||
MCPOutput out = noteToMCP[pitch - 57];
|
||||
@@ -121,14 +167,14 @@ void handleNoteOn(byte channel, byte pitch, byte velocity) {
|
||||
}
|
||||
}
|
||||
|
||||
// Flash LED on any valid Note On
|
||||
// Flash LED on Note On
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
ledOnTime = millis();
|
||||
ledActive = true;
|
||||
}
|
||||
|
||||
void handleNoteOff(byte channel, byte pitch, byte velocity) {
|
||||
if (channel == currentMidiChannel) {
|
||||
if (currentMidiChannel == MIDI_CHANNEL_OMNI || channel == currentMidiChannel) {
|
||||
if (pitch >= 57 && pitch <= 88) {
|
||||
MCPOutput out = noteToMCP[pitch - 57];
|
||||
if (out.chip == 0) {
|
||||
|
||||
Reference in New Issue
Block a user