152 lines
4.4 KiB
C++
152 lines
4.4 KiB
C++
/* **************************************** *
|
|
* MIDI Commander with Digole OLED Display *
|
|
* **************************************** *
|
|
* (C) 2016-05-17 Paolo Iocco *
|
|
* rev. 0.1 *
|
|
* **************************************** *
|
|
* Circuit diagram
|
|
* ---------------
|
|
*
|
|
* +---\/---+
|
|
* LED (D 0) PB0 1| |40 PA0 (A 0 / D24)
|
|
* (D 1) PB1 2| |39 PA1 (A 1 / D25)
|
|
* INT2 (D 2) PB2 3| |38 PA2 (A 2 / D26)
|
|
* PWM (D 3) PB3 4| |37 PA3 (A 3 / D27)
|
|
* PWM /SS (D 4) PB4 5| |36 PA4 (A 4 / D28)
|
|
* MOSI (D 5) PB5 6| |35 PA5 (A 5 / D29)
|
|
* PWM MISO (D 6) PB6 7| |34 PA6 (A 6 / D30)
|
|
* PWM SCK (D 7) PB7 8| |33 PA7 (A 7 / D31)
|
|
* RST 9| |32 AREF
|
|
* VCC 10| |31 GND
|
|
* GND 11| |30 AVCC
|
|
* XTAL2 12| |29 PC7 (D 23)
|
|
* XTAL1 13| |28 PC6 (D 22)
|
|
* RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
|
|
* TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
|
|
*(RX1)/INT0 (D 10) PD2 16| |25 PC3 (D 19) TMS
|
|
*(TX1)/INT1 (D 11) PD3 17| |24 PC2 (D 18) TCK
|
|
* PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
|
|
* PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
|
|
* PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
|
|
* +--------+
|
|
*
|
|
* ***************************************** *
|
|
* Midi Reference:
|
|
* http://arduinomidilib.fortyseveneffects.com/index.html
|
|
* ***************************************** */
|
|
|
|
//#include <SoftwareSerial.h>
|
|
#include <MIDI.h>
|
|
#include "GM_Table.h"
|
|
#include "MIDI_Display.h"
|
|
#include <Wire.h>
|
|
#define LCDWidth 128
|
|
#define LCDHeight 64
|
|
#define _Digole_Serial_SPI_
|
|
#include <DigoleSerial.h>
|
|
|
|
#define LED 13 // LED pin on Arduino Uno
|
|
#define encoder0PinA 2 // Encoder PIN A
|
|
#define encoder0PinB 3 // Encoder PIN B
|
|
#define button 4 // Button pin
|
|
#define MAXBUFFER 28
|
|
unsigned char encoder0Pos = 0;
|
|
unsigned char encoder0PinALast = HIGH;
|
|
unsigned char n = LOW;
|
|
char buffer[MAXBUFFER]; // Buffer for Display
|
|
DigoleSerialDisp mydisp(5,6,255); // SPI:(data, clock, SS). SS=255 --> SS to GND
|
|
//SoftwareSerial SoftSerial(8, 9); // RX, TX
|
|
//MIDI_CREATE_INSTANCE(SoftwareSerial, SoftSerial, MIDI);
|
|
//MIDI_CREATE_DEFAULT_INSTANCE();
|
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
|
|
unsigned long on_time = 0;
|
|
|
|
//* *******************************************
|
|
void DisplayInstrument(void)
|
|
{
|
|
mydisp.clearScreen();
|
|
mydisp.print("+--------------+");
|
|
mydisp.nextTextLine();
|
|
mydisp.print("|Instrument:");
|
|
sprintf(buffer,"%03d|",(encoder0Pos+1));
|
|
mydisp.print(buffer);
|
|
mydisp.nextTextLine();
|
|
mydisp.print("+--------------+");
|
|
mydisp.nextTextLine();
|
|
memcpy_P(buffer,GM_Table[encoder0Pos],MAXBUFFER);
|
|
mydisp.print(buffer);
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
/* General setup */
|
|
pinMode(LED, OUTPUT);
|
|
|
|
/* Setup MIDI */
|
|
MIDI.turnThruOn();
|
|
MIDI.begin(1);
|
|
|
|
/* Setup Encoder */
|
|
pinMode (encoder0PinA,INPUT_PULLUP);
|
|
pinMode (encoder0PinB,INPUT_PULLUP);
|
|
pinMode (button,INPUT_PULLUP);
|
|
|
|
/* Setup Display */
|
|
delay(2500); // please adjust delay
|
|
mydisp.begin();
|
|
//mydisp.uploadStartScreen(1024, StartScreen);
|
|
//mydisp.displayStartScreen(1);
|
|
//mydisp.displayConfig(0);
|
|
//mydisp.setFont(6);
|
|
mydisp.clearScreen();
|
|
mydisp.drawStr(0, 4, " Version 0.15");
|
|
delay(500);
|
|
DisplayInstrument();
|
|
}
|
|
|
|
//* ********************************************
|
|
void loop()
|
|
{
|
|
/* Encoder interpretation */
|
|
n = digitalRead(encoder0PinA);
|
|
if ((encoder0PinALast == LOW) && (n == HIGH)) {
|
|
if (digitalRead(encoder0PinB) == LOW) {
|
|
if (encoder0Pos>0){
|
|
encoder0Pos--;
|
|
}
|
|
} else {
|
|
if (encoder0Pos<127){
|
|
encoder0Pos++;
|
|
}
|
|
}
|
|
DisplayInstrument();
|
|
mydisp.drawStr(0, 1, "?");
|
|
mydisp.drawStr(15, 1, "?");
|
|
}
|
|
encoder0PinALast = n;
|
|
|
|
/* Button interpretation */
|
|
n=digitalRead(button);
|
|
if(n==LOW) {
|
|
mydisp.drawStr(0, 1, "|");
|
|
mydisp.drawStr(15, 1, "|");
|
|
MIDI.sendProgramChange(encoder0Pos,1);
|
|
}
|
|
|
|
/* MIDI Interpretation */
|
|
if (MIDI.read()) { // If we have received a message
|
|
digitalWrite(LED,HIGH); // LED ON
|
|
on_time=millis();
|
|
}
|
|
|
|
/* LED OFF */
|
|
if ((millis()-on_time) > 100) { // if >100ms LED ON
|
|
digitalWrite(LED,LOW); // LED OFF
|
|
}
|
|
}
|
|
|
|
//MIDI.sendNoteOn(42,127,1); // Send a Note (pitch 42, velo 127 on channel 1)
|
|
//delay(1000); // Wait for a second
|
|
//MIDI.sendNoteOff(42,0,1); // Stop the note
|
|
|