diff --git a/LiquidCrystalPlus_I2C.h b/LiquidCrystalPlus_I2C.h index 1b92a60..e6787ce 100644 --- a/LiquidCrystalPlus_I2C.h +++ b/LiquidCrystalPlus_I2C.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); diff --git a/MicroDexed.ino b/MicroDexed.ino index 5fb3d7f..a06c11c 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -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(); diff --git a/UI.cpp b/UI.cpp index 248e96b..effb015 100644 --- a/UI.cpp +++ b/UI.cpp @@ -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 diff --git a/UI.h b/UI.h index 0f5160b..3716595 100644 --- a/UI.h +++ b/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