Created derived classes for Encoder4 and LiquidCrystal_I2CPlus.

pull/4/head
Holger Wirtz 6 years ago
parent ed8be3aa69
commit 06e410173e
  1. 48
      Encoder4.h
  2. 86
      LiquidCrystalPlus_I2C.h
  3. 10
      MicroDexed.ino
  4. 12
      UI.cpp
  5. 24
      UI.h

@ -0,0 +1,48 @@
/*
MicroDexed
MicroDexed is a port of the Dexed sound engine
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
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, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Encoder.h>
#ifndef ENCODER4_H_INCLUDED
#define ENCODER4_H_INCLUDED
class Encoder4 : public Encoder
{
public:
using Encoder::Encoder;
int32_t read()
{
return (Encoder::read() / 4);
}
void write(int32_t p)
{
Encoder::write(p * 4);
}
};
#endif

@ -0,0 +1,86 @@
/*
MicroDexed
MicroDexed is a port of the Dexed sound engine
(https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield.
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018 H. Wirtz <wirtz@parasitstudio.de>
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, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <LiquidCrystal_I2C.h>
#ifndef LIQUIDCRYSTALPLUS_I2C_H_INCLUDED
#define LIQUIDCRYSTALPLUS_I2C_H_INCLUDED
class LiquidCrystalPlus_I2C : public LiquidCrystal_I2C
{
public:
using LiquidCrystal_I2C::LiquidCrystal_I2C;
void show(uint8_t y, uint8_t x, uint8_t fs, char *str)
{
_show(y, x, fs, str, false, false);
}
void show(uint8_t y, uint8_t x, uint8_t fs, long num)
{
char _buf10[64];
_show(y, x, fs, itoa(num, _buf10, 10), true, true);
}
private:
void _show(uint8_t pos_y, uint8_t pos_x, uint8_t field_size, char *str, bool justify_right, bool fill_zero)
{
{
char tmp[64];
char *s = tmp;
uint8_t l = strlen(str);
memset(tmp, 0, sizeof(tmp));
if (fill_zero == true)
memset(tmp, '0', field_size);
else
memset(tmp, 0x20, field_size - 1); // blank
if (l > field_size)
l = field_size;
if (justify_right == true)
s += field_size - l;
strncpy(s, str, l);
setCursor(pos_x, pos_y);
print(tmp);
#ifdef DEBUG
Serial.print(pos_y, DEC);
Serial.print(F("/"));
Serial.print(pos_x, DEC);
Serial.print(F(": ["));
Serial.print(tmp);
Serial.println(F("]"));
#endif
}
}
};
#endif

@ -40,10 +40,10 @@
#ifdef I2C_DISPLAY // selecting sounds by encoder, button and display
#include "UI.h"
#include <Bounce.h>
#include <Encoder.h>
#include <LiquidCrystalPlus_I2C.h>
#include "Encoder4.h"
#include "LiquidCrystalPlus_I2C.h"
LiquidCrystalPlus_I2C lcd(LCD_I2C_ADDRESS, LCD_CHARS, LCD_LINES);
Encoder enc[2] = {Encoder(ENC_L_PIN_A, ENC_L_PIN_B), Encoder(ENC_R_PIN_A, ENC_R_PIN_B)};
Encoder4 enc[2] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC_R_PIN_B)};
int32_t enc_val[2] = {INITIAL_ENC_L_VALUE, INITIAL_ENC_R_VALUE};
Bounce but[2] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)};
elapsedMillis master_timer;
@ -181,8 +181,8 @@ void setup()
// load default SYSEX data
load_sysex(bank, voice);
#ifdef I2C_DISPLAY
setEncPosition(0,bank);
setEncPosition(1,voice);
enc[0].write(bank);
enc[1].write(voice);
but[0].update();
but[1].update();
#endif

@ -26,9 +26,6 @@
#include <Arduino.h>
#include "config.h"
#include "UI.h"
#include <Bounce.h>
#include <Encoder.h>
#include <LiquidCrystalPlus_I2C.h>
#ifdef I2C_DISPLAY // selecting sounds by encoder, button and display
@ -47,7 +44,7 @@ void handle_ui(void)
#endif
}
if ((enc[i].read() / 4) == (enc_val[i] / 4))
if (enc[i].read() == enc_val[i])
continue;
else
{
@ -55,14 +52,14 @@ void handle_ui(void)
Serial.print(F("Encoder "));
Serial.print(i, DEC);
Serial.print(F(": "));
Serial.println(getEncPosition(i), DEC);
Serial.println(enc[i].read(), DEC);
#endif
}
enc_val[i] = enc[i].read();
}
}
int32_t getEncPosition(uint8_t encoder_number)
/*int32_t getEncPosition(uint8_t encoder_number)
{
return enc[encoder_number].read() / 4;
}
@ -71,5 +68,6 @@ void setEncPosition(uint8_t encoder_number, int32_t value)
{
enc[encoder_number].write(value * 4);
enc_val[encoder_number] = value * 4;
}
}*/
#endif

24
UI.h

@ -25,18 +25,30 @@
#include "config.h"
#include <Bounce.h>
#include <Encoder.h>
#include <LiquidCrystalPlus_I2C.h>
#include "LiquidCrystalPlus_I2C.h"
#include "Encoder4.h"
#ifndef UI_H_INCLUDED
#define UI_H_INCLUDED
extern Encoder enc[2];
extern Encoder4 enc[2];
extern int32_t enc_val[2];
extern Bounce but[2];
void handle_ui(void);
int32_t getEncPosition(uint8_t encoder_number);
void setEncPosition(uint8_t encoder_number, int32_t value);
/* int32_t getEncPosition(uint8_t encoder_number);
void setEncPosition(uint8_t encoder_number, int32_t value);*/
class MyEncoder : public Encoder
{
int32_t read()
{
return(Encoder::read()/4);
}
void write(int32_t p)
{
Encoder::write(p*4);
}
};
#endif

Loading…
Cancel
Save