Testing Tool for Board written.
This commit is contained in:
1
main/firmware/config.cpp
Normal file
1
main/firmware/config.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
123
main/firmware/config.h
Normal file
123
main/firmware/config.h
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
#ifndef Config_h
|
||||||
|
#define Config_h
|
||||||
|
|
||||||
|
|
||||||
|
// Include Configuration
|
||||||
|
// If you don't want a feature, switch it of with a '0'
|
||||||
|
#define USE_SDCARD 1
|
||||||
|
#define USE_LCD 1
|
||||||
|
#define USE_AXEFX 1
|
||||||
|
|
||||||
|
|
||||||
|
// ============== Pin Configuration ==============
|
||||||
|
//
|
||||||
|
// LCD-Pin Definitions
|
||||||
|
#if USE_LCD==1
|
||||||
|
#define LCD_D7 44
|
||||||
|
#define LCD_D6 45
|
||||||
|
#define LCD_D5 46
|
||||||
|
#define LCD_D4 47
|
||||||
|
#define LCD_E 48
|
||||||
|
#define LCD_RS 49
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// SD-Card-Pin Definitons
|
||||||
|
#if USE_SDCARD==1
|
||||||
|
#define SDC_MISO 50
|
||||||
|
#define SDC_MOSI 51
|
||||||
|
#define SDC_SCK 52
|
||||||
|
#define SDC_CS 53
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// LED und Switch Pins
|
||||||
|
#define SWT01 2
|
||||||
|
#define LED01 3
|
||||||
|
#define SWT02 4
|
||||||
|
#define LED02 5
|
||||||
|
#define SWT03 6
|
||||||
|
#define LED03 7
|
||||||
|
#define SWT04 8
|
||||||
|
#define LED04 9
|
||||||
|
#define SWT05 10
|
||||||
|
#define LED05 11
|
||||||
|
#define SWT06 12
|
||||||
|
#define LED06 13
|
||||||
|
|
||||||
|
#define SWT07 22
|
||||||
|
#define LED07 24
|
||||||
|
#define SWT08 26
|
||||||
|
#define LED08 28
|
||||||
|
#define SWT09 30
|
||||||
|
#define LED09 32
|
||||||
|
#define SWT10 34
|
||||||
|
#define LED10 36
|
||||||
|
#define SWT11 38
|
||||||
|
#define LED11 40
|
||||||
|
|
||||||
|
#define SWT12 23
|
||||||
|
#define LED12 25
|
||||||
|
#define SWT13 27
|
||||||
|
#define LED13 29
|
||||||
|
#define SWT14 31
|
||||||
|
#define LED14 33
|
||||||
|
#define SWT15 35
|
||||||
|
#define LED15 37
|
||||||
|
#define SWT16 39
|
||||||
|
#define LED16 41
|
||||||
|
|
||||||
|
#define SWT17 42
|
||||||
|
#define LED17 43
|
||||||
|
#define SWT18 A8
|
||||||
|
#define LED18 A9
|
||||||
|
#define SWT19 A10
|
||||||
|
#define LED19 A11
|
||||||
|
#define SWT20 A12
|
||||||
|
#define LED20 A13
|
||||||
|
#define SWT21 A14
|
||||||
|
#define LED21 A15
|
||||||
|
|
||||||
|
#define SWT22 A6
|
||||||
|
#define LED22 A7
|
||||||
|
#define SWT23 14
|
||||||
|
#define LED23 15
|
||||||
|
|
||||||
|
// Not used if you have SD-Card
|
||||||
|
#if USE_SDCARD==0
|
||||||
|
#define SWT24 16
|
||||||
|
#define LED24 17
|
||||||
|
#define SWT25 20
|
||||||
|
#define LED25 21
|
||||||
|
#define SWT26 50
|
||||||
|
#define LED26 51
|
||||||
|
#define SWT27 52
|
||||||
|
#define LED27 99
|
||||||
|
#define SWT28 53
|
||||||
|
#define LED28 99
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Expression-Pedal Pins
|
||||||
|
#define EXP01 A0
|
||||||
|
#define EXP02 A1
|
||||||
|
|
||||||
|
// Layer-LEDs
|
||||||
|
#define LAY_LED01 A2
|
||||||
|
#define LAY_LED02 A3
|
||||||
|
#define LAY_LED03 A4
|
||||||
|
#define LAY_LED04 A5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ============== Standard Board Configurtation ===============
|
||||||
|
//
|
||||||
|
// ...will be overwritten by SD-Card Config if you use SD-Cards!
|
||||||
|
// If there is no SD-Card or SD-Card-Config-File present
|
||||||
|
// it will use the Standard Configuration!
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
45
main/firmware/firmware.ino
Normal file
45
main/firmware/firmware.ino
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* @file firmware.ino
|
||||||
|
* Project axefx.de MIDI Borad TWO
|
||||||
|
* @brief Main Firmware-File for MIDI-Board
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author Bastian Buehrig
|
||||||
|
* @date 13/02/15
|
||||||
|
* license GPL axefx.de - 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// Standard-Config
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
// SD-Card includes
|
||||||
|
#if USE_SDCARD==1
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// LCD-Display includes
|
||||||
|
#if USE_LCD==1
|
||||||
|
#include <LiquidCrystal.h>
|
||||||
|
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// MIDI includes
|
||||||
|
#include <MIDI.h>
|
||||||
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
|
}
|
||||||
BIN
main/libraries/MIDI/.DS_Store
vendored
Normal file
BIN
main/libraries/MIDI/.DS_Store
vendored
Normal file
Binary file not shown.
98
main/libraries/MIDI/MIDI.cpp
Normal file
98
main/libraries/MIDI/MIDI.cpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/*!
|
||||||
|
* @file MIDI.cpp
|
||||||
|
* Project Arduino MIDI Library
|
||||||
|
* @brief MIDI Library for the Arduino
|
||||||
|
* @version 4.2
|
||||||
|
* @author Francois Best
|
||||||
|
* @date 24/02/11
|
||||||
|
* @license GPL v3.0 - Copyright Forty Seven Effects 2014
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MIDI.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BEGIN_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
/*! \brief Encode System Exclusive messages.
|
||||||
|
SysEx messages are encoded to guarantee transmission of data bytes higher than
|
||||||
|
127 without breaking the MIDI protocol. Use this static method to convert the
|
||||||
|
data you want to send.
|
||||||
|
\param inData The data to encode.
|
||||||
|
\param outSysEx The output buffer where to store the encoded message.
|
||||||
|
\param inLength The lenght of the input buffer.
|
||||||
|
\return The lenght of the encoded output buffer.
|
||||||
|
@see decodeSysEx
|
||||||
|
Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com
|
||||||
|
*/
|
||||||
|
unsigned encodeSysEx(const byte* inData, byte* outSysEx, unsigned inLength)
|
||||||
|
{
|
||||||
|
unsigned outLength = 0; // Num bytes in output array.
|
||||||
|
byte count = 0; // Num 7bytes in a block.
|
||||||
|
outSysEx[0] = 0;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < inLength; ++i)
|
||||||
|
{
|
||||||
|
const byte data = inData[i];
|
||||||
|
const byte msb = data >> 7;
|
||||||
|
const byte body = data & 0x7f;
|
||||||
|
|
||||||
|
outSysEx[0] |= (msb << count);
|
||||||
|
outSysEx[1 + count] = body;
|
||||||
|
|
||||||
|
if (count++ == 6)
|
||||||
|
{
|
||||||
|
outSysEx += 8;
|
||||||
|
outLength += 8;
|
||||||
|
outSysEx[0] = 0;
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outLength + count + (count != 0 ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Decode System Exclusive messages.
|
||||||
|
SysEx messages are encoded to guarantee transmission of data bytes higher than
|
||||||
|
127 without breaking the MIDI protocol. Use this static method to reassemble
|
||||||
|
your received message.
|
||||||
|
\param inSysEx The SysEx data received from MIDI in.
|
||||||
|
\param outData The output buffer where to store the decrypted message.
|
||||||
|
\param inLength The lenght of the input buffer.
|
||||||
|
\return The lenght of the output buffer.
|
||||||
|
@see encodeSysEx @see getSysExArrayLength
|
||||||
|
Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com
|
||||||
|
*/
|
||||||
|
unsigned decodeSysEx(const byte* inSysEx, byte* outData, unsigned inLength)
|
||||||
|
{
|
||||||
|
unsigned count = 0;
|
||||||
|
byte msbStorage = 0;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < inLength; ++i)
|
||||||
|
{
|
||||||
|
if ((i % 8) == 0)
|
||||||
|
{
|
||||||
|
msbStorage = inSysEx[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outData[count++] = inSysEx[i] | ((msbStorage & 1) << 7);
|
||||||
|
msbStorage >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
END_MIDI_NAMESPACE
|
||||||
224
main/libraries/MIDI/MIDI.h
Normal file
224
main/libraries/MIDI/MIDI.h
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
/*!
|
||||||
|
* @file MIDI.h
|
||||||
|
* Project Arduino MIDI Library
|
||||||
|
* @brief MIDI Library for the Arduino
|
||||||
|
* @version 4.2
|
||||||
|
* @author Francois Best
|
||||||
|
* @date 24/02/11
|
||||||
|
* @license GPL v3.0 - Copyright Forty Seven Effects 2014
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "midi_Defs.h"
|
||||||
|
#include "midi_Settings.h"
|
||||||
|
#include "midi_Message.h"
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BEGIN_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
/*! \brief The main class for MIDI handling.
|
||||||
|
It is templated over the type of serial port to provide abstraction from
|
||||||
|
the hardware interface, meaning you can use HardwareSerial, SoftwareSerial
|
||||||
|
or ak47's Uart classes. The only requirement is that the class implements
|
||||||
|
the begin, read, write and available methods.
|
||||||
|
*/
|
||||||
|
template<class SerialPort, class Settings = DefaultSettings>
|
||||||
|
class MidiInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline MidiInterface(SerialPort& inSerial);
|
||||||
|
inline ~MidiInterface();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void begin(Channel inChannel = 1);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// MIDI Output
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline void sendNoteOn(DataByte inNoteNumber,
|
||||||
|
DataByte inVelocity,
|
||||||
|
Channel inChannel);
|
||||||
|
|
||||||
|
inline void sendNoteOff(DataByte inNoteNumber,
|
||||||
|
DataByte inVelocity,
|
||||||
|
Channel inChannel);
|
||||||
|
|
||||||
|
inline void sendProgramChange(DataByte inProgramNumber,
|
||||||
|
Channel inChannel);
|
||||||
|
|
||||||
|
inline void sendControlChange(DataByte inControlNumber,
|
||||||
|
DataByte inControlValue,
|
||||||
|
Channel inChannel);
|
||||||
|
|
||||||
|
inline void sendPitchBend(int inPitchValue, Channel inChannel);
|
||||||
|
inline void sendPitchBend(double inPitchValue, Channel inChannel);
|
||||||
|
|
||||||
|
inline void sendPolyPressure(DataByte inNoteNumber,
|
||||||
|
DataByte inPressure,
|
||||||
|
Channel inChannel);
|
||||||
|
|
||||||
|
inline void sendAfterTouch(DataByte inPressure,
|
||||||
|
Channel inChannel);
|
||||||
|
|
||||||
|
inline void sendSysEx(unsigned inLength,
|
||||||
|
const byte* inArray,
|
||||||
|
bool inArrayContainsBoundaries = false);
|
||||||
|
|
||||||
|
inline void sendTimeCodeQuarterFrame(DataByte inTypeNibble,
|
||||||
|
DataByte inValuesNibble);
|
||||||
|
inline void sendTimeCodeQuarterFrame(DataByte inData);
|
||||||
|
|
||||||
|
inline void sendSongPosition(unsigned inBeats);
|
||||||
|
inline void sendSongSelect(DataByte inSongNumber);
|
||||||
|
inline void sendTuneRequest();
|
||||||
|
inline void sendRealTime(MidiType inType);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void send(MidiType inType,
|
||||||
|
DataByte inData1,
|
||||||
|
DataByte inData2,
|
||||||
|
Channel inChannel);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// MIDI Input
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline bool read();
|
||||||
|
inline bool read(Channel inChannel);
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline MidiType getType() const;
|
||||||
|
inline Channel getChannel() const;
|
||||||
|
inline DataByte getData1() const;
|
||||||
|
inline DataByte getData2() const;
|
||||||
|
inline const byte* getSysExArray() const;
|
||||||
|
inline unsigned getSysExArrayLength() const;
|
||||||
|
inline bool check() const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline Channel getInputChannel() const;
|
||||||
|
inline void setInputChannel(Channel inChannel);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static inline MidiType getTypeFromStatusByte(byte inStatus);
|
||||||
|
static inline Channel getChannelFromStatusByte(byte inStatus);
|
||||||
|
static inline bool isChannelMessage(MidiType inType);
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Input Callbacks
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline void setHandleNoteOff(void (*fptr)(byte channel, byte note, byte velocity));
|
||||||
|
inline void setHandleNoteOn(void (*fptr)(byte channel, byte note, byte velocity));
|
||||||
|
inline void setHandleAfterTouchPoly(void (*fptr)(byte channel, byte note, byte pressure));
|
||||||
|
inline void setHandleControlChange(void (*fptr)(byte channel, byte number, byte value));
|
||||||
|
inline void setHandleProgramChange(void (*fptr)(byte channel, byte number));
|
||||||
|
inline void setHandleAfterTouchChannel(void (*fptr)(byte channel, byte pressure));
|
||||||
|
inline void setHandlePitchBend(void (*fptr)(byte channel, int bend));
|
||||||
|
inline void setHandleSystemExclusive(void (*fptr)(byte * array, unsigned size));
|
||||||
|
inline void setHandleTimeCodeQuarterFrame(void (*fptr)(byte data));
|
||||||
|
inline void setHandleSongPosition(void (*fptr)(unsigned beats));
|
||||||
|
inline void setHandleSongSelect(void (*fptr)(byte songnumber));
|
||||||
|
inline void setHandleTuneRequest(void (*fptr)(void));
|
||||||
|
inline void setHandleClock(void (*fptr)(void));
|
||||||
|
inline void setHandleStart(void (*fptr)(void));
|
||||||
|
inline void setHandleContinue(void (*fptr)(void));
|
||||||
|
inline void setHandleStop(void (*fptr)(void));
|
||||||
|
inline void setHandleActiveSensing(void (*fptr)(void));
|
||||||
|
inline void setHandleSystemReset(void (*fptr)(void));
|
||||||
|
|
||||||
|
inline void disconnectCallbackFromType(MidiType inType);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void launchCallback();
|
||||||
|
|
||||||
|
void (*mNoteOffCallback)(byte channel, byte note, byte velocity);
|
||||||
|
void (*mNoteOnCallback)(byte channel, byte note, byte velocity);
|
||||||
|
void (*mAfterTouchPolyCallback)(byte channel, byte note, byte velocity);
|
||||||
|
void (*mControlChangeCallback)(byte channel, byte, byte);
|
||||||
|
void (*mProgramChangeCallback)(byte channel, byte);
|
||||||
|
void (*mAfterTouchChannelCallback)(byte channel, byte);
|
||||||
|
void (*mPitchBendCallback)(byte channel, int);
|
||||||
|
void (*mSystemExclusiveCallback)(byte * array, unsigned size);
|
||||||
|
void (*mTimeCodeQuarterFrameCallback)(byte data);
|
||||||
|
void (*mSongPositionCallback)(unsigned beats);
|
||||||
|
void (*mSongSelectCallback)(byte songnumber);
|
||||||
|
void (*mTuneRequestCallback)(void);
|
||||||
|
void (*mClockCallback)(void);
|
||||||
|
void (*mStartCallback)(void);
|
||||||
|
void (*mContinueCallback)(void);
|
||||||
|
void (*mStopCallback)(void);
|
||||||
|
void (*mActiveSensingCallback)(void);
|
||||||
|
void (*mSystemResetCallback)(void);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// MIDI Soft Thru
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline MidiFilterMode getFilterMode() const;
|
||||||
|
inline bool getThruState() const;
|
||||||
|
|
||||||
|
inline void turnThruOn(MidiFilterMode inThruFilterMode = Full);
|
||||||
|
inline void turnThruOff();
|
||||||
|
inline void setThruFilterMode(MidiFilterMode inThruFilterMode);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void thruFilter(byte inChannel);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool parse();
|
||||||
|
inline void handleNullVelocityNoteOnAsNoteOff();
|
||||||
|
inline bool inputFilter(Channel inChannel);
|
||||||
|
inline void resetInput();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mThruActivated : 1;
|
||||||
|
MidiFilterMode mThruFilterMode : 7;
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef Message<Settings::SysExMaxSize> MidiMessage;
|
||||||
|
|
||||||
|
private:
|
||||||
|
StatusByte mRunningStatus_RX;
|
||||||
|
StatusByte mRunningStatus_TX;
|
||||||
|
Channel mInputChannel;
|
||||||
|
byte mPendingMessage[3];
|
||||||
|
unsigned mPendingMessageExpectedLenght;
|
||||||
|
unsigned mPendingMessageIndex;
|
||||||
|
MidiMessage mMessage;
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline StatusByte getStatus(MidiType inType,
|
||||||
|
Channel inChannel) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SerialPort& mSerial;
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
unsigned encodeSysEx(const byte* inData, byte* outSysEx, unsigned inLenght);
|
||||||
|
unsigned decodeSysEx(const byte* inSysEx, byte* outData, unsigned inLenght);
|
||||||
|
|
||||||
|
END_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "MIDI.hpp"
|
||||||
1204
main/libraries/MIDI/MIDI.hpp
Normal file
1204
main/libraries/MIDI/MIDI.hpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
main/libraries/MIDI/examples/.DS_Store
vendored
Normal file
BIN
main/libraries/MIDI/examples/.DS_Store
vendored
Normal file
Binary file not shown.
27
main/libraries/MIDI/examples/MIDI_Basic_IO/MIDI_Basic_IO.ino
Normal file
27
main/libraries/MIDI/examples/MIDI_Basic_IO/MIDI_Basic_IO.ino
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include <MIDI.h>
|
||||||
|
|
||||||
|
// Simple tutorial on how to receive and send MIDI messages.
|
||||||
|
// Here, when receiving any message on channel 4, the Arduino
|
||||||
|
// will blink a led and play back a note for 1 second.
|
||||||
|
|
||||||
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||||
|
|
||||||
|
#define LED 13 // LED pin on Arduino Uno
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
pinMode(LED, OUTPUT);
|
||||||
|
MIDI.begin(4); // Launch MIDI and listen to channel 4
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if (MIDI.read()) // If we have received a message
|
||||||
|
{
|
||||||
|
digitalWrite(LED,HIGH);
|
||||||
|
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
|
||||||
|
digitalWrite(LED,LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
85
main/libraries/MIDI/examples/MIDI_Bench/MIDI_Bench.ino
Normal file
85
main/libraries/MIDI/examples/MIDI_Bench/MIDI_Bench.ino
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#include <MIDI.h>
|
||||||
|
|
||||||
|
// This program will measure the time needed to receive, parse and process a
|
||||||
|
// NoteOn message.
|
||||||
|
// For it to work, please connect RX and TX on the MIDI port:
|
||||||
|
// Due, Leonardo and other USB-native Arduinos: Serial1
|
||||||
|
// All other Arduinos: Connect pins 2 and 3.
|
||||||
|
// The program will then wait for 100 loops and print the results.
|
||||||
|
|
||||||
|
#if defined(ARDUINO_SAM_DUE) || defined(USBCON)
|
||||||
|
// Print through USB and bench with Hardware serial
|
||||||
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiBench);
|
||||||
|
#else
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
SoftwareSerial midiSerial(2,3);
|
||||||
|
MIDI_CREATE_INSTANCE(SoftwareSerial, midiSerial, midiBench);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
unsigned long gTime_start = 0;
|
||||||
|
unsigned long gTime_stop = 0;
|
||||||
|
unsigned gCounter = 0;
|
||||||
|
unsigned long gTime_sum = 0;
|
||||||
|
unsigned long gTime_min = -1;
|
||||||
|
unsigned long gTime_max = 0;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
|
||||||
|
{
|
||||||
|
gTime_stop = micros();
|
||||||
|
|
||||||
|
const unsigned long diff = gTime_stop - gTime_start;
|
||||||
|
gTime_sum += diff;
|
||||||
|
|
||||||
|
if (diff > gTime_max) gTime_max = diff;
|
||||||
|
if (diff < gTime_min) gTime_min = diff;
|
||||||
|
|
||||||
|
if (gCounter++ >= 1000)
|
||||||
|
{
|
||||||
|
const unsigned long average = gTime_sum / (float)gCounter;
|
||||||
|
|
||||||
|
Serial.println("Time to receive NoteOn: ");
|
||||||
|
|
||||||
|
Serial.print("Average: ");
|
||||||
|
Serial.print(average);
|
||||||
|
Serial.println(" microsecs");
|
||||||
|
|
||||||
|
Serial.print("Min: ");
|
||||||
|
Serial.print(gTime_min);
|
||||||
|
Serial.println(" microsecs");
|
||||||
|
|
||||||
|
Serial.print("Max: ");
|
||||||
|
Serial.print(gTime_max);
|
||||||
|
Serial.println(" microsecs");
|
||||||
|
|
||||||
|
gCounter = 0;
|
||||||
|
gTime_sum = 0;
|
||||||
|
gTime_max = 0;
|
||||||
|
gTime_min = -1;
|
||||||
|
|
||||||
|
midiBench.turnThruOff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
midiBench.setHandleNoteOn(handleNoteOn);
|
||||||
|
midiBench.begin();
|
||||||
|
|
||||||
|
while(!Serial);
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Arduino Ready");
|
||||||
|
|
||||||
|
midiBench.sendNoteOn(69,127,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
gTime_start = micros();
|
||||||
|
midiBench.read();
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#include <MIDI.h>
|
||||||
|
|
||||||
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// This function will be automatically called when a NoteOn is received.
|
||||||
|
// It must be a void-returning function with the correct parameters,
|
||||||
|
// see documentation here:
|
||||||
|
// http://arduinomidilib.fortyseveneffects.com/a00022.html
|
||||||
|
|
||||||
|
void handleNoteOn(byte channel, byte pitch, byte velocity)
|
||||||
|
{
|
||||||
|
// Do whatever you want when a note is pressed.
|
||||||
|
|
||||||
|
// Try to keep your callbacks short (no delays ect)
|
||||||
|
// otherwise it would slow down the loop() and have a bad impact
|
||||||
|
// on real-time performance.
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleNoteOff(byte channel, byte pitch, byte velocity)
|
||||||
|
{
|
||||||
|
// Do something when the note is released.
|
||||||
|
// Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Connect the handleNoteOn function to the library,
|
||||||
|
// so it is called upon reception of a NoteOn.
|
||||||
|
MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
|
||||||
|
|
||||||
|
// Do the same for NoteOffs
|
||||||
|
MIDI.setHandleNoteOff(handleNoteOff);
|
||||||
|
|
||||||
|
// Initiate MIDI communications, listen to all channels
|
||||||
|
MIDI.begin(MIDI_CHANNEL_OMNI);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// Call MIDI.read the fastest you can for real-time performance.
|
||||||
|
MIDI.read();
|
||||||
|
|
||||||
|
// There is no need to check if there are messages incoming
|
||||||
|
// if they are bound to a Callback function.
|
||||||
|
// The attached method will be called automatically
|
||||||
|
// when the corresponding message has been received.
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#include <MIDI.h>
|
||||||
|
|
||||||
|
// This example shows how to create two instances of the library to create a merger.
|
||||||
|
// There are two MIDI couples of IO, A and B, each using thru and merging with the
|
||||||
|
// input from the other node. The result is the following:
|
||||||
|
// A out = A in + B in
|
||||||
|
// B out = B in + A in
|
||||||
|
|
||||||
|
#ifdef ARDUINO_SAM_DUE
|
||||||
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA);
|
||||||
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiB);
|
||||||
|
#else
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
SoftwareSerial softSerial(2,3);
|
||||||
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiA);
|
||||||
|
MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiB);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Initiate MIDI communications, listen to all channels
|
||||||
|
midiA.begin(MIDI_CHANNEL_OMNI);
|
||||||
|
midiB.begin(MIDI_CHANNEL_OMNI);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if (midiA.read())
|
||||||
|
{
|
||||||
|
// Thru on A has already pushed the input message to out A.
|
||||||
|
// Forward the message to out B as well.
|
||||||
|
midiB.send(midiA.getType(),
|
||||||
|
midiA.getData1(),
|
||||||
|
midiA.getData2(),
|
||||||
|
midiA.getChannel());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (midiB.read())
|
||||||
|
{
|
||||||
|
// Thru on B has already pushed the input message to out B.
|
||||||
|
// Forward the message to out A as well.
|
||||||
|
midiA.send(midiB.getType(),
|
||||||
|
midiB.getData1(),
|
||||||
|
midiB.getData2(),
|
||||||
|
midiB.getChannel());
|
||||||
|
}
|
||||||
|
}
|
||||||
49
main/libraries/MIDI/examples/MIDI_Input/MIDI_Input.ino
Normal file
49
main/libraries/MIDI/examples/MIDI_Input/MIDI_Input.ino
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include <MIDI.h>
|
||||||
|
|
||||||
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// This example shows the old way of checking for input messages.
|
||||||
|
// It's simpler to use the callbacks now, check out the dedicated example.
|
||||||
|
|
||||||
|
#define LED 13 // LED pin on Arduino Uno
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void BlinkLed(byte num) // Basic blink function
|
||||||
|
{
|
||||||
|
for (byte i=0;i<num;i++)
|
||||||
|
{
|
||||||
|
digitalWrite(LED,HIGH);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(LED,LOW);
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
pinMode(LED, OUTPUT);
|
||||||
|
MIDI.begin(); // Launch MIDI, by default listening to channel 1.
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if (MIDI.read()) // Is there a MIDI message incoming ?
|
||||||
|
{
|
||||||
|
switch(MIDI.getType()) // Get the type of the message we caught
|
||||||
|
{
|
||||||
|
case midi::ProgramChange: // If it is a Program Change,
|
||||||
|
BlinkLed(MIDI.getData1()); // blink the LED a number of times
|
||||||
|
// correponding to the program number
|
||||||
|
// (0 to 127, it can last a while..)
|
||||||
|
break;
|
||||||
|
// See the online reference for other message types
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
main/libraries/MIDI/examples/MIDI_SimpleSynth/.DS_Store
vendored
Normal file
BIN
main/libraries/MIDI/examples/MIDI_SimpleSynth/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -0,0 +1,97 @@
|
|||||||
|
#include <MIDI.h>
|
||||||
|
#include "noteList.h"
|
||||||
|
#include "pitches.h"
|
||||||
|
|
||||||
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
||||||
|
|
||||||
|
#ifdef ARDUINO_SAM_DUE // Due has no tone function (yet), overriden to prevent build errors.
|
||||||
|
#define tone(...)
|
||||||
|
#define noTone(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This example shows how to make a simple synth out of an Arduino, using the
|
||||||
|
// tone() function. It also outputs a gate signal for controlling external
|
||||||
|
// analog synth components (like envelopes).
|
||||||
|
|
||||||
|
static const unsigned sGatePin = 13;
|
||||||
|
static const unsigned sAudioOutPin = 10;
|
||||||
|
static const unsigned sMaxNumNotes = 16;
|
||||||
|
MidiNoteList<sMaxNumNotes> midiNotes;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
inline void handleGateChanged(bool inGateActive)
|
||||||
|
{
|
||||||
|
digitalWrite(sGatePin, inGateActive ? HIGH : LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void pulseGate()
|
||||||
|
{
|
||||||
|
handleGateChanged(false);
|
||||||
|
delay(1);
|
||||||
|
handleGateChanged(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void handleNotesChanged(bool isFirstNote = false)
|
||||||
|
{
|
||||||
|
if (midiNotes.empty())
|
||||||
|
{
|
||||||
|
handleGateChanged(false);
|
||||||
|
noTone(sAudioOutPin);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Possible playing modes:
|
||||||
|
// Mono Low: use midiNotes.getLow
|
||||||
|
// Mono High: use midiNotes.getHigh
|
||||||
|
// Mono Last: use midiNotes.getLast
|
||||||
|
|
||||||
|
byte currentNote = 0;
|
||||||
|
if (midiNotes.getLast(currentNote))
|
||||||
|
{
|
||||||
|
tone(sAudioOutPin, sNotePitches[currentNote]);
|
||||||
|
|
||||||
|
if (isFirstNote)
|
||||||
|
{
|
||||||
|
handleGateChanged(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pulseGate(); // Retrigger envelopes. Remove for legato effect.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
|
||||||
|
{
|
||||||
|
const bool firstNote = midiNotes.empty();
|
||||||
|
midiNotes.add(MidiNote(inNote, inVelocity));
|
||||||
|
handleNotesChanged(firstNote);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
|
||||||
|
{
|
||||||
|
midiNotes.remove(inNote);
|
||||||
|
handleNotesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
pinMode(sGatePin, OUTPUT);
|
||||||
|
pinMode(sAudioOutPin, OUTPUT);
|
||||||
|
MIDI.setHandleNoteOn(handleNoteOn);
|
||||||
|
MIDI.setHandleNoteOff(handleNoteOff);
|
||||||
|
MIDI.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
MIDI.read();
|
||||||
|
}
|
||||||
21
main/libraries/MIDI/examples/MIDI_SimpleSynth/noteList.cpp
Normal file
21
main/libraries/MIDI/examples/MIDI_SimpleSynth/noteList.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*!
|
||||||
|
* \file synth-core_NoteList.h
|
||||||
|
* \author Francois Best
|
||||||
|
* \date 24/05/2013
|
||||||
|
* \license GPL v3.0 - Copyright Forty Seven Effects 2013
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "noteList.h"
|
||||||
391
main/libraries/MIDI/examples/MIDI_SimpleSynth/noteList.h
Normal file
391
main/libraries/MIDI/examples/MIDI_SimpleSynth/noteList.h
Normal file
@@ -0,0 +1,391 @@
|
|||||||
|
/*!
|
||||||
|
* \file noteList.h
|
||||||
|
* \author Francois Best
|
||||||
|
* \date 24/05/2013
|
||||||
|
* \brief Linked list of notes, for Low, Last & High playing modes.
|
||||||
|
* \license GPL v3.0 - Copyright Forty Seven Effects 2013
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
typedef uint8_t byte;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct MidiNote
|
||||||
|
{
|
||||||
|
inline MidiNote();
|
||||||
|
inline MidiNote(byte inPitch, byte inVelocity);
|
||||||
|
inline MidiNote(const MidiNote& inOther);
|
||||||
|
inline MidiNote& operator= (const MidiNote& inOther);
|
||||||
|
|
||||||
|
byte pitch;
|
||||||
|
byte velocity;
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
class MidiNoteList
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
struct Cell
|
||||||
|
{
|
||||||
|
inline Cell();
|
||||||
|
inline Cell(const Cell& inOther);
|
||||||
|
inline Cell& operator= (const Cell& inOther);
|
||||||
|
|
||||||
|
MidiNote note;
|
||||||
|
bool active;
|
||||||
|
Cell* next;
|
||||||
|
Cell* prev;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline MidiNoteList();
|
||||||
|
inline ~MidiNoteList();
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline void add(const MidiNote& inNote);
|
||||||
|
inline void remove(byte inPitch);
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline bool get(byte inIndex, byte& outPitch) const;
|
||||||
|
inline bool getLast(byte& outPitch) const;
|
||||||
|
inline bool getHigh(byte& outPitch) const;
|
||||||
|
inline bool getLow(byte& outPitch) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline bool empty() const;
|
||||||
|
inline byte size() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline Cell* getFirstEmptyCell();
|
||||||
|
inline void print() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Cell mArray[Size];
|
||||||
|
Cell* mHead;
|
||||||
|
Cell* mTail;
|
||||||
|
byte mSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ########################################################################## //
|
||||||
|
// Inline implementation
|
||||||
|
|
||||||
|
inline MidiNote::MidiNote()
|
||||||
|
: pitch(0)
|
||||||
|
, velocity(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline MidiNote::MidiNote(byte inPitch, byte inVelocity)
|
||||||
|
: pitch(inPitch)
|
||||||
|
, velocity(inVelocity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline MidiNote::MidiNote(const MidiNote& inOther)
|
||||||
|
: pitch(inOther.pitch)
|
||||||
|
, velocity(inOther.velocity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline MidiNote& MidiNote::operator= (const MidiNote& inOther)
|
||||||
|
{
|
||||||
|
pitch = inOther.pitch;
|
||||||
|
velocity = inOther.velocity;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ########################################################################## //
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline MidiNoteList<Size>::Cell::Cell()
|
||||||
|
: note()
|
||||||
|
, active(false)
|
||||||
|
, next(0)
|
||||||
|
, prev(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline MidiNoteList<Size>::Cell::Cell(const Cell& inOther)
|
||||||
|
: note(inOther.note)
|
||||||
|
, active(inOther.active)
|
||||||
|
, next(inOther.next)
|
||||||
|
, prev(inOther.prev)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline typename MidiNoteList<Size>::Cell& MidiNoteList<Size>::Cell::operator= (const Cell& inOther)
|
||||||
|
{
|
||||||
|
note = inOther.note;
|
||||||
|
active = inOther.active;
|
||||||
|
next = inOther.next;
|
||||||
|
prev = inOther.prev;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ########################################################################## //
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline MidiNoteList<Size>::MidiNoteList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline MidiNoteList<Size>::~MidiNoteList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \brief Add a note, sorting it by time.
|
||||||
|
Call this when receiving a NoteOn event. This will add the new note as the tail
|
||||||
|
of the list.
|
||||||
|
*/
|
||||||
|
template<byte Size>
|
||||||
|
inline void MidiNoteList<Size>::add(const MidiNote& inNote)
|
||||||
|
{
|
||||||
|
if (mHead == 0)
|
||||||
|
{
|
||||||
|
mArray[0].note = inNote;
|
||||||
|
mArray[0].active = true;
|
||||||
|
mArray[0].next = 0;
|
||||||
|
mArray[0].prev = 0;
|
||||||
|
mHead = mArray;
|
||||||
|
mTail = mArray;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Find the first inactive cell, and use it as tail.
|
||||||
|
Cell* const oldTail = mTail;
|
||||||
|
Cell* const newTail = getFirstEmptyCell();
|
||||||
|
|
||||||
|
newTail->active = true;
|
||||||
|
newTail->note = inNote;
|
||||||
|
|
||||||
|
oldTail->next = newTail;
|
||||||
|
newTail->prev = oldTail;
|
||||||
|
newTail->next = 0;
|
||||||
|
mTail = newTail;
|
||||||
|
}
|
||||||
|
mSize++;
|
||||||
|
print();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Remove a note
|
||||||
|
Call this when receiving a NoteOff event.
|
||||||
|
*/
|
||||||
|
template<byte Size>
|
||||||
|
inline void MidiNoteList<Size>::remove(byte inPitch)
|
||||||
|
{
|
||||||
|
if (mTail != 0)
|
||||||
|
{
|
||||||
|
for (Cell* it = mTail; it != 0; it = it->prev)
|
||||||
|
{
|
||||||
|
if (it->note.pitch == inPitch)
|
||||||
|
{
|
||||||
|
Cell* const prev = it->prev;
|
||||||
|
Cell* const next = it->next;
|
||||||
|
|
||||||
|
it->active = false;
|
||||||
|
it->next = 0;
|
||||||
|
it->prev = 0;
|
||||||
|
|
||||||
|
// Reconnect both ends
|
||||||
|
if (it == mHead)
|
||||||
|
{
|
||||||
|
//AVR_ASSERT(prev == 0);
|
||||||
|
mHead = next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//AVR_ASSERT(prev != 0);
|
||||||
|
prev->next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it == mTail)
|
||||||
|
{
|
||||||
|
//AVR_ASSERT(next == 0);
|
||||||
|
mTail = prev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//AVR_ASSERT(next != 0);
|
||||||
|
next->prev = prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
mSize--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \brief Get a note at an arbitrary position
|
||||||
|
This can be interesting for duo/multi/polyphony operations.
|
||||||
|
*/
|
||||||
|
template<byte Size>
|
||||||
|
inline bool MidiNoteList<Size>::get(byte inIndex, byte& outPitch) const
|
||||||
|
{
|
||||||
|
if (mTail)
|
||||||
|
{
|
||||||
|
const Cell* it = mTail;
|
||||||
|
for (byte i = 0; i < inIndex; ++i)
|
||||||
|
{
|
||||||
|
if (it->prev)
|
||||||
|
{
|
||||||
|
it = it->prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print();
|
||||||
|
//AVR_LOG("Index " << inIndex << ": " << it->note.pitch);
|
||||||
|
|
||||||
|
outPitch = it->note.pitch;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Get the last active note played
|
||||||
|
This implements the Mono Last playing mode.
|
||||||
|
*/
|
||||||
|
template<byte Size>
|
||||||
|
inline bool MidiNoteList<Size>::getLast(byte& outPitch) const
|
||||||
|
{
|
||||||
|
if (!mTail)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
outPitch = mTail->note.pitch;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Get the highest pitched active note
|
||||||
|
This implements the Mono High playing mode.
|
||||||
|
*/
|
||||||
|
template<byte Size>
|
||||||
|
inline bool MidiNoteList<Size>::getHigh(byte& outPitch) const
|
||||||
|
{
|
||||||
|
if (!mTail)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
outPitch = 0;
|
||||||
|
const Cell* it = mTail;
|
||||||
|
for (byte i = 0; i < mSize; ++i)
|
||||||
|
{
|
||||||
|
if (it->note.pitch > outPitch)
|
||||||
|
{
|
||||||
|
outPitch = it->note.pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it->prev)
|
||||||
|
{
|
||||||
|
it = it->prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Get the lowest pitched active note
|
||||||
|
This implements the Mono Low playing mode.
|
||||||
|
*/
|
||||||
|
template<byte Size>
|
||||||
|
inline bool MidiNoteList<Size>::getLow(byte& outPitch) const
|
||||||
|
{
|
||||||
|
if (!mTail)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
outPitch = 0xff;
|
||||||
|
const Cell* it = mTail;
|
||||||
|
for (byte i = 0; i < mSize; ++i)
|
||||||
|
{
|
||||||
|
if (it->note.pitch < outPitch)
|
||||||
|
{
|
||||||
|
outPitch = it->note.pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it->prev)
|
||||||
|
{
|
||||||
|
it = it->prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline bool MidiNoteList<Size>::empty() const
|
||||||
|
{
|
||||||
|
return mSize == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \brief Get the number of active notes.
|
||||||
|
*/
|
||||||
|
template<byte Size>
|
||||||
|
inline byte MidiNoteList<Size>::size() const
|
||||||
|
{
|
||||||
|
return mSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Private implementations, for internal use only.
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline typename MidiNoteList<Size>::Cell* MidiNoteList<Size>::getFirstEmptyCell()
|
||||||
|
{
|
||||||
|
for (byte i = 0; i < Size; ++i)
|
||||||
|
{
|
||||||
|
if (mArray[i].active == false)
|
||||||
|
{
|
||||||
|
return mArray + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<byte Size>
|
||||||
|
inline void MidiNoteList<Size>::print() const
|
||||||
|
{
|
||||||
|
//#ifndef NDEBUG
|
||||||
|
// AVR_DBG("Note List: [ ");
|
||||||
|
// if (mHead)
|
||||||
|
// {
|
||||||
|
// for (const Cell* it = mHead; it != 0; it = it->next)
|
||||||
|
// {
|
||||||
|
// AVR_DBG(it->note.pitch);
|
||||||
|
// if (it->next)
|
||||||
|
// AVR_DBG(" -> ");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// AVR_LOG(" ]");
|
||||||
|
//#endif
|
||||||
|
}
|
||||||
108
main/libraries/MIDI/examples/MIDI_SimpleSynth/pitches.h
Normal file
108
main/libraries/MIDI/examples/MIDI_SimpleSynth/pitches.h
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/*************************************************
|
||||||
|
* Public Constants
|
||||||
|
*************************************************/
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define NOTE_B0 31
|
||||||
|
#define NOTE_C1 33
|
||||||
|
#define NOTE_CS1 35
|
||||||
|
#define NOTE_D1 37
|
||||||
|
#define NOTE_DS1 39
|
||||||
|
#define NOTE_E1 41
|
||||||
|
#define NOTE_F1 44
|
||||||
|
#define NOTE_FS1 46
|
||||||
|
#define NOTE_G1 49
|
||||||
|
#define NOTE_GS1 52
|
||||||
|
#define NOTE_A1 55
|
||||||
|
#define NOTE_AS1 58
|
||||||
|
#define NOTE_B1 62
|
||||||
|
#define NOTE_C2 65
|
||||||
|
#define NOTE_CS2 69
|
||||||
|
#define NOTE_D2 73
|
||||||
|
#define NOTE_DS2 78
|
||||||
|
#define NOTE_E2 82
|
||||||
|
#define NOTE_F2 87
|
||||||
|
#define NOTE_FS2 93
|
||||||
|
#define NOTE_G2 98
|
||||||
|
#define NOTE_GS2 104
|
||||||
|
#define NOTE_A2 110
|
||||||
|
#define NOTE_AS2 117
|
||||||
|
#define NOTE_B2 123
|
||||||
|
#define NOTE_C3 131
|
||||||
|
#define NOTE_CS3 139
|
||||||
|
#define NOTE_D3 147
|
||||||
|
#define NOTE_DS3 156
|
||||||
|
#define NOTE_E3 165
|
||||||
|
#define NOTE_F3 175
|
||||||
|
#define NOTE_FS3 185
|
||||||
|
#define NOTE_G3 196
|
||||||
|
#define NOTE_GS3 208
|
||||||
|
#define NOTE_A3 220
|
||||||
|
#define NOTE_AS3 233
|
||||||
|
#define NOTE_B3 247
|
||||||
|
#define NOTE_C4 262
|
||||||
|
#define NOTE_CS4 277
|
||||||
|
#define NOTE_D4 294
|
||||||
|
#define NOTE_DS4 311
|
||||||
|
#define NOTE_E4 330
|
||||||
|
#define NOTE_F4 349
|
||||||
|
#define NOTE_FS4 370
|
||||||
|
#define NOTE_G4 392
|
||||||
|
#define NOTE_GS4 415
|
||||||
|
#define NOTE_A4 440
|
||||||
|
#define NOTE_AS4 466
|
||||||
|
#define NOTE_B4 494
|
||||||
|
#define NOTE_C5 523
|
||||||
|
#define NOTE_CS5 554
|
||||||
|
#define NOTE_D5 587
|
||||||
|
#define NOTE_DS5 622
|
||||||
|
#define NOTE_E5 659
|
||||||
|
#define NOTE_F5 698
|
||||||
|
#define NOTE_FS5 740
|
||||||
|
#define NOTE_G5 784
|
||||||
|
#define NOTE_GS5 831
|
||||||
|
#define NOTE_A5 880
|
||||||
|
#define NOTE_AS5 932
|
||||||
|
#define NOTE_B5 988
|
||||||
|
#define NOTE_C6 1047
|
||||||
|
#define NOTE_CS6 1109
|
||||||
|
#define NOTE_D6 1175
|
||||||
|
#define NOTE_DS6 1245
|
||||||
|
#define NOTE_E6 1319
|
||||||
|
#define NOTE_F6 1397
|
||||||
|
#define NOTE_FS6 1480
|
||||||
|
#define NOTE_G6 1568
|
||||||
|
#define NOTE_GS6 1661
|
||||||
|
#define NOTE_A6 1760
|
||||||
|
#define NOTE_AS6 1865
|
||||||
|
#define NOTE_B6 1976
|
||||||
|
#define NOTE_C7 2093
|
||||||
|
#define NOTE_CS7 2217
|
||||||
|
#define NOTE_D7 2349
|
||||||
|
#define NOTE_DS7 2489
|
||||||
|
#define NOTE_E7 2637
|
||||||
|
#define NOTE_F7 2794
|
||||||
|
#define NOTE_FS7 2960
|
||||||
|
#define NOTE_G7 3136
|
||||||
|
#define NOTE_GS7 3322
|
||||||
|
#define NOTE_A7 3520
|
||||||
|
#define NOTE_AS7 3729
|
||||||
|
#define NOTE_B7 3951
|
||||||
|
#define NOTE_C8 4186
|
||||||
|
#define NOTE_CS8 4435
|
||||||
|
#define NOTE_D8 4699
|
||||||
|
#define NOTE_DS8 4978
|
||||||
|
|
||||||
|
static const uint16_t sNotePitches[] = {
|
||||||
|
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1,
|
||||||
|
NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2,
|
||||||
|
NOTE_DS2, NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2,
|
||||||
|
NOTE_B2, NOTE_C3, NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3,
|
||||||
|
NOTE_G3, NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4,
|
||||||
|
NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4,
|
||||||
|
NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5,
|
||||||
|
NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6,
|
||||||
|
NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6,
|
||||||
|
NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7,
|
||||||
|
NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8,
|
||||||
|
};
|
||||||
112
main/libraries/MIDI/keywords.txt
Normal file
112
main/libraries/MIDI/keywords.txt
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#######################################
|
||||||
|
# Syntax Coloring Map For Test
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Datatypes (KEYWORD1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
MIDI KEYWORD1
|
||||||
|
MIDI.h KEYWORD1
|
||||||
|
MidiInterface KEYWORD1
|
||||||
|
DefaultSettings KEYWORD1
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Methods and Functions (KEYWORD2)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
send KEYWORD2
|
||||||
|
sendNoteOn KEYWORD2
|
||||||
|
sendNoteOff KEYWORD2
|
||||||
|
sendProgramChange KEYWORD2
|
||||||
|
sendControlChange KEYWORD2
|
||||||
|
sendPitchBend KEYWORD2
|
||||||
|
sendPolyPressure KEYWORD2
|
||||||
|
sendAfterTouch KEYWORD2
|
||||||
|
sendSysEx KEYWORD2
|
||||||
|
sendTimeCodeQuarterFrame KEYWORD2
|
||||||
|
sendSongPosition KEYWORD2
|
||||||
|
sendSongSelect KEYWORD2
|
||||||
|
sendTuneRequest KEYWORD2
|
||||||
|
sendRealTime KEYWORD2
|
||||||
|
begin KEYWORD2
|
||||||
|
read KEYWORD2
|
||||||
|
getType KEYWORD2
|
||||||
|
getChannel KEYWORD2
|
||||||
|
getData1 KEYWORD2
|
||||||
|
getData2 KEYWORD2
|
||||||
|
getSysExArray KEYWORD2
|
||||||
|
getFilterMode KEYWORD2
|
||||||
|
getThruState KEYWORD2
|
||||||
|
getInputChannel KEYWORD2
|
||||||
|
check KEYWORD2
|
||||||
|
delMsg KEYWORD2
|
||||||
|
delSysEx KEYWORD2
|
||||||
|
setInputChannel KEYWORD2
|
||||||
|
setStatus KEYWORD2
|
||||||
|
turnThruOn KEYWORD2
|
||||||
|
turnThruOff KEYWORD2
|
||||||
|
setThruFilterMode KEYWORD2
|
||||||
|
disconnectCallbackFromType KEYWORD2
|
||||||
|
setHandleNoteOff KEYWORD2
|
||||||
|
setHandleNoteOn KEYWORD2
|
||||||
|
setHandleAfterTouchPoly KEYWORD2
|
||||||
|
setHandleControlChange KEYWORD2
|
||||||
|
setHandleProgramChange KEYWORD2
|
||||||
|
setHandleAfterTouchChannel KEYWORD2
|
||||||
|
setHandlePitchBend KEYWORD2
|
||||||
|
setHandleSystemExclusive KEYWORD2
|
||||||
|
setHandleTimeCodeQuarterFrame KEYWORD2
|
||||||
|
setHandleSongPosition KEYWORD2
|
||||||
|
setHandleSongSelect KEYWORD2
|
||||||
|
setHandleTuneRequest KEYWORD2
|
||||||
|
setHandleClock KEYWORD2
|
||||||
|
setHandleStart KEYWORD2
|
||||||
|
setHandleContinue KEYWORD2
|
||||||
|
setHandleStop KEYWORD2
|
||||||
|
setHandleActiveSensing KEYWORD2
|
||||||
|
setHandleSystemReset KEYWORD2
|
||||||
|
getTypeFromStatusByte KEYWORD2
|
||||||
|
encodeSysEx KEYWORD2
|
||||||
|
decodeSysEx KEYWORD2
|
||||||
|
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Instances (KEYWORD2)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Constants (LITERAL1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
# Namespace, considering it as a literal
|
||||||
|
midi LITERAL1
|
||||||
|
|
||||||
|
NoteOff LITERAL1
|
||||||
|
NoteOn LITERAL1
|
||||||
|
AfterTouchPoly LITERAL1
|
||||||
|
ControlChange LITERAL1
|
||||||
|
ProgramChange LITERAL1
|
||||||
|
AfterTouchChannel LITERAL1
|
||||||
|
PitchBend LITERAL1
|
||||||
|
SystemExclusive LITERAL1
|
||||||
|
TimeCodeQuarterFrame LITERAL1
|
||||||
|
SongPosition LITERAL1
|
||||||
|
SongSelect LITERAL1
|
||||||
|
TuneRequest LITERAL1
|
||||||
|
Clock LITERAL1
|
||||||
|
Start LITERAL1
|
||||||
|
Stop LITERAL1
|
||||||
|
Continue LITERAL1
|
||||||
|
ActiveSensing LITERAL1
|
||||||
|
SystemReset LITERAL1
|
||||||
|
InvalidType LITERAL1
|
||||||
|
Off LITERAL1
|
||||||
|
Full LITERAL1
|
||||||
|
SameChannel LITERAL1
|
||||||
|
DifferentChannel LITERAL1
|
||||||
|
MIDI_CHANNEL_OMNI LITERAL1
|
||||||
|
MIDI_CHANNEL_OFF LITERAL1
|
||||||
|
MIDI_CREATE_INSTANCE LITERAL1
|
||||||
|
MIDI_CREATE_DEFAULT_INSTANCE LITERAL1
|
||||||
|
MIDI_CREATE_CUSTOM_INSTANCE LITERAL1
|
||||||
193
main/libraries/MIDI/midi_Defs.h
Normal file
193
main/libraries/MIDI/midi_Defs.h
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
/*!
|
||||||
|
* @file midi_Defs.h
|
||||||
|
* Project Arduino MIDI Library
|
||||||
|
* @brief MIDI Library for the Arduino - Definitions
|
||||||
|
* @version 4.2
|
||||||
|
* @author Francois Best
|
||||||
|
* @date 24/02/11
|
||||||
|
* @license GPL v3.0 - Copyright Forty Seven Effects 2014
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "midi_Namespace.h"
|
||||||
|
|
||||||
|
#if ARDUINO
|
||||||
|
#include <Arduino.h>
|
||||||
|
#else
|
||||||
|
#include <inttypes.h>
|
||||||
|
typedef uint8_t byte;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BEGIN_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define MIDI_CHANNEL_OMNI 0
|
||||||
|
#define MIDI_CHANNEL_OFF 17 // and over
|
||||||
|
|
||||||
|
#define MIDI_PITCHBEND_MIN -8192
|
||||||
|
#define MIDI_PITCHBEND_MAX 8191
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Type definitions
|
||||||
|
|
||||||
|
typedef byte StatusByte;
|
||||||
|
typedef byte DataByte;
|
||||||
|
typedef byte Channel;
|
||||||
|
typedef byte FilterMode;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! Enumeration of MIDI types */
|
||||||
|
enum MidiType
|
||||||
|
{
|
||||||
|
InvalidType = 0x00, ///< For notifying errors
|
||||||
|
NoteOff = 0x80, ///< Note Off
|
||||||
|
NoteOn = 0x90, ///< Note On
|
||||||
|
AfterTouchPoly = 0xA0, ///< Polyphonic AfterTouch
|
||||||
|
ControlChange = 0xB0, ///< Control Change / Channel Mode
|
||||||
|
ProgramChange = 0xC0, ///< Program Change
|
||||||
|
AfterTouchChannel = 0xD0, ///< Channel (monophonic) AfterTouch
|
||||||
|
PitchBend = 0xE0, ///< Pitch Bend
|
||||||
|
SystemExclusive = 0xF0, ///< System Exclusive
|
||||||
|
TimeCodeQuarterFrame = 0xF1, ///< System Common - MIDI Time Code Quarter Frame
|
||||||
|
SongPosition = 0xF2, ///< System Common - Song Position Pointer
|
||||||
|
SongSelect = 0xF3, ///< System Common - Song Select
|
||||||
|
TuneRequest = 0xF6, ///< System Common - Tune Request
|
||||||
|
Clock = 0xF8, ///< System Real Time - Timing Clock
|
||||||
|
Start = 0xFA, ///< System Real Time - Start
|
||||||
|
Continue = 0xFB, ///< System Real Time - Continue
|
||||||
|
Stop = 0xFC, ///< System Real Time - Stop
|
||||||
|
ActiveSensing = 0xFE, ///< System Real Time - Active Sensing
|
||||||
|
SystemReset = 0xFF, ///< System Real Time - System Reset
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! Enumeration of Thru filter modes */
|
||||||
|
enum MidiFilterMode
|
||||||
|
{
|
||||||
|
Off = 0, ///< Thru disabled (nothing passes through).
|
||||||
|
Full = 1, ///< Fully enabled Thru (every incoming message is sent back).
|
||||||
|
SameChannel = 2, ///< Only the messages on the Input Channel will be sent back.
|
||||||
|
DifferentChannel = 3, ///< All the messages but the ones on the Input Channel will be sent back.
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \brief Enumeration of Control Change command numbers.
|
||||||
|
See the detailed controllers numbers & description here:
|
||||||
|
http://www.somascape.org/midi/tech/spec.html#ctrlnums
|
||||||
|
*/
|
||||||
|
enum MidiControlChangeNumber
|
||||||
|
{
|
||||||
|
// High resolution Continuous Controllers MSB (+32 for LSB) ----------------
|
||||||
|
BankSelect = 0,
|
||||||
|
ModulationWheel = 1,
|
||||||
|
BreathController = 2,
|
||||||
|
// CC3 undefined
|
||||||
|
FootController = 4,
|
||||||
|
PortamentoTime = 5,
|
||||||
|
DataEntry = 6,
|
||||||
|
ChannelVolume = 7,
|
||||||
|
Balance = 8,
|
||||||
|
// CC9 undefined
|
||||||
|
Pan = 10,
|
||||||
|
ExpressionController = 11,
|
||||||
|
EffectControl1 = 12,
|
||||||
|
EffectControl2 = 13,
|
||||||
|
// CC14 undefined
|
||||||
|
// CC15 undefined
|
||||||
|
GeneralPurposeController1 = 16,
|
||||||
|
GeneralPurposeController2 = 17,
|
||||||
|
GeneralPurposeController3 = 18,
|
||||||
|
GeneralPurposeController4 = 19,
|
||||||
|
|
||||||
|
// Switches ----------------------------------------------------------------
|
||||||
|
Sustain = 64,
|
||||||
|
Portamento = 65,
|
||||||
|
Sostenuto = 66,
|
||||||
|
SoftPedal = 67,
|
||||||
|
Legato = 68,
|
||||||
|
Hold = 69,
|
||||||
|
|
||||||
|
// Low resolution continuous controllers -----------------------------------
|
||||||
|
SoundController1 = 70, ///< Synth: Sound Variation FX: Exciter On/Off
|
||||||
|
SoundController2 = 71, ///< Synth: Harmonic Content FX: Compressor On/Off
|
||||||
|
SoundController3 = 72, ///< Synth: Release Time FX: Distortion On/Off
|
||||||
|
SoundController4 = 73, ///< Synth: Attack Time FX: EQ On/Off
|
||||||
|
SoundController5 = 74, ///< Synth: Brightness FX: Expander On/Off
|
||||||
|
SoundController6 = 75, ///< Synth: Decay Time FX: Reverb On/Off
|
||||||
|
SoundController7 = 76, ///< Synth: Vibrato Rate FX: Delay On/Off
|
||||||
|
SoundController8 = 77, ///< Synth: Vibrato Depth FX: Pitch Transpose On/Off
|
||||||
|
SoundController9 = 78, ///< Synth: Vibrato Delay FX: Flange/Chorus On/Off
|
||||||
|
SoundController10 = 79, ///< Synth: Undefined FX: Special Effects On/Off
|
||||||
|
GeneralPurposeController5 = 80,
|
||||||
|
GeneralPurposeController6 = 81,
|
||||||
|
GeneralPurposeController7 = 82,
|
||||||
|
GeneralPurposeController8 = 83,
|
||||||
|
PortamentoControl = 84,
|
||||||
|
// CC85 to CC90 undefined
|
||||||
|
Effects1 = 91, ///< Reverb send level
|
||||||
|
Effects2 = 92, ///< Tremolo depth
|
||||||
|
Effects3 = 93, ///< Chorus send level
|
||||||
|
Effects4 = 94, ///< Celeste depth
|
||||||
|
Effects5 = 95, ///< Phaser depth
|
||||||
|
|
||||||
|
// Channel Mode messages ---------------------------------------------------
|
||||||
|
AllSoundOff = 120,
|
||||||
|
ResetAllControllers = 121,
|
||||||
|
LocalControl = 122,
|
||||||
|
AllNotesOff = 123,
|
||||||
|
OmniModeOff = 124,
|
||||||
|
OmniModeOn = 125,
|
||||||
|
MonoModeOn = 126,
|
||||||
|
PolyModeOn = 127
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*! \brief Create an instance of the library attached to a serial port.
|
||||||
|
You can use HardwareSerial or SoftwareSerial for the serial port.
|
||||||
|
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
|
||||||
|
Then call midi2.begin(), midi2.read() etc..
|
||||||
|
*/
|
||||||
|
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
|
||||||
|
midi::MidiInterface<Type> Name((Type&)SerialPort);
|
||||||
|
|
||||||
|
#if defined(ARDUINO_SAM_DUE) || defined(USBCON)
|
||||||
|
// Leonardo, Due and other USB boards use Serial1 by default.
|
||||||
|
#define MIDI_CREATE_DEFAULT_INSTANCE() \
|
||||||
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
|
||||||
|
#else
|
||||||
|
/*! \brief Create an instance of the library with default name, serial port
|
||||||
|
and settings, for compatibility with sketches written with pre-v4.2 MIDI Lib,
|
||||||
|
or if you don't bother using custom names, serial port or settings.
|
||||||
|
*/
|
||||||
|
#define MIDI_CREATE_DEFAULT_INSTANCE() \
|
||||||
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! \brief Create an instance of the library attached to a serial port with
|
||||||
|
custom settings.
|
||||||
|
@see DefaultSettings
|
||||||
|
@see MIDI_CREATE_INSTANCE
|
||||||
|
*/
|
||||||
|
#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
|
||||||
|
midi::MidiInterface<Type, Settings> Name((Type&)SerialPort);
|
||||||
|
|
||||||
|
END_MIDI_NAMESPACE
|
||||||
81
main/libraries/MIDI/midi_Message.h
Normal file
81
main/libraries/MIDI/midi_Message.h
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*!
|
||||||
|
* @file midi_Message.h
|
||||||
|
* Project Arduino MIDI Library
|
||||||
|
* @brief MIDI Library for the Arduino - Message struct definition
|
||||||
|
* @version 4.2
|
||||||
|
* @author Francois Best
|
||||||
|
* @date 11/06/14
|
||||||
|
* @license GPL v3.0 - Copyright Forty Seven Effects 2014
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "midi_Namespace.h"
|
||||||
|
#include "midi_Defs.h"
|
||||||
|
|
||||||
|
BEGIN_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
/*! The Message structure contains decoded data of a MIDI message
|
||||||
|
read from the serial port with read()
|
||||||
|
*/
|
||||||
|
template<unsigned SysExMaxSize>
|
||||||
|
struct Message
|
||||||
|
{
|
||||||
|
/*! The maximum size for the System Exclusive array.
|
||||||
|
*/
|
||||||
|
static const unsigned sSysExMaxSize = SysExMaxSize;
|
||||||
|
|
||||||
|
/*! The MIDI channel on which the message was recieved.
|
||||||
|
\n Value goes from 1 to 16.
|
||||||
|
*/
|
||||||
|
Channel channel;
|
||||||
|
|
||||||
|
/*! The type of the message
|
||||||
|
(see the MidiType enum for types reference)
|
||||||
|
*/
|
||||||
|
MidiType type;
|
||||||
|
|
||||||
|
/*! The first data byte.
|
||||||
|
\n Value goes from 0 to 127.
|
||||||
|
*/
|
||||||
|
DataByte data1;
|
||||||
|
|
||||||
|
/*! The second data byte.
|
||||||
|
If the message is only 2 bytes long, this one is null.
|
||||||
|
\n Value goes from 0 to 127.
|
||||||
|
*/
|
||||||
|
DataByte data2;
|
||||||
|
|
||||||
|
/*! System Exclusive dedicated byte array.
|
||||||
|
\n Array length is stocked on 16 bits,
|
||||||
|
in data1 (LSB) and data2 (MSB)
|
||||||
|
*/
|
||||||
|
DataByte sysexArray[sSysExMaxSize];
|
||||||
|
|
||||||
|
/*! This boolean indicates if the message is valid or not.
|
||||||
|
There is no channel consideration here,
|
||||||
|
validity means the message respects the MIDI norm.
|
||||||
|
*/
|
||||||
|
bool valid;
|
||||||
|
|
||||||
|
inline unsigned getSysExSize() const
|
||||||
|
{
|
||||||
|
const unsigned size = unsigned(data2) << 8 | data1;
|
||||||
|
return size > sSysExMaxSize ? sSysExMaxSize : size;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
END_MIDI_NAMESPACE
|
||||||
34
main/libraries/MIDI/midi_Namespace.h
Normal file
34
main/libraries/MIDI/midi_Namespace.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*!
|
||||||
|
* @file midi_Namespace.h
|
||||||
|
* Project Arduino MIDI Library
|
||||||
|
* @brief MIDI Library for the Arduino - Namespace declaration
|
||||||
|
* @version 4.2
|
||||||
|
* @author Francois Best
|
||||||
|
* @date 24/02/11
|
||||||
|
* @license GPL v3.0 - Copyright Forty Seven Effects 2014
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define MIDI_NAMESPACE midi
|
||||||
|
#define BEGIN_MIDI_NAMESPACE namespace MIDI_NAMESPACE {
|
||||||
|
#define END_MIDI_NAMESPACE }
|
||||||
|
|
||||||
|
#define USING_NAMESPACE_MIDI using namespace MIDI_NAMESPACE;
|
||||||
|
|
||||||
|
BEGIN_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
END_MIDI_NAMESPACE
|
||||||
76
main/libraries/MIDI/midi_Settings.h
Normal file
76
main/libraries/MIDI/midi_Settings.h
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*!
|
||||||
|
* @file midi_Settings.h
|
||||||
|
* Project Arduino MIDI Library
|
||||||
|
* @brief MIDI Library for the Arduino - Settings
|
||||||
|
* @version 4.2
|
||||||
|
* @author Francois Best
|
||||||
|
* @date 24/02/11
|
||||||
|
* @license GPL v3.0 - Copyright Forty Seven Effects 2014
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "midi_Defs.h"
|
||||||
|
|
||||||
|
BEGIN_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
/*! \brief Default Settings for the MIDI Library.
|
||||||
|
|
||||||
|
To change the default settings, don't edit them there, create a subclass and
|
||||||
|
override the values in that subclass, then use the MIDI_CREATE_CUSTOM_INSTANCE
|
||||||
|
macro to create your instance. The settings you don't override will keep their
|
||||||
|
default value. Eg:
|
||||||
|
\code{.cpp}
|
||||||
|
struct MySettings : public midi::DefaultSettings
|
||||||
|
{
|
||||||
|
static const bool UseRunningStatus = false; // Messes with my old equipment!
|
||||||
|
};
|
||||||
|
|
||||||
|
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial2, midi, MySettings);
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
struct DefaultSettings
|
||||||
|
{
|
||||||
|
/*! Running status enables short messages when sending multiple values
|
||||||
|
of the same type and channel.\n
|
||||||
|
Set to 0 if you have troubles controlling your hardware.
|
||||||
|
*/
|
||||||
|
static const bool UseRunningStatus = true;
|
||||||
|
|
||||||
|
/* NoteOn with 0 velocity should be handled as NoteOf.\n
|
||||||
|
Set to 1 to get NoteOff events when receiving null-velocity NoteOn messages.\n
|
||||||
|
Set to 0 to get NoteOn events when receiving null-velocity NoteOn messages.
|
||||||
|
*/
|
||||||
|
static const bool HandleNullVelocityNoteOnAsNoteOff = true;
|
||||||
|
|
||||||
|
// Setting this to 1 will make MIDI.read parse only one byte of data for each
|
||||||
|
// call when data is available. This can speed up your application if receiving
|
||||||
|
// a lot of traffic, but might induce MIDI Thru and treatment latency.
|
||||||
|
static const bool Use1ByteParsing = true;
|
||||||
|
|
||||||
|
/*! Override the default MIDI baudrate to transmit over USB serial, to
|
||||||
|
a decoding program such as Hairless MIDI (set baudrate to 115200)\n
|
||||||
|
http://projectgus.github.io/hairless-midiserial/
|
||||||
|
*/
|
||||||
|
static const long BaudRate = 31250;
|
||||||
|
|
||||||
|
/*! Maximum size of SysEx receivable. Decrease to save RAM if you don't expect
|
||||||
|
to receive SysEx, or adjust accordingly.
|
||||||
|
*/
|
||||||
|
static const unsigned SysExMaxSize = 128;
|
||||||
|
};
|
||||||
|
|
||||||
|
END_MIDI_NAMESPACE
|
||||||
115
tools/testing/config.h
Normal file
115
tools/testing/config.h
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
* @file config.h
|
||||||
|
* Project axefx.de MIDI Borad TWO
|
||||||
|
* @brief Config-File for Testing-Tool.
|
||||||
|
* Here you have to modify your used Arduino-Pins
|
||||||
|
* and if you like to use the LCD-Display.
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author Bastian Buehrig
|
||||||
|
* @date 15/02/15
|
||||||
|
* license GPL axefx.de - 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Config_h
|
||||||
|
#define Config_h
|
||||||
|
|
||||||
|
|
||||||
|
// Include Configuration
|
||||||
|
// If you don't want a feature, switch it of with a '0'
|
||||||
|
#define USE_LCD 1
|
||||||
|
|
||||||
|
|
||||||
|
// ============== Pin Configuration ==============
|
||||||
|
//
|
||||||
|
// LCD-Pin Definitions
|
||||||
|
#if USE_LCD==1
|
||||||
|
#define LCD_D7 44
|
||||||
|
#define LCD_D6 45
|
||||||
|
#define LCD_D5 46
|
||||||
|
#define LCD_D4 47
|
||||||
|
#define LCD_E 48
|
||||||
|
#define LCD_RS 49
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// LED und Switch Pins
|
||||||
|
#define SWT_MAX 23 // How many switches (and LEDs) does your MIDI-Board have?
|
||||||
|
|
||||||
|
#define SWT01 2
|
||||||
|
#define LED01 3
|
||||||
|
#define SWT02 4
|
||||||
|
#define LED02 5
|
||||||
|
#define SWT03 6
|
||||||
|
#define LED03 7
|
||||||
|
#define SWT04 8
|
||||||
|
#define LED04 9
|
||||||
|
#define SWT05 10
|
||||||
|
#define LED05 11
|
||||||
|
#define SWT06 12
|
||||||
|
#define LED06 13
|
||||||
|
|
||||||
|
#define SWT07 22
|
||||||
|
#define LED07 24
|
||||||
|
#define SWT08 26
|
||||||
|
#define LED08 28
|
||||||
|
#define SWT09 30
|
||||||
|
#define LED09 32
|
||||||
|
#define SWT10 34
|
||||||
|
#define LED10 36
|
||||||
|
#define SWT11 38
|
||||||
|
#define LED11 40
|
||||||
|
|
||||||
|
#define SWT12 23
|
||||||
|
#define LED12 25
|
||||||
|
#define SWT13 27
|
||||||
|
#define LED13 29
|
||||||
|
#define SWT14 31
|
||||||
|
#define LED14 33
|
||||||
|
#define SWT15 35
|
||||||
|
#define LED15 37
|
||||||
|
#define SWT16 39
|
||||||
|
#define LED16 41
|
||||||
|
|
||||||
|
#define SWT17 42
|
||||||
|
#define LED17 43
|
||||||
|
#define SWT18 A8
|
||||||
|
#define LED18 A9
|
||||||
|
#define SWT19 A10
|
||||||
|
#define LED19 A11
|
||||||
|
#define SWT20 A12
|
||||||
|
#define LED20 A13
|
||||||
|
#define SWT21 A14
|
||||||
|
#define LED21 A15
|
||||||
|
|
||||||
|
#define SWT22 A6
|
||||||
|
#define LED22 A7
|
||||||
|
#define SWT23 14
|
||||||
|
#define LED23 15
|
||||||
|
|
||||||
|
#define SWT24 16
|
||||||
|
#define LED24 17
|
||||||
|
#define SWT25 20
|
||||||
|
#define LED25 21
|
||||||
|
#define SWT26 50
|
||||||
|
#define LED26 51
|
||||||
|
#define SWT27 52
|
||||||
|
#define LED27 99
|
||||||
|
#define SWT28 53
|
||||||
|
#define LED28 99
|
||||||
|
|
||||||
|
|
||||||
|
// Expression-Pedal Pins
|
||||||
|
#define EXP01 A0
|
||||||
|
#define EXP02 A1
|
||||||
|
|
||||||
|
// Layer-LEDs
|
||||||
|
#define LAY_LED01 A2
|
||||||
|
#define LAY_LED02 A3
|
||||||
|
#define LAY_LED03 A4
|
||||||
|
#define LAY_LED04 A5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,24 +1,105 @@
|
|||||||
|
/**
|
||||||
|
* @file testing.ino
|
||||||
|
* Project axefx.de MIDI Borad TWO
|
||||||
|
* @brief Testing-Tool for test all your switches, leds and
|
||||||
|
* LCD-Display (if you'll use one).
|
||||||
|
* It will turn on and of all your LEDs. After it,
|
||||||
|
* you can test your switches to light up the LEDs manually.
|
||||||
|
* Additionally you can see some Informations on your LCD-Display
|
||||||
|
* and it writes the same text in the serial monitor.
|
||||||
|
* @version 1.0.0
|
||||||
|
* @author Bastian Buehrig
|
||||||
|
* @date 16/02/15
|
||||||
|
* license GPL axefx.de - 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
// LCD-Display includes
|
||||||
|
#if USE_LCD==1
|
||||||
|
#include <LiquidCrystal.h>
|
||||||
|
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Pin-Definitions - you have to modify this list, if you like to use more or less than 23 Switches!
|
||||||
|
byte swt_pins[SWT_MAX] = { SWT01, SWT02, SWT03, SWT04, SWT05, SWT06, SWT07, SWT08, SWT09, SWT10,
|
||||||
|
SWT11, SWT12, SWT13, SWT14, SWT15, SWT16, SWT17, SWT18, SWT19, SWT20,
|
||||||
|
SWT21, SWT22, SWT23 }; // SWT24, SWT25, SWT26, SWT27, SWT28
|
||||||
|
|
||||||
|
byte led_pins[SWT_MAX] = { LED01, LED02, LED03, LED04, LED05, LED06, LED07, LED08, LED09, LED10,
|
||||||
|
LED11, LED12, LED13, LED14, LED15, LED16, LED17, LED18, LED19, LED20,
|
||||||
|
LED21, LED22, LED23 }; // LED24, LED25, LED26, LED27, LED28
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to initialize the pin-modes and
|
||||||
|
* switch on and off shortly all LEDs.
|
||||||
|
*
|
||||||
|
*/
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Init Serial Monitor for Informations...
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
for(int i=22; i <= 36; i=i+2) {
|
|
||||||
pinMode(i, INPUT);
|
|
||||||
pinMode(i+1, OUTPUT);
|
#if USE_LCD==1
|
||||||
|
// set up the LCD's number of columns and rows:
|
||||||
|
lcd.begin(16, 2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printInfo("Initialisation...");
|
||||||
|
|
||||||
|
|
||||||
|
// Setting Pin-Modes
|
||||||
|
for(byte i=0; i < SWT_MAX; i=i+1) {
|
||||||
|
pinMode(swt_pins[i], INPUT_PULLUP);
|
||||||
|
pinMode(led_pins[i], OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=22; i <= 36; i=i+2) {
|
|
||||||
digitalWrite(i+1, HIGH); // turn the LED on (HIGH is the voltage level)
|
// Turn LED on, then off
|
||||||
|
for(byte i=0; i < SWT_MAX; i=i+1) {
|
||||||
|
printInfo("LED " + String(i+1));
|
||||||
|
|
||||||
|
digitalWrite(led_pins[i], HIGH); // turn the LED on (HIGH is the voltage level)
|
||||||
delay(100); // wait for a second
|
delay(100); // wait for a second
|
||||||
digitalWrite(i+1, LOW); // turn the LED off by making the voltage LOW
|
digitalWrite(led_pins[i], LOW); // turn the LED off by making the voltage LOW
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main Loop-Function. Read out the Switch-States and
|
||||||
|
* if you press a switch, the Switch LED will be switch on
|
||||||
|
* during you are pressing the switch.
|
||||||
|
*
|
||||||
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
for(int i=22; i <= 36; i=i+2) {
|
for(byte i=0; i < SWT_MAX; i=i+1) {
|
||||||
byte actState = digitalRead(i);
|
byte actState = digitalRead(swt_pins[i]);
|
||||||
digitalWrite(i+1, actState);
|
digitalWrite(led_pins[i], !actState);
|
||||||
|
|
||||||
|
if(!actState) {
|
||||||
|
printInfo("Switch " + String(i+1) + " pressed!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to print out informations to Serial-Monitor and LCD-Dsiplay
|
||||||
|
*
|
||||||
|
* @param infoText Text to print out
|
||||||
|
*/
|
||||||
|
void printInfo(String infoText) {
|
||||||
|
Serial.println(infoText);
|
||||||
|
|
||||||
|
#if USE_LCD==1
|
||||||
|
lcd.print(infoText);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user