Simple Click Sound
-
I'm using the LVGL with MicroPython for a project and I'd like to be able to make a click noice when the user interacts with the application's buttons.
Is there any easy way to do that?
-
-
Hello@purpledread
I don't use MicroPython, but it works with the Arduino IDE.
Development environment
Arduino IDE 1.8.9
LVGL 8.1.0
M5Stack Basic , Gray , FireTouch and button operation:
Core2 is used with Touch (x, y).
M5Stack is used by setting A, B, C Button with x, y.Output sound from Button:
Use M5.Speaker.beep or M5.Speaker.tone.Set lv_conf.h for LVGL8 :
//=====================================================================
// Set lv_conf.h for LVGL8 : lvgl_8.1.0 / src / lv_conf.h
// #define LV_TICK_CUSTOM 1 : LVGL lv_conf.h setup
// #define LV_COLOR_DEPTH 16 : LVGL lv_conf.h setup
// #define LV_COLOR_16_SWAP 0 : color
//=====================================================================Arduino IDE example :
//=====================================================================
// Initialize the (dummy) input device driver/
void init_m5_button(){
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = M5_btn;
lv_indev_drv_register(&indev_drv);
}
//=====================================================================
// https://github.com/m5stack/m5-docs/blob/master/docs/ja/api/speaker.md
void M5_btn(lv_indev_drv_tindev_driver,lv_indev_data_tdata){
int mx, my;
// A Button : Leftward ----------------------------------------------
if (M5.BtnA.wasPressed()){ // center position
mx = 320/2 -100; my = 240/2;
data->point.x = mx; data->point.y = my;
data->state = LV_INDEV_STATE_PR;
//
M5.Speaker.setVolume(2); // 0, 1 to 8
M5.Speaker.beep(); delay(100); // beep 100msec
//
M5.update(); return;
}
// B Button : Rightward ---------------------------------------------
if (M5.BtnB.wasPressed()){
mx = 320/2; my = 240/2;
data->point.x = mx; data->point.y = my;
data->state = LV_INDEV_STATE_PR;
//
M5.Speaker.setVolume(1); // 0, 1 to 10
M5.Speaker.tone(1000, 250); // 1KHz , 250msec
//
M5.update(); return;
}
// C Button : Auto / Manual Display ---------------------------------
if (M5.BtnC.wasPressed()){
mx = 320/2 + 100; my = 240/2;
data->point.x = mx; data->point.y = my;
data->state = LV_INDEV_STATE_PR;
//
M5.Speaker.setVolume(1); // 0, 1 to 10
M5.Speaker.tone(440, 100); delay(100);
M5.Speaker.mute(); delay(100);
M5.Speaker.tone(440, 100); delay(100);
M5.Speaker.mute(); delay(100);
M5.Speaker.tone(440, 100);
//
M5.update(); return;
}
// No button operation ----------------------------------------------
data->state = LV_INDEV_STATE_REL; M5.update(); return;
}
//=====================================================================Use btn Exsample from LVGL 8.1.0.
// --------------------------------------------------------------------
// lvgl(8.1.0) / examples / widgets / btn /
// lv_example_btn_1.c , lv_example_btn_2.c , lv_example_btn_3.c
// lv_example_btn_1.py
lv_example_btn_1(); // From the btn demo of LVGL 8.1.0
lv_example_btn_2(); // From the btn demo of LVGL 8.1.0
lv_example_btn_3(); // From the btn demo of LVGL 8.1.0
// --------------------------------------------------------------------:
reference : Core 2 touchVoid my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data){
TouchPoint_t pos = M5.Touch.getPressPoint();
bool touched = ( pos.x == -1 ) ? false : true;
if(!touched) {
data->state = LV_INDEV_STATE_REL;
} else {
data->state = LV_INDEV_STATE_PR;
/Set the coordinates/
data->point.x = pos.x;
data->point.y = pos.y;
}
return;
} -
I really appreciate the response, but I'm running with an image that just has lvgl and micropython and not the M5 classes.
Looking for how to play a sound with the standard esp32 hardware support on the device.
/Chris
-
-
Thanks. Any kind of sound would be great.
My machine module doesn't have the I2S used in this example.
/Chris