Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speaker on core 2 #118

Open
slidekor opened this issue Jul 14, 2024 · 1 comment
Open

speaker on core 2 #118

slidekor opened this issue Jul 14, 2024 · 1 comment

Comments

@slidekor
Copy link

I am trying to use the speaker so that it works when the button is pressed, but it turns on when it is turned on and does not respond to the button, how to fix it

@lovyan03
Copy link
Collaborator

Hello, @slidekor

Please try following code.
You should hear a sound when you touch the button area at the bottom of the screen.

#include <M5Unified.h>

void setup() {
  M5.begin();
}

void loop() {
  M5.update();

  if (M5.BtnA.wasPressed()) {
    M5.Speaker.tone(800, 100);
  }
  if (M5.BtnB.wasPressed()) {
    M5.Speaker.tone(1600, 100);
  }
  if (M5.BtnC.wasPressed()) {
    M5.Speaker.tone(3200, 100);
  }

  M5.Display.fillRoundRect(  0, 10, 100, 100, 10, M5.BtnA.isPressed() ? TFT_YELLOW : TFT_RED);
  M5.Display.fillRoundRect(100, 10, 100, 100, 10, M5.BtnB.isPressed() ? TFT_YELLOW : TFT_RED);
  M5.Display.fillRoundRect(200, 10, 100, 100, 10, M5.BtnC.isPressed() ? TFT_YELLOW : TFT_RED);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants