parent
e3843ac0c8
commit
6b291d988b
@ -0,0 +1,539 @@ |
||||
#ifndef NervousSuperMother_h |
||||
#define NervousSuperMother_h |
||||
|
||||
#include "hardware/HardwareControls.h" |
||||
// #include "display/Display.h"
|
||||
|
||||
/*
|
||||
* NervousSuperMother |
||||
* v0.1.0 beta |
||||
*/ |
||||
class NervousSuperMother{ |
||||
|
||||
private: |
||||
static NervousSuperMother *instance; |
||||
NervousSuperMother(); |
||||
|
||||
byte *inputs; |
||||
|
||||
byte ioNumber = 6; |
||||
byte currentInput = 0; |
||||
|
||||
byte analogResolution = 7; |
||||
|
||||
// Potentiometers
|
||||
unsigned int *potentiometers; |
||||
unsigned int *potentiometersPrevious; |
||||
byte potardIndex; |
||||
// For smoothing purposes
|
||||
unsigned int *potentiometersTemp; |
||||
byte *potentiometersReadings; |
||||
// Buttons
|
||||
bool *buttons; |
||||
byte buttonIndex; |
||||
bool *pushed; |
||||
// Encoders
|
||||
long *encoders; |
||||
long *encodersPrevious; |
||||
byte encoderIndex; |
||||
long *encodersMaxValue; |
||||
// Triggers
|
||||
byte triggerIndex; |
||||
|
||||
// Display
|
||||
String display_line_1; |
||||
String display_line_2; |
||||
String previous_display_line_1; |
||||
String previous_display_line_2; |
||||
|
||||
// Callbacks
|
||||
using PressCallback = void (*)(byte); |
||||
PressCallback *inputsPressCallback; |
||||
using LongPressCallback = void (*)(byte); |
||||
LongPressCallback *inputsLongPressCallback; |
||||
using DoublePressCallback = void (*)(byte); |
||||
DoublePressCallback *inputsDoublePressCallback; |
||||
elapsedMillis *inputsPressTime; |
||||
using PotentiometerChangeCallback = void (*)(byte, unsigned int, int); |
||||
PotentiometerChangeCallback *inputsPotentiometerChangeCallback; |
||||
using EncoderChangeCallback = void (*)(byte, long); |
||||
EncoderChangeCallback *inputsEncoderChangeCallback; |
||||
using TriggerCallback = void (*)(byte); |
||||
TriggerCallback *inputsTriggerCallback; |
||||
|
||||
|
||||
void readPotentiometer(byte inputIndex); |
||||
void readButton(byte inputIndex); |
||||
void readEncoder(byte inputIndex); |
||||
void readTrigger(byte inputIndex); |
||||
void refreshDisplay(); |
||||
|
||||
// Main clock
|
||||
elapsedMicros clockMain; |
||||
const unsigned int intervalClockMain = 10000; |
||||
|
||||
// Inputs clock
|
||||
const unsigned int intervalInputs = 500; |
||||
elapsedMicros clockInputs; |
||||
|
||||
public: |
||||
static NervousSuperMother *getInstance(); |
||||
void init(byte *inputs); |
||||
void update(); |
||||
int getInput(byte index); |
||||
int getAnalogMaxValue(); |
||||
int getAnalogMinValue(); |
||||
void iterateInputs(); |
||||
void readCurrentInput(); |
||||
void updateEncodeursMaxValue(byte index, long encoderMax); |
||||
void updateEncodeursValue(byte inputIndex, long encoderValue); |
||||
// void updateLine(byte line_nb, String line);
|
||||
|
||||
// Callbacks
|
||||
void setHandlePress(byte inputIndex, PressCallback fptr); |
||||
void setHandleLongPress(byte inputIndex, LongPressCallback fptr); |
||||
void setHandleDoublePress(byte inputIndex, DoublePressCallback fptr); |
||||
void setHandlePotentiometerChange(byte inputIndex, PotentiometerChangeCallback fptr); |
||||
void setHandleEncoderChange(byte inputIndex, EncoderChangeCallback fptr); |
||||
void setHandleTrigger(byte inputIndex, TriggerCallback fptr); |
||||
}; |
||||
|
||||
// Instance pre init
|
||||
NervousSuperMother * NervousSuperMother::instance = nullptr; |
||||
|
||||
/**
|
||||
* Constructor |
||||
*/ |
||||
inline NervousSuperMother::NervousSuperMother(){ |
||||
this->inputs = new byte[this->ioNumber]; |
||||
for(byte i = 0; i < this->ioNumber; i++){ |
||||
this->inputs[i] = 0; |
||||
} |
||||
|
||||
// Potentiometers
|
||||
this->potardIndex = 0; |
||||
this->potentiometers = new unsigned int[ANALOG_CONTROL_PINS]; |
||||
this->potentiometersPrevious = new unsigned int[ANALOG_CONTROL_PINS]; |
||||
this->potentiometersTemp = new unsigned int[ANALOG_CONTROL_PINS]; |
||||
this->potentiometersReadings = new byte[ANALOG_CONTROL_PINS]; |
||||
this->inputsPotentiometerChangeCallback = new PotentiometerChangeCallback[ANALOG_CONTROL_PINS]; |
||||
|
||||
for(byte i = 0; i < ANALOG_CONTROL_PINS; i++){ |
||||
this->potentiometers[i] = 0; |
||||
this->potentiometersPrevious[i] = 0; |
||||
this->potentiometersTemp[i] = 0; |
||||
this->potentiometersReadings[i] = 0; |
||||
this->inputsPotentiometerChangeCallback[i] = nullptr; |
||||
} |
||||
|
||||
// Buttons
|
||||
this->buttonIndex = 0; |
||||
this->buttons = new bool[BUTTON_PINS]; |
||||
this->pushed = new bool[BUTTON_PINS]; |
||||
this->inputsPressCallback = new PressCallback[BUTTON_PINS]; |
||||
this->inputsLongPressCallback = new DoublePressCallback[BUTTON_PINS]; |
||||
this->inputsDoublePressCallback = new LongPressCallback[BUTTON_PINS]; |
||||
this->inputsPressTime = new elapsedMillis[BUTTON_PINS]; |
||||
|
||||
for(byte i = 0; i < BUTTON_PINS; i++){ |
||||
this->buttons[i] = true; |
||||
this->pushed[i] = false; |
||||
this->inputsPressCallback[i] = nullptr; |
||||
this->inputsLongPressCallback[i] = nullptr; |
||||
this->inputsDoublePressCallback[i] = nullptr; |
||||
this->inputsPressTime[i] = 0; |
||||
} |
||||
|
||||
// Encoders
|
||||
this->encoderIndex = 0; |
||||
this->encoders = new long[NB_ENCODER]; |
||||
this->encodersPrevious = new long[NB_ENCODER]; |
||||
this->inputsEncoderChangeCallback = new EncoderChangeCallback[NB_ENCODER]; |
||||
this->encodersMaxValue = new long[NB_ENCODER]; |
||||
|
||||
for(byte i = 0; i < NB_ENCODER; i++){ |
||||
this->encoders[i] = 0; |
||||
this->encodersPrevious[i] = -999; |
||||
this->inputsEncoderChangeCallback[i] = nullptr; |
||||
this->encodersMaxValue[i] = 0; |
||||
} |
||||
|
||||
// Triggers
|
||||
this->triggerIndex = 0; |
||||
this->inputsTriggerCallback = new TriggerCallback[TRIGGER_PINS]; |
||||
for(byte i = 0; i < TRIGGER_PINS; i++){ |
||||
this->inputsTriggerCallback[i] = nullptr; |
||||
} |
||||
|
||||
// // Display
|
||||
// this->display_line_1 = "";
|
||||
// this->display_line_2 = "";
|
||||
// this->previous_display_line_1 = "";
|
||||
// this->previous_display_line_2 = "";
|
||||
} |
||||
|
||||
/**
|
||||
* Singleton instance |
||||
*/ |
||||
inline NervousSuperMother *NervousSuperMother::getInstance() { |
||||
if (!instance) |
||||
instance = new NervousSuperMother; |
||||
return instance; |
||||
} |
||||
|
||||
/**
|
||||
* Init |
||||
*/ |
||||
inline void NervousSuperMother::init(byte *inputs){ |
||||
for(byte i = 0; i < this->ioNumber; i++){ |
||||
this->inputs[i] = inputs[i]; |
||||
} |
||||
setup_hardware_controls(); |
||||
// setup_lcd();
|
||||
} |
||||
|
||||
/**
|
||||
* Update |
||||
*/ |
||||
inline void NervousSuperMother::update(){ |
||||
// Main clock
|
||||
if (this->clockMain >= this->intervalClockMain) { |
||||
this->clockMain = 0; |
||||
} |
||||
if (this->clockMain > this->intervalClockMain / 2) { |
||||
return; |
||||
}else{ |
||||
// AudioNoInterrupts();
|
||||
// Inputs
|
||||
// At the end of the clock we iterate to next input
|
||||
if (this->clockInputs >= this->intervalInputs) { |
||||
this->iterateInputs(); |
||||
this->clockInputs = 0; |
||||
}else{ |
||||
// Reading the current input
|
||||
this->readCurrentInput(); |
||||
} |
||||
// AudioInterrupts();
|
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Iterate over the inputs |
||||
*/ |
||||
inline void NervousSuperMother::iterateInputs(){ |
||||
this->currentInput++; |
||||
this->currentInput = this->currentInput % this->ioNumber; |
||||
} |
||||
|
||||
/**
|
||||
* Read value of current inout |
||||
*/ |
||||
inline void NervousSuperMother::readCurrentInput(){ |
||||
switch(this->inputs[this->currentInput]){ |
||||
default: |
||||
case 0: |
||||
// Silence is golden
|
||||
break; |
||||
|
||||
case 1: |
||||
if(this->potardIndex < ANALOG_CONTROL_PINS) { |
||||
this->readPotentiometer(this->potardIndex); |
||||
this->potardIndex ++; |
||||
} else { |
||||
this->potardIndex = 0; |
||||
} |
||||
break; |
||||
case 2: |
||||
if(this->buttonIndex < BUTTON_PINS) { |
||||
this->readButton(this->buttonIndex); |
||||
this->buttonIndex ++; |
||||
}else { |
||||
this->buttonIndex = 0; |
||||
} |
||||
break; |
||||
case 3: |
||||
if(this->encoderIndex < NB_ENCODER) { |
||||
this->readEncoder(this->encoderIndex); |
||||
this->encoderIndex ++; |
||||
}else { |
||||
this->encoderIndex = 0; |
||||
} |
||||
break; |
||||
case 4: |
||||
if(this->triggerIndex < TRIGGER_PINS) { |
||||
this->readTrigger(this->triggerIndex); |
||||
this->triggerIndex ++; |
||||
}else { |
||||
this->triggerIndex = 0; |
||||
} |
||||
break; |
||||
case 5: |
||||
// this->refreshDisplay();
|
||||
break; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Get potentiometer value |
||||
* @param byte inputeIndex The index of the input |
||||
*/ |
||||
inline void NervousSuperMother::readPotentiometer(byte inputIndex){ |
||||
analog_controls[inputIndex].update(); |
||||
if(analog_controls[inputIndex].hasChanged()){ |
||||
this->potentiometers[inputIndex] = analog_controls[inputIndex].getValue(); |
||||
|
||||
if(this->potentiometers[inputIndex] != this->potentiometersPrevious[inputIndex]){ |
||||
// Calling the potentiometer callback if there is one
|
||||
if(this->inputsPotentiometerChangeCallback[inputIndex] != nullptr){ |
||||
this->inputsPotentiometerChangeCallback[inputIndex](inputIndex, this->potentiometers[inputIndex], this->potentiometers[inputIndex] - this->potentiometersPrevious[inputIndex] ); |
||||
} |
||||
} |
||||
this->potentiometersPrevious[inputIndex] = this->potentiometers[inputIndex]; |
||||
} |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* Get input value |
||||
* @param byte index The index of the input |
||||
*/ |
||||
inline int NervousSuperMother::getInput(byte index){ |
||||
switch(this->inputs[index]){ |
||||
default: |
||||
case 0: |
||||
// Empty
|
||||
return 0; |
||||
break; |
||||
case 1: |
||||
// Buttons
|
||||
return !this->buttons[index]; |
||||
break; |
||||
case 2: |
||||
// Potentiometer
|
||||
return this->potentiometers[index]; |
||||
break; |
||||
case 3: |
||||
// Encoder
|
||||
// Device is not saving the encoders values, only the latest change
|
||||
// int value = this->encoders[index];
|
||||
// this->encoders[index] = 0;
|
||||
// return value;
|
||||
break; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Get max analog value according to resolution |
||||
*/ |
||||
inline int NervousSuperMother::getAnalogMinValue(){ |
||||
return 0; |
||||
} |
||||
|
||||
/**
|
||||
* Get max analog value according to resolution |
||||
*/ |
||||
inline int NervousSuperMother::getAnalogMaxValue(){ |
||||
return (1 << this->analogResolution) - 1; |
||||
} |
||||
|
||||
/**
|
||||
* Handle potentiometer |
||||
*/ |
||||
inline void NervousSuperMother::setHandlePotentiometerChange(byte inputIndex, PotentiometerChangeCallback fptr){ |
||||
this->inputsPotentiometerChangeCallback[inputIndex] = fptr; |
||||
} |
||||
|
||||
/**
|
||||
* Get button value |
||||
* @param byte inputeIndex The index of the input |
||||
*/ |
||||
inline void NervousSuperMother::readButton(byte buttonIndex) { |
||||
// If there is a short or a long press callback on that input
|
||||
if(this->inputsPressCallback[buttonIndex] != nullptr || |
||||
this->inputsDoublePressCallback[buttonIndex] != nullptr || |
||||
this->inputsLongPressCallback[buttonIndex] != nullptr) { |
||||
if(digital_button[buttonIndex].update()){ |
||||
if(digital_button[buttonIndex].fallingEdge()){ |
||||
this->pushed[buttonIndex] = true; |
||||
if(this->inputsPressTime[buttonIndex] <= 400 && this->pushed[buttonIndex]){ |
||||
if(this->inputsDoublePressCallback[buttonIndex] != nullptr){ |
||||
this->inputsDoublePressCallback[buttonIndex](buttonIndex); |
||||
} |
||||
} |
||||
this->inputsPressTime[buttonIndex] = 0; |
||||
} |
||||
|
||||
if(digital_button[buttonIndex].risingEdge()){ |
||||
if(this->inputsPressTime[buttonIndex] > 150 && this->inputsPressTime[buttonIndex] < 500){ |
||||
if(this->inputsPressCallback[buttonIndex] != nullptr){ |
||||
this->inputsPressCallback[buttonIndex](buttonIndex); |
||||
} |
||||
} |
||||
this->pushed[buttonIndex] = false; |
||||
} |
||||
}else if(this->inputsPressTime[buttonIndex] >= 800 && this->pushed[buttonIndex]){ |
||||
if(this->inputsLongPressCallback[buttonIndex] != nullptr){ |
||||
this->inputsLongPressCallback[buttonIndex](buttonIndex); |
||||
} |
||||
this->pushed[buttonIndex] = false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Handle press down on a button |
||||
*/ |
||||
inline void NervousSuperMother::setHandlePress(byte inputIndex, PressCallback fptr){ |
||||
this->inputsPressCallback[inputIndex] = fptr; |
||||
} |
||||
|
||||
/**
|
||||
* Handle press up on a button |
||||
*/ |
||||
inline void NervousSuperMother::setHandleDoublePress(byte inputIndex, DoublePressCallback fptr){ |
||||
this->inputsDoublePressCallback[inputIndex] = fptr; |
||||
} |
||||
|
||||
/**
|
||||
* Handle long press down on a button |
||||
*/ |
||||
inline void NervousSuperMother::setHandleLongPress(byte inputIndex, LongPressCallback fptr){ |
||||
this->inputsLongPressCallback[inputIndex] = fptr; |
||||
} |
||||
|
||||
/**
|
||||
* Get encoder value |
||||
* @param byte inputeIndex The index of the input |
||||
*/ |
||||
inline void NervousSuperMother::readEncoder(byte inputIndex) { |
||||
// Get rotary encoder value
|
||||
// Reverse
|
||||
if(this->encodersMaxValue[inputIndex] < 0){ |
||||
this->encoders[inputIndex] = encoders_knob[inputIndex].read(); |
||||
if(this->encoders[inputIndex] < this->encodersMaxValue[inputIndex]-2){ |
||||
this->encoders[inputIndex] = 0; |
||||
encoders_knob[inputIndex].write(0); |
||||
} |
||||
if(this->encoders[inputIndex] > 2){ |
||||
this->encoders[inputIndex] = this->encodersMaxValue[inputIndex]; |
||||
encoders_knob[inputIndex].write(this->encodersMaxValue[inputIndex]); |
||||
} |
||||
if (this->encoders[inputIndex]%4 == 0 && this->encoders[inputIndex] != this->encodersPrevious[inputIndex]) { |
||||
this->encodersPrevious[inputIndex] = this->encoders[inputIndex]; |
||||
// Calling the Encoder callback if there is one
|
||||
if(this->inputsEncoderChangeCallback[inputIndex] != nullptr){ |
||||
this->inputsEncoderChangeCallback[inputIndex](inputIndex, abs(this->encoders[inputIndex])/4); |
||||
} |
||||
} |
||||
// Normal
|
||||
}else { |
||||
this->encoders[inputIndex] = encoders_knob[inputIndex].read(); |
||||
if(this->encoders[inputIndex] > this->encodersMaxValue[inputIndex]+2){ |
||||
this->encoders[inputIndex] = 0; |
||||
encoders_knob[inputIndex].write(0); |
||||
} |
||||
if(this->encoders[inputIndex] < -2){ |
||||
this->encoders[inputIndex] = this->encodersMaxValue[inputIndex]; |
||||
encoders_knob[inputIndex].write(this->encodersMaxValue[inputIndex]); |
||||
} |
||||
if (this->encoders[inputIndex]%4 == 0 && this->encoders[inputIndex] != this->encodersPrevious[inputIndex]) { |
||||
this->encodersPrevious[inputIndex] = this->encoders[inputIndex]; |
||||
// Calling the Encoder callback if there is one
|
||||
if(this->inputsEncoderChangeCallback[inputIndex] != nullptr){ |
||||
this->inputsEncoderChangeCallback[inputIndex](inputIndex, this->encoders[inputIndex]/4); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Handle encoder change |
||||
*/ |
||||
inline void NervousSuperMother::setHandleEncoderChange(byte inputIndex, EncoderChangeCallback fptr) { |
||||
this->inputsEncoderChangeCallback[inputIndex] = fptr; |
||||
} |
||||
|
||||
/**
|
||||
* Update encoders max value |
||||
*/ |
||||
inline void NervousSuperMother::updateEncodeursMaxValue(byte inputIndex, long encoderMax) { |
||||
this->encodersMaxValue[inputIndex] = encoderMax*4; |
||||
} |
||||
|
||||
/**
|
||||
* Update encoders value |
||||
*/ |
||||
inline void NervousSuperMother::updateEncodeursValue(byte inputIndex, long encoderValue) { |
||||
encoders_knob[inputIndex].write(encoderValue*4); |
||||
} |
||||
|
||||
/**
|
||||
* Get trigger |
||||
* @param byte inputeIndex The index of the input |
||||
*/ |
||||
inline void NervousSuperMother::readTrigger(byte inputIndex){ |
||||
digital_trigger[inputIndex].update(); |
||||
if (digital_trigger[inputIndex].fallingEdge()) { |
||||
if(this->inputsTriggerCallback[inputIndex] != nullptr){ |
||||
this->inputsTriggerCallback[inputIndex](inputIndex); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Handle trigger |
||||
*/ |
||||
inline void NervousSuperMother::setHandleTrigger(byte inputIndex, TriggerCallback fptr){ |
||||
this->inputsTriggerCallback[inputIndex] = fptr; |
||||
} |
||||
|
||||
/**
|
||||
* Update line to display |
||||
*/ |
||||
// inline void NervousSuperMother::updateLine(byte line_nb, String line) {
|
||||
// if(line_nb == 1){
|
||||
// this->display_line_1 = line;
|
||||
// }else if(line_nb == 2){
|
||||
// this->display_line_2 = line;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Refresh the display |
||||
*/ |
||||
// inline void NervousSuperMother::refreshDisplay() {
|
||||
// if(this->display_line_1 != this->previous_display_line_1 || this->display_line_2 != this->previous_display_line_2){
|
||||
// byte j = 0;
|
||||
// for(byte i = 0; i < this->display_line_1.length(); i++){
|
||||
// if(this->previous_display_line_1[i] != this->display_line_1[i]){
|
||||
// lcd.setCursor(i, 0);
|
||||
// lcd.print(this->display_line_1[i]);
|
||||
// }
|
||||
// j = i+1;
|
||||
// }
|
||||
// if(j < 20){
|
||||
// for(byte i = j; i < 20; i++){
|
||||
// lcd.setCursor(i, 0);
|
||||
// lcd.print(" ");
|
||||
// }
|
||||
// }
|
||||
// j = 0;
|
||||
// for(byte i = 0; i < this->display_line_2.length(); i++){
|
||||
// if(this->previous_display_line_2[i] != this->display_line_2[i]){
|
||||
// lcd.setCursor(i, 1);
|
||||
// lcd.print(this->display_line_2[i]);
|
||||
// }
|
||||
// j = i+1;
|
||||
// }
|
||||
// if(j < 20){
|
||||
// for(byte i = j; i < 20; i++){
|
||||
// lcd.setCursor(i, 1);
|
||||
// lcd.print(" ");
|
||||
// }
|
||||
// }
|
||||
// this->previous_display_line_1 = this->display_line_1;
|
||||
// this->previous_display_line_2 = this->display_line_2;
|
||||
// }
|
||||
// }
|
||||
|
||||
#endif |
@ -0,0 +1,168 @@ |
||||
#ifndef Display_h |
||||
#define Display_h |
||||
|
||||
#include "Arduino.h" |
||||
#include <LiquidCrystalFast.h> |
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
// LiquidCrystal lcd(RS, RW, Enable, D4, D5, D6, D7)
|
||||
LiquidCrystalFast lcd(DISPLAY_RS, DISPLAY_RW, DISPLAY_E, DISPLAY_DB4, DISPLAY_DB5, DISPLAY_DB6, DISPLAY_DB7); |
||||
|
||||
int LCD_NB_COLUMNS = 20; |
||||
|
||||
/* Caractères personnalisés */ |
||||
byte START_DIV_0_OF_1[8] = { |
||||
B01111, |
||||
B11000, |
||||
B10000, |
||||
B10000, |
||||
B10000, |
||||
B10000, |
||||
B11000, |
||||
B01111 |
||||
}; // Char début 0 / 1
|
||||
|
||||
byte START_DIV_1_OF_1[8] = { |
||||
B01111, |
||||
B11000, |
||||
B10011, |
||||
B10111, |
||||
B10111, |
||||
B10011, |
||||
B11000, |
||||
B01111 |
||||
}; // Char début 1 / 1
|
||||
|
||||
byte DIV_0_OF_2[8] = { |
||||
B11111, |
||||
B00000, |
||||
B00000, |
||||
B00000, |
||||
B00000, |
||||
B00000, |
||||
B00000, |
||||
B11111 |
||||
}; // Char milieu 0 / 2
|
||||
|
||||
byte DIV_1_OF_2[8] = { |
||||
B11111, |
||||
B00000, |
||||
B11000, |
||||
B11000, |
||||
B11000, |
||||
B11000, |
||||
B00000, |
||||
B11111 |
||||
}; // Char milieu 1 / 2
|
||||
|
||||
byte DIV_2_OF_2[8] = { |
||||
B11111, |
||||
B00000, |
||||
B11011, |
||||
B11011, |
||||
B11011, |
||||
B11011, |
||||
B00000, |
||||
B11111 |
||||
}; // Char milieu 2 / 2
|
||||
|
||||
byte END_DIV_0_OF_1[8] = { |
||||
B11110, |
||||
B00011, |
||||
B00001, |
||||
B00001, |
||||
B00001, |
||||
B00001, |
||||
B00011, |
||||
B11110 |
||||
}; // Char fin 0 / 1
|
||||
|
||||
byte END_DIV_1_OF_1[8] = { |
||||
B11110, |
||||
B00011, |
||||
B11001, |
||||
B11101, |
||||
B11101, |
||||
B11001, |
||||
B00011, |
||||
B11110 |
||||
}; // Char fin 1 / 1
|
||||
|
||||
/**
|
||||
* Fonction de configuration de l'écran LCD pour la barre de progression. |
||||
* Utilise les caractères personnalisés de 0 à 6 (7 reste disponible). |
||||
*/ |
||||
void setup_progressbar() { |
||||
|
||||
/* Enregistre les caractères personnalisés dans la mémoire de l'écran LCD */ |
||||
lcd.createChar(0, START_DIV_0_OF_1); |
||||
lcd.createChar(1, START_DIV_1_OF_1); |
||||
lcd.createChar(2, DIV_0_OF_2); |
||||
lcd.createChar(3, DIV_1_OF_2); |
||||
lcd.createChar(4, DIV_2_OF_2); |
||||
lcd.createChar(5, END_DIV_0_OF_1); |
||||
lcd.createChar(6, END_DIV_1_OF_1); |
||||
} |
||||
|
||||
void setup_lcd(){ |
||||
// set up the LCD's number of rows and columns:
|
||||
lcd.begin(20, 2); |
||||
setup_progressbar(); |
||||
} |
||||
|
||||
/**
|
||||
* Fonction dessinant la barre de progression. |
||||
* |
||||
* @param percent Le pourcentage à afficher. |
||||
*/ |
||||
void draw_progressbar(byte percent) { |
||||
/* Déplace le curseur sur la seconde ligne */ |
||||
lcd.setCursor(0, 1); |
||||
|
||||
/* Map la plage (0 ~ 100) vers la plage (0 ~ LCD_NB_COLUMNS * 2 - 2) */ |
||||
byte nb_columns = map(percent, 0, 100, 0, LCD_NB_COLUMNS * 2 - 2); |
||||
// Chaque caractère affiche 2 barres verticales, mais le premier et dernier caractère n'en affiche qu'une.
|
||||
|
||||
/* Dessine chaque caractère de la ligne */ |
||||
for (byte i = 0; i < LCD_NB_COLUMNS; ++i) { |
||||
|
||||
if (i == 0) { // Premiére case
|
||||
|
||||
/* Affiche le char de début en fonction du nombre de colonnes */ |
||||
if (nb_columns > 0) { |
||||
lcd.write(1); // Char début 1 / 1
|
||||
nb_columns -= 1; |
||||
|
||||
} else { |
||||
lcd.write((byte) 0); // Char début 0 / 1
|
||||
} |
||||
|
||||
} else if (i == LCD_NB_COLUMNS -1) { // Derniére case
|
||||
|
||||
/* Affiche le char de fin en fonction du nombre de colonnes */ |
||||
if (nb_columns > 0) { |
||||
lcd.write(6); // Char fin 1 / 1
|
||||
|
||||
} else { |
||||
lcd.write(5); // Char fin 0 / 1
|
||||
} |
||||
|
||||
} else { // Autres cases
|
||||
|
||||
/* Affiche le char adéquat en fonction du nombre de colonnes */ |
||||
if (nb_columns >= 2) { |
||||
lcd.write(4); // Char div 2 / 2
|
||||
nb_columns -= 2; |
||||
|
||||
} else if (nb_columns == 1) { |
||||
lcd.write(3); // Char div 1 / 2
|
||||
nb_columns -= 1; |
||||
|
||||
} else { |
||||
lcd.write(2); // Char div 0 / 2
|
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,118 @@ |
||||
#ifndef HardwareControls_h |
||||
#define HardwareControls_h |
||||
|
||||
#include "Arduino.h" |
||||
// include the ResponsiveAnalogRead library for analog smoothing
|
||||
#include <ResponsiveAnalogRead.h> |
||||
// include the Bounce library for 'de-bouncing' switches -- removing electrical chatter as contacts settle
|
||||
#include <Bounce.h> |
||||
// This optional setting causes Encoder to use more optimized code,
|
||||
// It must be defined before Encoder.h is included.
|
||||
#define ENCODER_OPTIMIZE_INTERRUPTS |
||||
#include <Encoder.h> |
||||
#include "pins.h" |
||||
|
||||
// ******ANALOG CONSTANT VALUES********
|
||||
const int ANALOG_CONTROL_PINS = 18; |
||||
const int ANALOG_CONTROL[ANALOG_CONTROL_PINS] = { |
||||
SLIDE1, |
||||
SLIDE2, |
||||
SLIDE3, |
||||
SLIDE4, |
||||
SLIDE5, |
||||
SLIDE6, |
||||
SLIDE7, |
||||
SLIDE8, |
||||
SLIDE9, |
||||
SLIDE10, |
||||
POT1, |
||||
POT2, |
||||
POT3, |
||||
POT4, |
||||
POT5, |
||||
SW1, |
||||
SW2, |
||||
SW3 |
||||
}; |
||||
|
||||
// ******BUTTONS CONSTANT VALUES********
|
||||
const int BUTTON_PINS = 2; // number of Digital trigger PINS
|
||||
const int BOUNCE_TIME = 5; // 5 ms is usually sufficient
|
||||
const boolean toggled = true; |
||||
|
||||
// define the pins and notes for digital events
|
||||
const int BUTTONS[BUTTON_PINS] = { |
||||
ENC1_SW, |
||||
ENC2_SW |
||||
}; |
||||
|
||||
// ******TRIGGERS CONSTANT VALUES********
|
||||
const int TRIGGER_PINS = 6; |
||||
const int TRIGGERS[TRIGGER_PINS] = { |
||||
TRIG1, |
||||
TRIG2, |
||||
TRIG3, |
||||
TRIG4, |
||||
TRIG5, |
||||
TRIG6 |
||||
}; |
||||
|
||||
//******VARIABLES***********
|
||||
|
||||
//************INITIALIZE LIBRARY OBJECTS**************
|
||||
|
||||
// initialize the ReponsiveAnalogRead objects
|
||||
ResponsiveAnalogRead analog_controls[]{ |
||||
{ANALOG_CONTROL[0],true}, |
||||
{ANALOG_CONTROL[1],true}, |
||||
{ANALOG_CONTROL[2],true}, |
||||
{ANALOG_CONTROL[3],true}, |
||||
{ANALOG_CONTROL[4],true}, |
||||
{ANALOG_CONTROL[5],true}, |
||||
{ANALOG_CONTROL[6],true}, |
||||
{ANALOG_CONTROL[7],true}, |
||||
{ANALOG_CONTROL[8],true}, |
||||
{ANALOG_CONTROL[9],true}, |
||||
{ANALOG_CONTROL[10],true}, |
||||
{ANALOG_CONTROL[11],true}, |
||||
{ANALOG_CONTROL[12],true}, |
||||
{ANALOG_CONTROL[13],true}, |
||||
{ANALOG_CONTROL[14],true}, |
||||
{ANALOG_CONTROL[15],true}, |
||||
{ANALOG_CONTROL[16],true}, |
||||
{ANALOG_CONTROL[17],true} |
||||
}; |
||||
|
||||
// initialize the bounce objects
|
||||
Bounce digital_button[] = { |
||||
Bounce(BUTTONS[0],BOUNCE_TIME), |
||||
Bounce(BUTTONS[1],BOUNCE_TIME) |
||||
}; |
||||
|
||||
Bounce digital_trigger[] = { |
||||
Bounce(TRIGGERS[0],BOUNCE_TIME), |
||||
Bounce(TRIGGERS[1],BOUNCE_TIME), |
||||
Bounce(TRIGGERS[2],BOUNCE_TIME), |
||||
Bounce(TRIGGERS[3],BOUNCE_TIME), |
||||
Bounce(TRIGGERS[4],BOUNCE_TIME), |
||||
Bounce(TRIGGERS[5],BOUNCE_TIME) |
||||
}; |
||||
|
||||
const int NB_ENCODER = 2; |
||||
Encoder encoders_knob[] = { |
||||
Encoder(ENC1_1, ENC1_2), |
||||
Encoder(ENC2_1, ENC2_2) |
||||
}; |
||||
|
||||
void setup_hardware_controls(){ |
||||
// loop to configure input pins and internal pullup resisters for digital section
|
||||
for (int i=0;i<BUTTON_PINS;i++){ |
||||
pinMode(BUTTONS[i], INPUT_PULLUP); |
||||
} |
||||
|
||||
for (int i=0;i<TRIGGER_PINS;i++){ |
||||
pinMode(TRIGGERS[i], INPUT_PULLUP); |
||||
} |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,64 @@ |
||||
#ifndef pins_h |
||||
#define pins_h |
||||
|
||||
// MIDI IN
|
||||
#define MIDI_IN 0 |
||||
|
||||
// PT8211 DAC
|
||||
#define BCK_DAC 9 |
||||
#define U7_DIN 22 |
||||
#define U7_WS 23 |
||||
|
||||
// Encoders
|
||||
#define ENC1_1 2 |
||||
#define ENC1_2 3 |
||||
#define ENC1_SW 4 |
||||
#define ENC2_1 6 |
||||
#define ENC2_2 5 |
||||
#define ENC2_SW 7 |
||||
|
||||
// Triggers
|
||||
#define TRIG1 8 |
||||
#define TRIG2 10 |
||||
#define TRIG3 11 |
||||
#define TRIG4 12 |
||||
#define TRIG5 38 |
||||
#define TRIG6 39 |
||||
|
||||
// Display
|
||||
#define DISPLAY_RS 24 |
||||
#define DISPLAY_RW 25 |
||||
#define DISPLAY_E 26 |
||||
#define DISPLAY_DB4 27 |
||||
#define DISPLAY_DB5 28 |
||||
#define DISPLAY_DB6 29 |
||||
#define DISPLAY_DB7 30 |
||||
|
||||
// Potentiometers
|
||||
#define POT1 A12 |
||||
#define POT2 A13 |
||||
#define POT3 A14 |
||||
#define POT4 A15 |
||||
#define POT5 A16 |
||||
|
||||
// Switches
|
||||
#define SW1 A17 |
||||
#define SW2 A18 |
||||
// Teensy 3.5
|
||||
// #define SW3 A25
|
||||
// Teensy 3.6
|
||||
#define SW3 A23 |
||||
|
||||
// Sliders
|
||||
#define SLIDE1 A0 |
||||
#define SLIDE2 A1 |
||||
#define SLIDE3 A2 |
||||
#define SLIDE4 A3 |
||||
#define SLIDE5 A4 |
||||
#define SLIDE6 A5 |
||||
#define SLIDE7 A6 |
||||
#define SLIDE8 A7 |
||||
#define SLIDE9 A10 |
||||
#define SLIDE10 A11 |
||||
|
||||
#endif |
Loading…
Reference in new issue