初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: Button example. 按键示例
* date: 2021/7/21
*******************************************************************************
*/
#include <M5Core2.h>
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core2 启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup() {
M5.begin(); //Init M5Core. 初始化 M5Core2
M5.Lcd.setTextColor(YELLOW); //Set the font color to yellow. 设置字体颜色为黄色
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小为2
M5.Lcd.setCursor(65, 10); //Move the cursor position to (x, y). 移动光标位置到 (x, y)处
M5.Lcd.println("Button example"); //The screen prints the formatted string and wraps the line. 输出格式化字符串并换行
M5.Lcd.setCursor(3, 35);
M5.Lcd.println("Press button B for 700ms");
M5.Lcd.println("to clear screen.");
M5.Lcd.setTextColor(RED);
}
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
M5.update(); //Read the press state of the key. 读取按键 A, B, C 的状态
if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) {
M5.Lcd.print('A');
} else if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) {
M5.Lcd.print('B');
} else if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) {
M5.Lcd.print('C');
} else if (M5.BtnB.wasReleasefor(700)) {
M5.Lcd.clear(WHITE); // Clear the screen and set white to the background color. 清空屏幕并将白色设置为底色
M5.Lcd.setCursor(0, 0);
}
}

View File

@@ -0,0 +1,60 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: Display Example. 显示屏示例
* date: 2021/7/21
*******************************************************************************
*/
#include <M5Core2.h>
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core2 启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup() {
M5.begin(); //Init M5Core2. 初始化 M5Core2
M5.Lcd.fillScreen(WHITE); // Set the screen background. 设置屏幕底色为白色
delay(500); //Delay 500ms. 延迟500ms
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(GREEN);
delay(500);
M5.Lcd.fillScreen(BLUE);
delay(500);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.setCursor(10, 10); //Move the cursor position to (x,y). 移动光标位置到 (x,y)处
M5.Lcd.setTextColor(WHITE); //Set the font color to white. 设置字体颜色为白色
M5.Lcd.setTextSize(1); //Set the font size. 设置字体大小
M5.Lcd.printf("Display Test!"); //Serial output format string. 输出格式化字符串
// draw graphic
delay(1000);
M5.Lcd.drawRect(100, 100, 50, 50, BLUE); //Draw a 50x50 blue rectangle wireframe at (x,y).
delay(1000); //在x,y处画 长宽为50x50的蓝色矩形线框
M5.Lcd.fillRect(100, 100, 50, 50, BLUE);//Draw a blue rectangle 50x50 at (x,y)
delay(1000); //在x,y处画 长宽为50x50的蓝色矩形
M5.Lcd.drawCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
delay(1000); //在x,y处画 半径为50的红色圆线圈
M5.Lcd.fillCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
delay(1000); //在x,y处画 半径为50的红色圆
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); //Make a triangle wireframe with (x1,y1) (x2,y2) (x3,y3) as the vertices
delay(1000); //以 (x1,y1) (x2,y2) (x3,y3)为顶点作三角形线框
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW); //以 (x1,y1) (x2,y2) (x3,y3)为顶点作三角形
} // Construct a triangle with (x1,y1) (x2,y2) (x3,y3) as its vertices
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop(){
M5.Lcd.fillTriangle(random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(0xfffe));
M5.update(); //Read the press state of the key. 读取按键 A, B, C 的状态
}

View File

@@ -0,0 +1,32 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: Hello World
* date: 2021/7/21
*******************************************************************************
*/
#include <M5Core2.h>
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core2 启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup(){
M5.begin(); //Init M5Core2. 初始化 M5Core2
/* Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project */
M5.Lcd.print("Hello World"); // Print text on the screen (string) 在屏幕上打印文本(字符串)
}
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
}

View File

@@ -0,0 +1,76 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: MPU6886 example. 惯性传感器
* date: 2021/7/21
*******************************************************************************
*/
#include <M5Core2.h>
float accX = 0.0F; // Define variables for storing inertial sensor data
float accY = 0.0F; //定义存储惯性传感器相关数据的相关变量
float accZ = 0.0F;
float gyroX = 0.0F;
float gyroY = 0.0F;
float gyroZ = 0.0F;
float pitch = 0.0F;
float roll = 0.0F;
float yaw = 0.0F;
float temp = 0.0F;
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core2 启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup(){
M5.begin(); //Init M5Core. 初始化 M5Core
M5.IMU.Init(); //Init IMU sensor. 初始化惯性传感器
M5.Lcd.fillScreen(BLACK); //Set the screen background color to black. 设置屏幕背景色为黑色
M5.Lcd.setTextColor(GREEN , BLACK); //Sets the foreground color and background color of the displayed text. 设置显示文本的前景颜色和背景颜色
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小
}
void loop() {
//Stores the triaxial gyroscope data of the inertial sensor to the relevant variable
//将惯性传感器的三轴陀螺仪数据存储至相关变量
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
M5.IMU.getAccelData(&accX,&accY,&accZ); //Stores the triaxial accelerometer. 存储三轴加速度计数据
M5.IMU.getAhrsData(&pitch,&roll,&yaw); //Stores the inertial sensor attitude. 存储惯性传感器的姿态
M5.IMU.getTempData(&temp); //Stores the inertial sensor temperature to temp. 存储惯性传感器的温度
/* The M5Core screen is 320x240 pixels, starting at the top left corner of the screen (0,0).
gyroscope output related
M5Core2屏幕像素为 320x240,以屏幕左上角为原点 (0,0)*/
//gyroscope output related. 陀螺仪输出相关
M5.Lcd.setCursor(0, 20); //Move the cursor position to (x,y). 移动光标位置到(x,y)处
M5.Lcd.printf("gyroX, gyroY, gyroZ"); //Screen printingformatted string. 输出格式化字符串
M5.Lcd.setCursor(0, 42);
M5.Lcd.printf("%6.2f %6.2f%6.2f o/s", gyroX, gyroY, gyroZ);
// Accelerometer output is related
//加速度计输出相关
M5.Lcd.setCursor(0, 70);
M5.Lcd.printf("accX, accY, accZ");
M5.Lcd.setCursor(0, 92);
M5.Lcd.printf("%5.2f %5.2f %5.2f G", accX, accY, accZ);
// Pose output is related
//姿态输出相关
M5.Lcd.setCursor(0, 120);
M5.Lcd.printf("pitch, roll, yaw");
M5.Lcd.setCursor(0, 142);
M5.Lcd.printf("%5.2f %5.2f %5.2f deg", pitch, roll, yaw);
// Inertial sensor temperature output related
//惯性传感器温度输出相关
M5.Lcd.setCursor(0, 175);
M5.Lcd.printf("Temperature : %.2f C", temp);
delay(10); // Delay 10ms. 延迟10ms
}

View File

@@ -0,0 +1,142 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: NS4168--I2S power amplifier. 功放示例
* date: 2022/2/22
*******************************************************************************
*/
#include <M5Core2.h>
#include <driver/i2s.h>
#define CONFIG_I2S_BCK_PIN 12 // Define I2S related ports. 定义I2S相关端口
#define CONFIG_I2S_LRCK_PIN 0
#define CONFIG_I2S_DATA_PIN 2
#define CONFIG_I2S_DATA_IN_PIN 34
#define Speak_I2S_NUMBER I2S_NUM_0 // Define the speaker port. 定义扬声器端口
#define MODE_MIC 0 // Define the working mode. 定义工作模式
#define MODE_SPK 1
#define DATA_SIZE 1024
uint8_t microphonedata0[1024 * 100];
int data_offset = 0;
bool InitI2SSpeakOrMic(int mode) { // Init I2S. 初始化I2S
esp_err_t err = ESP_OK;
i2s_driver_uninstall(
Speak_I2S_NUMBER); // Uninstall the I2S driver. 卸载I2S驱动
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode.
// 设置I2S工作模式
.sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率
.bits_per_sample =
I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB.
// 固定为12位立体声MSB
.channel_format =
I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式
.communication_format =
I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication.
// 设置通讯格式
.intr_alloc_flags =
ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志
.dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数
.dma_buf_len = 128, // DMA buffer length. DMA缓冲区长度
};
if (mode == MODE_MIC) {
i2s_config.mode =
(i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM);
} else {
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
i2s_config.use_apll = false; // I2S clock setup. I2S时钟设置
i2s_config.tx_desc_auto_clear =
true; // Enables auto-cleanup descriptors for understreams.
// 开启欠流自动清除描述符
}
// Install and drive I2S. 安装并驱动I2S
err += i2s_driver_install(Speak_I2S_NUMBER, &i2s_config, 0, NULL);
i2s_pin_config_t tx_pin_config;
#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0))
tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE;
#endif
tx_pin_config.bck_io_num =
CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin.
// 将BCK链接至CONFIG_I2S_BCK_PIN引脚
tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ...
tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ...
tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; // ...
err +=
i2s_set_pin(Speak_I2S_NUMBER,
&tx_pin_config); // Set the I2S pin number. 设置I2S引脚编号
err += i2s_set_clk(
Speak_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT,
I2S_CHANNEL_MONO); // Set the clock and bitwidth used by I2S Rx and Tx.
// 设置I2S RX、Tx使用的时钟和位宽
return true;
}
void DisplayInit(void) { // Initialize the display. 显示屏初始化
M5.Lcd.fillScreen(WHITE); // Set the screen background color to white.
// 设置屏幕背景色为白色
M5.Lcd.setTextColor(
BLACK); // Set the text color to black. 设置文字颜色为黑色
M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2
}
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run
once. 在 M5Core2
启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup() {
M5.begin(true, true, true, true); // Init M5Core2. 初始化 M5Core2
M5.Axp.SetSpkEnable(true); // Enable speaker power. 启用扬声器电源
DisplayInit();
M5.Lcd.setTextColor(RED);
M5.Lcd.setCursor(10,
10); // Set the cursor at (10,10). 将光标设在1010
M5.Lcd.printf("Recorder!"); // The screen prints the formatted string and
// wraps it. 屏幕打印格式化字符串并换行
M5.Lcd.setTextColor(BLACK);
M5.Lcd.setCursor(10, 26);
M5.Lcd.printf("Press Left Button to recording!");
delay(100); // delay 100ms. 延迟100ms
}
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
TouchPoint_t pos =
M5.Touch.getPressPoint(); // Stores the touch coordinates in pos.
// 将触摸坐标存储在pos.内
if (pos.y > 240) {
if (pos.x < 109) {
M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达
delay(100);
M5.Axp.SetLDOEnable(3, false);
data_offset = 0;
InitI2SSpeakOrMic(MODE_MIC);
size_t byte_read;
while (1) {
i2s_read(Speak_I2S_NUMBER,
(char *)(microphonedata0 + data_offset), DATA_SIZE,
&byte_read, (100 / portTICK_RATE_MS));
data_offset += 1024;
if (data_offset == 1024 * 100 || M5.Touch.ispressed() != true)
break;
}
size_t bytes_written;
InitI2SSpeakOrMic(MODE_SPK);
i2s_write(Speak_I2S_NUMBER, microphonedata0, data_offset,
&bytes_written, portMAX_DELAY);
}
}
}

View File

@@ -0,0 +1,66 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: RTC--实时时钟示例
* date: 2022/1/9
*******************************************************************************
*/
#include <M5Core2.h>
RTC_TimeTypeDef RTCtime;
RTC_DateTypeDef RTCDate;
char timeStrbuff[64];
void flushTime() {
M5.Rtc.GetTime(&RTCtime); // Gets the time in the real-time clock.
// 获取实时时钟内的时间
M5.Rtc.GetDate(&RTCDate);
sprintf(timeStrbuff, "%d/%02d/%02d %02d:%02d:%02d", RTCDate.Year,
RTCDate.Month, RTCDate.Date, RTCtime.Hours, RTCtime.Minutes,
RTCtime.Seconds);
// Stores real-time time and date data
// to timeStrbuff.
// 将实时时间、日期数据存储至timeStrbuff
M5.lcd.setCursor(10, 100);
// Move the cursor position to (x,y). 移动光标位置到(x,y)处
M5.Lcd.println(timeStrbuff);
// Output the contents of. 输出timeStrbuff中的内容
}
void setupTime() {
RTCtime.Hours = 16; // Set the time. 设置时间
RTCtime.Minutes = 51;
RTCtime.Seconds = 20;
if (!M5.Rtc.SetTime(&RTCtime)) Serial.println("wrong time set!");
// and writes the set time to the real
// time clock. 并将设置的时间写入实时时钟
RTCDate.Year = 2022; // Set the date. 设置日期
RTCDate.Month = 1;
RTCDate.Date = 9;
if (!M5.Rtc.SetDate(&RTCDate)) Serial.println("wrong date set!");
}
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run
once. 在 M5Core2
启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup() {
M5.begin(); // Init M5Core2. 初始化 M5Core2
delay(1000);
setupTime();
M5.Lcd.setTextSize(2); // Set the text size. 设置文本大小
}
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
flushTime();
delay(1000);
}

View File

@@ -0,0 +1,56 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: RTC--时间管理示例
* date: 2021/7/21
*******************************************************************************
*/
#include <M5Core2.h>
RTC_TimeTypeDef RTCtime;
RTC_TimeTypeDef RTCtime_Now;
char timeStrbuff[64];
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core2 启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup(){
M5.begin(); //Init M5Core2. 初始化 M5Stack
RTCtime.Hours = 10; // Set the time. 设置时间
RTCtime.Minutes = 30;
RTCtime.Seconds = 45;
M5.Lcd.setCursor(0,80); // Move the cursor position to (x,y). 移动光标位置到(x,y)处
M5.Lcd.println("BtnA: shutdown, use power button to turn back on"); // The screen prints the formatted string and wraps it. 屏幕打印格式化字符串并换行
M5.Lcd.println("BtnB: shutdown, wake up after 5 seconds");
M5.Lcd.printf("BtnC: shutdown, wake up at RTC Time %d:%d:%d",RTCtime.Hours,RTCtime.Minutes, RTCtime.Seconds);
}
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop(){
M5.update(); //Read the status of keys A, B, and C. 读取按键 A, B, C 的状态
if(M5.BtnA.wasPressed()){ //Constantly check the status of keys A, B, and C, if A press..... 不断检测按键A、B、C的状态如果A按下....
M5.shutdown(); //Turn off the power. 关闭电源
}else if(M5.BtnB.wasPressed()){
M5.shutdown(5); //Turn off the power and wake up again after 5 seconds. 关闭电源,5秒后再次唤醒
}else if(M5.BtnC.wasPressed()){
M5.shutdown(RTCtime); //Turn off the power and wake up at the specified time. 关闭电源,在指定时间唤醒
}
M5.Lcd.setCursor(0,140);
M5.Rtc.GetTime(&RTCtime_Now); //Gets the current time. 获取当前时间
sprintf(timeStrbuff,"RTC Time Now is %02d:%02d:%02d", //Stores real-time time data to timeStrbuff. 将实时时间数据存储至timeStrbuff
RTCtime_Now.Hours,RTCtime_Now.Minutes,RTCtime_Now.Seconds);
M5.Lcd.println(timeStrbuff); //Screen printing output timeStrbuff. 输出timeStrbuff
}

View File

@@ -0,0 +1,46 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: Sleep--Axp电源休眠
* date: 2022/3/12
*******************************************************************************
*/
#include <M5Core2.h>
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core2 启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup(){
M5.begin(); //Init M5Core2. 初始化 M5Core2
M5.Lcd.setTextFont(2); //Set font size to 2. 设置字体大小为2
Serial.println("Light / Deep Sleep Test."); //The serial port prints the formatted string with a newline. 串口输出格式化字符串并换行
M5.Lcd.println("Light / Deep Sleep Test."); //The screen prints the formatted string and wraps it. 屏幕打印格式化字符串并换行
Serial.println("Going to light sleep for 5 seconds.");
M5.Lcd.println("Going to light sleep for 5 seconds.");
delay(2500); //delay 2500ms. 延迟2500ms
M5.Axp.LightSleep(SLEEP_SEC(5)); //Wake up after 5 seconds of light sleep, the CPU will reboot and the program will start from the beginning. 轻度睡眠10秒后重新启动程序从下一行继续执行
Serial.println("Wakeup from light sleep.");
M5.Lcd.println("Wakeup from light sleep.");
delay(1000);
Serial.println("Going to deep sleep for 5 seconds.");
M5.Lcd.println("Going to deep sleep for 5 seconds.");
delay(2500);
M5.Axp.DeepSleep(SLEEP_SEC(5)); //Wake up after 5 seconds of deep sleep, the CPU will reboot and the program will start from the beginning. 深度睡眠5秒后唤醒,CPU将重新启动程序将从头开始执行
}
void loop()
{
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,141 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
*
* describe: Speaker example. 喇叭示例
* date: 2022/2/22
*******************************************************************************
*/
#include <M5Core2.h>
#include <driver/i2s.h>
extern const unsigned char
previewR[120264]; // Referring to external data (Dingdong audio files are
// stored inside).
// 引用外部数据dingdong音频文件存储在内
#define CONFIG_I2S_BCK_PIN 12 //定义I2S相关端口
#define CONFIG_I2S_LRCK_PIN 0
#define CONFIG_I2S_DATA_PIN 2
#define CONFIG_I2S_DATA_IN_PIN 34
#define Speak_I2S_NUMBER I2S_NUM_0 //定义扬声器端口
#define MODE_MIC 0 //定义工作模式
#define MODE_SPK 1
#define DATA_SIZE 1024
bool InitI2SSpeakOrMic(int mode) { // Init I2S. 初始化I2S
esp_err_t err = ESP_OK;
i2s_driver_uninstall(
Speak_I2S_NUMBER); // Uninstall the I2S driver. 卸载I2S驱动
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode.
// 设置I2S工作模式
.sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率
.bits_per_sample =
I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB.
// 固定为12位立体声MSB
.channel_format =
I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式
.communication_format =
I2S_COMM_FORMAT_I2S, // Set the format of the communication.
// 设置通讯格式
.intr_alloc_flags =
ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志
.dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数
.dma_buf_len = 128, // DMA buffer length. DMA缓冲区长度
};
if (mode == MODE_MIC) {
i2s_config.mode =
(i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM);
} else {
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
i2s_config.use_apll = false; // I2S clock setup. I2S时钟设置
i2s_config.tx_desc_auto_clear =
true; // Enables auto-cleanup descriptors for understreams.
// 开启欠流自动清除描述符
}
// Install and drive I2S. 安装并驱动I2S
err += i2s_driver_install(Speak_I2S_NUMBER, &i2s_config, 0, NULL);
i2s_pin_config_t tx_pin_config;
#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0))
tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE;
#endif
tx_pin_config.bck_io_num =
CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin.
// 将BCK链接至CONFIG_I2S_BCK_PIN引脚
tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ...
tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ...
tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; // ...
err +=
i2s_set_pin(Speak_I2S_NUMBER,
&tx_pin_config); // Set the I2S pin number. 设置I2S引脚编号
err += i2s_set_clk(
Speak_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT,
I2S_CHANNEL_MONO); // Set the clock and bitwidth used by I2S Rx and Tx.
// 设置I2S RX、Tx使用的时钟和位宽
return true;
}
void DisplayInit(void) { // Initialize the display. 显示屏初始化
M5.Lcd.fillScreen(WHITE); // Set the screen background color to white.
// 设置屏幕背景色为白色
M5.Lcd.setTextColor(
BLACK); // Set the text color to black. 设置文字颜色为黑色
M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2
}
void SpeakInit(void) { // 初始化扬声器
M5.Axp.SetSpkEnable(true); //启用扬声器电源
InitI2SSpeakOrMic(MODE_SPK);
}
void DingDong(void) {
size_t bytes_written = 0;
i2s_write(Speak_I2S_NUMBER, previewR, 120264, &bytes_written,
portMAX_DELAY);
}
//在 M5Core
//启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。
void setup() {
M5.begin(true, true, true, true); // Init M5Core2. 初始化 M5Core2
DisplayInit();
M5.Lcd.setTextColor(RED);
M5.Lcd.setCursor(10,
10); // Set the cursor at (10,10). 将光标设在1010
M5.Lcd.printf("Speak Test!"); // The screen prints the formatted string and
// wraps it. 屏幕打印格式化字符串并换行
M5.Lcd.setTextColor(BLACK);
M5.Lcd.setCursor(10, 26);
M5.Lcd.printf("Press Left Button to listen DingDong!");
SpeakInit();
DingDong();
delay(100);
}
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
TouchPoint_t pos =
M5.Touch.getPressPoint(); // Stores the touch coordinates in pos.
// 将触摸坐标存储在pos.内
if (pos.y > 240)
if (pos.x < 109) {
M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达
delay(100);
M5.Axp.SetLDOEnable(3, false);
DingDong();
}
delay(10);
}

View File

@@ -0,0 +1,68 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: TF Card. TF卡
* date: 2022/3/25
*******************************************************************************
In this example, we will detect the existence of a file and perform read and
write operations on it
在这个示例中,我们将会检测某文件是否存在,并进行读写文件操作
*/
#include <M5Core2.h>
void setup() {
M5.begin();
if (!SD.begin()) { // Initialize the SD card. 初始化SD卡
M5.Lcd.println(
"Card failed, or not present"); // Print a message if the SD card
// initialization fails or if the
// SD card does not exist
// 如果SD卡初始化失败或者SD卡不存在则打印消息
while (1)
;
}
M5.Lcd.println("TF card initialized.");
if (SD.exists("/hello.txt")) { // Check if the "/hello.txt" file
// exists.查看是否存在"/hello.txt"文件
M5.Lcd.println("hello.txt exists.");
} else {
M5.Lcd.println("hello.txt doesn't exist.");
}
M5.Lcd.println("Creating hello.txt");
File myFile = SD.open("/hello.txt",
FILE_WRITE); // Create a new file "/hello.txt".
// 创建一个新文件"/hello.txt"
if (myFile) { // If the file is open, then write to it.
// 如果文件打开,则进行写入操作
M5.Lcd.println("Writing to test.txt...");
myFile.println("SD test.");
myFile.close(); // Close the file. 关闭文件
M5.Lcd.println("done.");
} else {
M5.Lcd.println("error opening test.txt");
}
delay(500);
myFile = SD.open("/hello.txt",
FILE_READ); // Open the file "/hello.txt" in read mode.
// 以读取模式打开文件"/hello.txt"
if (myFile) {
M5.Lcd.println("/hello.txt Content:");
// Read the data from the file and print it until the reading is
// complete. 从文件里读取数据并打印到串口,直到读取完成.
while (myFile.available()) {
M5.Lcd.write(myFile.read());
}
myFile.close();
} else {
M5.Lcd.println("error opening /hello.txt"); // If the file is not open.
// 如果文件没有打开
}
}
void loop() {}

View File

@@ -0,0 +1,31 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
*
* describe: vibrate example. 震动电机示例
* date: 2021/9/18
*******************************************************************************
*/
#include <M5Core2.h>
/* After M5Core2 is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core2 启动或者复位后即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup() {
M5.begin(); //Init M5Core2. 初始化 M5Core2
}
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
M5.Axp.SetLDOEnable(3,true); //Open the vibration. 开启震动马达
delay(1000);
M5.Axp.SetLDOEnable(3,false); //Open the vibration. 关闭震动马达
delay(1000);
}