|
1 | 1 | /* |
2 | 2 | ******************************************************************************* |
3 | | -* Copyright (c) 2021 by M5Stack |
| 3 | +* Copyright (c) 2023 by M5Stack |
4 | 4 | * Equipped with M5Core2 sample source code |
5 | 5 | * 配套 M5Core2 示例源代码 |
6 | 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 |
7 | 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 |
8 | 8 | * |
9 | 9 | * Describe: Speaker example. 喇叭示例 |
10 | | -* Date: 2022/7/26 |
| 10 | +* Date: 2023/7/31 |
11 | 11 | ******************************************************************************* |
12 | 12 | */ |
13 | 13 | #include <M5Core2.h> |
14 | 14 |
|
| 15 | +extern const unsigned char previewR[120264]; |
| 16 | + |
| 17 | +void DisplayInit(void) { // Initialize the display. 显示屏初始化 |
| 18 | + M5.Lcd.fillScreen(WHITE); // Set the screen background color to white. |
| 19 | + // 设置屏幕背景色为白色 |
| 20 | + M5.Lcd.setTextColor( |
| 21 | + BLACK); // Set the text color to black. 设置文字颜色为黑色 |
| 22 | + M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2 |
| 23 | +} |
| 24 | + |
| 25 | +/* After M5Core2 is started or reset |
| 26 | +the program in the setUp () function will be run, and this part will only be run once. |
| 27 | +在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ |
| 28 | +void setup() { |
| 29 | + M5.begin(true, true, true, true, mbus_mode_t::kMBusModeOutput, |
| 30 | + true); // Init M5Core2. 初始化 M5Core2 |
| 31 | + DisplayInit(); |
| 32 | + M5.Lcd.setTextColor(RED); |
| 33 | + M5.Lcd.setCursor(10, |
| 34 | + 10); // Set the cursor at (10,10). 将光标设在(10,10)处 |
| 35 | + M5.Lcd.printf("Speak Test!"); // The screen prints the formatted string and |
| 36 | + // wraps it. 屏幕打印格式化字符串并换行 |
| 37 | + M5.Lcd.setTextColor(BLACK); |
| 38 | + M5.Lcd.setCursor(10, 26); |
| 39 | + M5.Lcd.printf("Press Left Button to listen DingDong!"); |
| 40 | + M5.Spk.PlaySound( |
| 41 | + previewR, |
| 42 | + sizeof(previewR)); // Play the DingDong sound. 播放 DingDong 声音 |
| 43 | + delay(100); |
| 44 | +} |
| 45 | + |
| 46 | +/* After the program in setup() runs, it runs the program in loop() |
| 47 | +The loop() function is an infinite loop in which the program runs repeatedly |
| 48 | +在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 |
| 49 | +loop()函数是一个死循环,其中的程序会不断的重复运行 */ |
| 50 | +void loop() { |
| 51 | + TouchPoint_t pos = |
| 52 | + M5.Touch.getPressPoint(); // Stores the touch coordinates in pos. |
| 53 | + // 将触摸坐标存储在pos.内 |
| 54 | + if (pos.y > 240) |
| 55 | + if (pos.x < 109) { |
| 56 | + M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达 |
| 57 | + delay(100); |
| 58 | + M5.Axp.SetLDOEnable(3, false); |
| 59 | + delay(100); |
| 60 | + M5.Spk.PlaySound( |
| 61 | + previewR, |
| 62 | + sizeof(previewR)); // Play the DingDong sound. 播放 DingDong 声音 |
| 63 | + } |
| 64 | + delay(10); |
| 65 | +} |
| 66 | + |
15 | 67 | const unsigned char previewR[120264] = { |
16 | 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
17 | 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
@@ -10035,53 +10087,3 @@ const unsigned char previewR[120264] = { |
10035 | 10087 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
10036 | 10088 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
10037 | 10089 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
10038 | | - |
10039 | | -void DisplayInit(void) { // Initialize the display. 显示屏初始化 |
10040 | | - M5.Lcd.fillScreen(WHITE); // Set the screen background color to white. |
10041 | | - // 设置屏幕背景色为白色 |
10042 | | - M5.Lcd.setTextColor( |
10043 | | - BLACK); // Set the text color to black. 设置文字颜色为黑色 |
10044 | | - M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2 |
10045 | | -} |
10046 | | - |
10047 | | -//在 M5Core |
10048 | | -//启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 |
10049 | | -void setup() { |
10050 | | - M5.begin(true, true, true, true, mbus_mode_t::kMBusModeOutput, |
10051 | | - true); // Init M5Core2. 初始化 M5Core2 |
10052 | | - DisplayInit(); |
10053 | | - M5.Lcd.setTextColor(RED); |
10054 | | - M5.Lcd.setCursor(10, |
10055 | | - 10); // Set the cursor at (10,10). 将光标设在(10,10)处 |
10056 | | - M5.Lcd.printf("Speak Test!"); // The screen prints the formatted string and |
10057 | | - // wraps it. 屏幕打印格式化字符串并换行 |
10058 | | - M5.Lcd.setTextColor(BLACK); |
10059 | | - M5.Lcd.setCursor(10, 26); |
10060 | | - M5.Lcd.printf("Press Left Button to listen DingDong!"); |
10061 | | - M5.Spk.PlaySound( |
10062 | | - previewR, |
10063 | | - sizeof(previewR)); // Play the DingDong sound. 播放 DingDong 声音 |
10064 | | - delay(100); |
10065 | | -} |
10066 | | - |
10067 | | -/* After the program in setup() runs, it runs the program in loop() |
10068 | | -The loop() function is an infinite loop in which the program runs repeatedly |
10069 | | -在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 |
10070 | | -loop()函数是一个死循环,其中的程序会不断的重复运行 */ |
10071 | | -void loop() { |
10072 | | - TouchPoint_t pos = |
10073 | | - M5.Touch.getPressPoint(); // Stores the touch coordinates in pos. |
10074 | | - // 将触摸坐标存储在pos.内 |
10075 | | - if (pos.y > 240) |
10076 | | - if (pos.x < 109) { |
10077 | | - M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达 |
10078 | | - delay(100); |
10079 | | - M5.Axp.SetLDOEnable(3, false); |
10080 | | - delay(100); |
10081 | | - M5.Spk.PlaySound( |
10082 | | - previewR, |
10083 | | - sizeof( |
10084 | | - previewR)); // Play the DingDong sound. 播放 DingDong 声音 |
10085 | | - } |
10086 | | - delay(10); |
10087 | | -} |
|
0 commit comments