Added left encoder as volume pot.

pull/4/head
Holger Wirtz 6 years ago
parent 06e410173e
commit 2a93214d17
  1. 6
      LiquidCrystalPlus_I2C.h
  2. 2
      MicroDexed.ino
  3. 26
      UI.cpp
  4. 24
      UI.h

@ -28,6 +28,8 @@
#ifndef LIQUIDCRYSTALPLUS_I2C_H_INCLUDED
#define LIQUIDCRYSTALPLUS_I2C_H_INCLUDED
#define STRING_BUF_SIZE 21
class LiquidCrystalPlus_I2C : public LiquidCrystal_I2C
{
public:
@ -41,7 +43,7 @@ class LiquidCrystalPlus_I2C : public LiquidCrystal_I2C
void show(uint8_t y, uint8_t x, uint8_t fs, long num)
{
char _buf10[64];
char _buf10[STRING_BUF_SIZE];
_show(y, x, fs, itoa(num, _buf10, 10), true, true);
}
@ -50,7 +52,7 @@ class LiquidCrystalPlus_I2C : public LiquidCrystal_I2C
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 tmp[STRING_BUF_SIZE];
char *s = tmp;
uint8_t l = strlen(str);

@ -181,7 +181,7 @@ void setup()
// load default SYSEX data
load_sysex(bank, voice);
#ifdef I2C_DISPLAY
enc[0].write(bank);
enc[0].write(map(vol*100,0,100,0,20));
enc[1].write(voice);
but[0].update();
but[1].update();

@ -29,6 +29,10 @@
#ifdef I2C_DISPLAY // selecting sounds by encoder, button and display
enum ui_state {UI_MAIN};
uint8_t ui_state = UI_MAIN;
void handle_ui(void)
{
for (uint8_t i = 0; i < NUM_ENCODER; i++)
@ -48,6 +52,18 @@ void handle_ui(void)
continue;
else
{
switch (i)
{
case 0: // left encoder moved
if (enc[i].read() <= 0)
enc[i].write(0);
else if (enc[i].read() >= 20)
enc[i].write(20);
set_volume(float(map(enc[i].read(), 0, 20, 0, 100))/100, vol_left, vol_right);
break;
case 1: // right encoder moved
break;
}
#ifdef DEBUG
Serial.print(F("Encoder "));
Serial.print(i, DEC);
@ -60,14 +76,14 @@ void handle_ui(void)
}
/*int32_t getEncPosition(uint8_t encoder_number)
{
{
return enc[encoder_number].read() / 4;
}
}
void setEncPosition(uint8_t encoder_number, int32_t value)
{
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

@ -34,21 +34,25 @@
extern Encoder4 enc[2];
extern int32_t enc_val[2];
extern Bounce but[2];
extern float vol_left;
extern float vol_right;
extern void set_volume(float v, float vr, float vl);
void handle_ui(void);
/* int32_t getEncPosition(uint8_t encoder_number);
void setEncPosition(uint8_t encoder_number, int32_t value);*/
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);
}
int32_t read()
{
return (Encoder::read() / 4);
}
void write(int32_t p)
{
Encoder::write(p * 4);
}
};
#endif

Loading…
Cancel
Save