Added showing the current selected volume inside the display.

Added configurable number of steps for volume encoder.
pull/4/head
Holger Wirtz 6 years ago
parent 2a93214d17
commit 190bad2f46
  1. 11
      MicroDexed.ino
  2. 51
      UI.cpp
  3. 13
      UI.h
  4. 2
      config.h

@ -47,6 +47,7 @@ Encoder4 enc[2] = {Encoder4(ENC_L_PIN_A, ENC_L_PIN_B), Encoder4(ENC_R_PIN_A, ENC
int32_t enc_val[2] = {INITIAL_ENC_L_VALUE, INITIAL_ENC_R_VALUE}; 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)}; Bounce but[2] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)};
elapsedMillis master_timer; elapsedMillis master_timer;
uint8_t ui_state = UI_MAIN;
#endif #endif
// GUItool: begin automatically generated code // GUItool: begin automatically generated code
@ -181,7 +182,7 @@ void setup()
// load default SYSEX data // load default SYSEX data
load_sysex(bank, voice); load_sysex(bank, voice);
#ifdef I2C_DISPLAY #ifdef I2C_DISPLAY
enc[0].write(map(vol*100,0,100,0,20)); enc[0].write(map(vol * 100, 0, 100, 0, ENC_VOL_STEPS));
enc[1].write(voice); enc[1].write(voice);
but[0].update(); but[0].update();
but[1].update(); but[1].update();
@ -222,13 +223,7 @@ void setup()
#endif #endif
#ifdef I2C_DISPLAY #ifdef I2C_DISPLAY
lcd.clear(); ui_show_main();
lcd.show(0, 0, 2, bank + 1);
lcd.show(0, 2, 1, " ");
lcd.show(0, 3, 10, bank_name);
lcd.show(1, 0, 2, voice + 1);
lcd.show(1, 2, 1, " ");
lcd.show(1, 3, 10, voice_name);
#endif #endif
#ifdef TEST_NOTE #ifdef TEST_NOTE

@ -29,12 +29,13 @@
#ifdef I2C_DISPLAY // selecting sounds by encoder, button and display #ifdef I2C_DISPLAY // selecting sounds by encoder, button and display
elapsedMillis ui_back_to_main;
enum ui_state {UI_MAIN};
uint8_t ui_state = UI_MAIN;
void handle_ui(void) void handle_ui(void)
{ {
if (ui_back_to_main >= UI_AUTO_BACK_MS && ui_state != UI_MAIN)
ui_show_main();
for (uint8_t i = 0; i < NUM_ENCODER; i++) for (uint8_t i = 0; i < NUM_ENCODER; i++)
{ {
but[i].update(); but[i].update();
@ -57,11 +58,13 @@ void handle_ui(void)
case 0: // left encoder moved case 0: // left encoder moved
if (enc[i].read() <= 0) if (enc[i].read() <= 0)
enc[i].write(0); enc[i].write(0);
else if (enc[i].read() >= 20) else if (enc[i].read() >= ENC_VOL_STEPS)
enc[i].write(20); enc[i].write(ENC_VOL_STEPS);
set_volume(float(map(enc[i].read(), 0, 20, 0, 100))/100, vol_left, vol_right); set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, vol_left, vol_right);
ui_show_volume();
break; break;
case 1: // right encoder moved case 1: // right encoder moved
ui_show_main();
break; break;
} }
#ifdef DEBUG #ifdef DEBUG
@ -75,15 +78,33 @@ void handle_ui(void)
} }
} }
/*int32_t getEncPosition(uint8_t encoder_number) void ui_show_main(void)
{ {
return enc[encoder_number].read() / 4; ui_state = UI_MAIN;
}
lcd.clear();
lcd.show(0, 0, 2, bank + 1);
lcd.show(0, 2, 1, " ");
lcd.show(0, 3, 10, bank_name);
lcd.show(1, 0, 2, voice + 1);
lcd.show(1, 2, 1, " ");
lcd.show(1, 3, 10, voice_name);
}
void setEncPosition(uint8_t encoder_number, int32_t value) void ui_show_volume(void)
{ {
enc[encoder_number].write(value * 4); ui_back_to_main = 0;
enc_val[encoder_number] = value * 4;
}*/ if (ui_state != UI_VOLUME)
lcd.show(0, 0, LCD_CHARS, "Volume");
lcd.show(0, LCD_CHARS - 3, 3, vol * 100);
for (uint8_t i = 0; i < map(vol * 100, 0, 100, 0, LCD_CHARS); i++)
lcd.show(1, i, 1, "*");
for (uint8_t i = map(vol * 100, 0, 100, 0, LCD_CHARS); i < LCD_CHARS; i++)
lcd.show(1, i, 1, " ");
ui_state = UI_VOLUME;
}
#endif #endif

13
UI.h

@ -34,14 +34,23 @@
extern Encoder4 enc[2]; extern Encoder4 enc[2];
extern int32_t enc_val[2]; extern int32_t enc_val[2];
extern Bounce but[2]; extern Bounce but[2];
extern float vol;
extern float vol_left; extern float vol_left;
extern float vol_right; extern float vol_right;
extern LiquidCrystalPlus_I2C lcd;
extern uint8_t bank;
extern uint8_t voice;
extern char bank_name[11];
extern char voice_name[11];
extern uint8_t ui_state;
extern void set_volume(float v, float vr, float vl); extern void set_volume(float v, float vr, float vl);
void handle_ui(void); void handle_ui(void);
/* int32_t getEncPosition(uint8_t encoder_number); void ui_show_main(void);
void setEncPosition(uint8_t encoder_number, int32_t value);*/ void ui_show_volume(void);
enum ui_states {UI_MAIN, UI_VOLUME};
class MyEncoder : public Encoder class MyEncoder : public Encoder
{ {

@ -92,8 +92,10 @@
#define LCD_I2C_ADDRESS 0x27 #define LCD_I2C_ADDRESS 0x27
#define LCD_CHARS 16 #define LCD_CHARS 16
#define LCD_LINES 2 #define LCD_LINES 2
#define UI_AUTO_BACK_MS 2000
// Encoder with button // Encoder with button
#define ENC_VOL_STEPS 50
#define TIMER_UI_HANDLING_MS 50 #define TIMER_UI_HANDLING_MS 50
#define NUM_ENCODER 2 #define NUM_ENCODER 2
#define ENC_L_PIN_A 3 #define ENC_L_PIN_A 3

Loading…
Cancel
Save