🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Simple Click Sound

    Scheduled Pinned Locked Moved Micropython
    6 Posts 3 Posters 10.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P Offline
      purpledread
      last edited by

      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?

      P 1 Reply Last reply Reply Quote 0
      • P Offline
        purpledread @purpledread
        last edited by

        @purpledread

        Should have mentioned I'm running on a M5Core2.

        /Chris

        1 Reply Last reply Reply Quote 0
        • M Offline
          macsbug
          last edited by macsbug

          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 , Fire

          Touch 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 touch

          Void 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;
          }

          P 1 Reply Last reply Reply Quote 0
          • P Offline
            purpledread @macsbug
            last edited by

            @macsbug

            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

            1 Reply Last reply Reply Quote 0
            • felmueF Offline
              felmue
              last edited by felmue

              Hello @purpledread

              not a click sound, but at least a tone on M5Core2.

              Thanks
              Felix

              GPIO translation table M5Stack / M5Core2
              Information about various M5Stack products.
              Code examples

              P 1 Reply Last reply Reply Quote 0
              • P Offline
                purpledread @felmue
                last edited by

                @felmue

                Thanks. Any kind of sound would be great.

                My machine module doesn't have the I2S used in this example.

                /Chris

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post