M5Unified
user_code.cpp
Go to the documentation of this file.
1 #include <M5Unified.h>
2 
3 void setup(void)
4 {
6  M5_LOGE("this is error LOG");
7  M5_LOGW("this is warning LOG");
8  M5_LOGI("this is info LOG");
9  M5_LOGD("this is debug LOG");
10  M5_LOGV("this is verbose LOG");
11 
12  M5.begin();
13  M5.Speaker.tone(2000, 100, 0, false);
14  M5.Speaker.tone(1000, 100, 0, false);
15 
16  M5.Display.printf("Please push cursor keys.\nButtonA == Left key\nButtonB == Down key\nButtonC == Right key\nButtonPWR == Up key\n");
17 }
18 
19 void loop(void)
20 {
21  M5.delay(8);
22  M5.update();
23  auto td = M5.Touch.getDetail();
24  if (td.isPressed()) {
25  M5.Display.fillCircle(td.x, td.y, 64, rand());
26  int32_t tone = 880 + td.x + td.y;
27  if (tone > 0) {
28  M5.Speaker.tone(tone, 50, 0);
29  }
30  }
31 
32  if (M5.BtnPWR.wasClicked()) {
33  M5.Speaker.tone(4000, 200);
34  M5_LOGD("BtnPWR Clicked");
35  }
36  if (M5.BtnA.wasClicked()) {
37  M5.Speaker.tone(2000, 200);
38  M5_LOGI("BtnA Clicked");
39  }
40  if (M5.BtnB.wasClicked()) {
41  M5.Speaker.tone(1000, 200);
42  M5_LOGW("BtnB Clicked");
43  }
44  if (M5.BtnC.wasClicked()) {
45  M5.Speaker.tone(500, 200);
46  M5_LOGE("BtnC Clicked");
47  }
48 }
49 
50 #if defined ( ESP_PLATFORM ) && !defined ( ARDUINO )
51 extern "C" {
52 int app_main(int, char**)
53 {
54  setup();
55  for (;;) {
56  loop();
57  }
58  return 0;
59 }
60 }
61 #endif
#define M5_LOGI(format,...)
Output Info log with source info.
Definition: Log_Class.hpp:30
#define M5_LOGE(format,...)
Output Error log with source info.
Definition: Log_Class.hpp:24
#define M5_LOGD(format,...)
Output Debug log with source info.
Definition: Log_Class.hpp:33
#define M5_LOGW(format,...)
Output Warn log with source info.
Definition: Log_Class.hpp:27
#define M5_LOGV(format,...)
Output Verbose log with source info.
Definition: Log_Class.hpp:36
m5::M5Unified M5
global instance.
Definition: M5Unified.cpp:32
bool wasClicked(void) const
Returns true when the button is pressed briefly and released.
void begin(void)
Perform initialization process at startup.
Definition: M5Unified.hpp:303
Button_Class BtnA
Definition: M5Unified.hpp:219
Button_Class BtnC
Definition: M5Unified.hpp:221
Button_Class BtnB
Definition: M5Unified.hpp:220
Button_Class BtnPWR
Definition: M5Unified.hpp:223
Touch_Class Touch
Definition: M5Unified.hpp:206
void update(void)
To call this function in a loop function.
Definition: M5Unified.cpp:1056
static void delay(uint32_t msec)
Definition: M5Unified.hpp:276
Speaker_Class Speaker
Definition: M5Unified.hpp:231
bool tone(float frequency, uint32_t duration, int channel, bool stop_current_sound, const uint8_t *raw_data, size_t array_len, bool stereo=false)
const touch_detail_t & getDetail(std::size_t index=0) const
Definition: Touch_Class.hpp:91
void loop(void)
Definition: user_code.cpp:19
void setup(void)
Definition: user_code.cpp:3