-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from Tinyu-Zhao/master
add some Ex&explain
- Loading branch information
Showing
76 changed files
with
6,213 additions
and
1,979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
/* | ||
在 src.h 文件中 GbkStr 显示为乱码为正常现象 | ||
HZK16为GB2312中文编码格式字库, 需要显示中文建议使用notepad++或其它软件(Arduino IDE 为UTF-8)通过编码GB2312打开str.h | ||
即可修改为个人想要输出中文字符 | ||
*/ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2021 by M5Stack | ||
* Equipped with M5Stick-C sample source code | ||
* 配套 M5Stick-C 示例源代码 | ||
* Visit the website for more information:https://docs.m5stack.com/en/core/m5stickc | ||
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/m5stickc | ||
* | ||
* describe:Character library. 字库 | ||
* date:2021/7/28 | ||
******************************************************************************* | ||
-----PLEASE SEE THE README---- | ||
------请在使用前看README文件----*/ | ||
#include <M5StickC.h> | ||
#include "str.h" | ||
|
||
void setup() { | ||
|
||
M5.begin(); | ||
|
||
M5.Lcd.loadHzk16(); | ||
|
||
M5.Lcd.setTextColor(WHITE, BLACK); | ||
|
||
M5.begin(); //Init M5StickC. 初始化M5StickC | ||
M5.Lcd.setRotation(3); //Rotate the screen. 旋转屏幕 | ||
M5.Lcd.loadHzk16(); //Load the Chinese character library (be sure to load before using the Chinese character library). 加载汉字库(务必在使用汉字库前加载) | ||
M5.Lcd.setTextColor(WHITE, BLACK);//Set the text color to white and the text background color to black (mandatory). 设置文字颜色为白色,文字背景颜色为黑色(必加) | ||
// Set text with red highlight color | ||
M5.Lcd.setHighlightColor(RED); | ||
|
||
// Set text size to 1 | ||
M5.Lcd.setTextSize(1); | ||
M5.Lcd.setCursor(0,0,1); | ||
M5.Lcd.writeHzk(AscStr); | ||
M5.Lcd.setHighlightColor(RED);//Set the text highlight color to red. 设置文字高亮颜色为红色 | ||
M5.Lcd.setTextSize(1);//Set text size to 1. 设置字号大小为1 Set text size to 1(必加) | ||
} | ||
|
||
void loop() { | ||
M5.Lcd.setCursor(0,0,1); //Set the cursor at (0,0) and the size to 1(mandatory). 将光标设置在(0,0)处,并设置字号为1(必加) | ||
M5.Lcd.writeHzk(AscStr); //Display the contents of AscStr here (which can be changed in str.h). 在此处显示AscStr中的内容(可在str.h中更改) | ||
// Print some ASCII text on the screen | ||
delay(1000); | ||
// Highlight the text | ||
M5.Lcd.highlight(true); | ||
M5.Lcd.setCursor(0,32); | ||
M5.Lcd.writeHzk(AscStr); | ||
delay(1000); | ||
// Clear screen | ||
//M5.Lcd.clear(); | ||
// Turn highlight off | ||
M5.Lcd.highlight(false); | ||
M5.Lcd.setCursor(0,70); | ||
// print some GBK text on the screen | ||
M5.Lcd.writeHzk(GbkStr); | ||
|
||
M5.Lcd.setCursor(0,40); | ||
M5.Lcd.writeHzk(GbkStr); //Display the contents of GbkStr here (which can be changed in str.h). 在此处显示GbkStr中的内容(可在str.h中更改) | ||
delay(1000); | ||
M5.Lcd.highlight(true); | ||
M5.Lcd.setCursor(0,90); | ||
//Highlight the text. 高亮显示文本 | ||
M5.Lcd.highlight(true); //Turn on highlight. 开启高亮显示 | ||
M5.Lcd.setCursor(0,60); | ||
M5.Lcd.writeHzk(GbkStr); | ||
|
||
|
||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
|
||
delay(1000); | ||
M5.Lcd.fillScreen(BLACK); //Fill the screen with black color, equivalent to empty the screen. 填充屏幕颜色为黑色,等效于清空屏幕 | ||
M5.Lcd.highlight(false); //Turn off highlight. 关闭高亮显示 | ||
delay(500); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
HZK16 is the GB2312 Chinese encoding format font, so it is normal that GbkStr is displayed as garbled in the src.h file | ||
To display Chinese normally, notepad++ or other software (UTF-8 for Arduino IDE) should be used to open str.h with encoding GB2312 | ||
Modify the content in GbkStr to replace it with the character you want to display | ||
|
||
HZK16为GB2312中文编码格式字库, 故在 src.h 文件中 GbkStr 显示为乱码为正常现象 | ||
若要正常显示中文应使用notepad++或其它软件(Arduino IDE 为UTF-8)使用编码GB2312打开str.h | ||
修改GbkStr里的内容即可更换为想要显示的字符 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2021 by M5Stack | ||
* Equipped with M5Stick-C sample source code | ||
* 配套 M5Stick-C 示例源代码 | ||
* Visit the website for more information:https://docs.m5stack.com/en/core/m5stickc | ||
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/m5stickc | ||
* | ||
* describe:Ellipse drawing. 椭圆绘制 | ||
* date:2021/7/27 | ||
*******************************************************************************/ | ||
|
||
#include <M5StickC.h> | ||
|
||
void setup(void) { | ||
M5.begin(); //Init M5Stick-C. 初始化M5Stick-C | ||
} | ||
|
||
void loop() { | ||
// Draw some random ellipses. 绘制一些随机形状的椭圆 | ||
for (int i = 0; i < 40; i++) | ||
{ | ||
int rx = random(40); | ||
int ry = random(40); | ||
int x = rx + random(80 - rx - rx); | ||
int y = ry + random(160 - ry - ry); | ||
M5.Lcd.fillEllipse(x, y, rx, ry, random(0xFFFF)); //At (x, y), draw a filled ellipse with random width and height of rx, ry with random color random (0xFFFF). 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的填充椭圆 | ||
} | ||
|
||
delay(2000); | ||
M5.Lcd.fillScreen(BLACK); //清空屏幕 | ||
|
||
for (int i = 0; i < 40; i++) | ||
{ | ||
int rx = random(40); | ||
int ry = random(40); | ||
int x = rx + random(80 - rx - rx); | ||
int y = ry + random(160 - ry - ry); | ||
M5.Lcd.drawEllipse(x, y, rx, ry, random(0xFFFF));//At (x, y), draw an elliptical wire frame with a random width and height of rx, ry in a random color (0xFFFF). 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的椭圆线框 | ||
} | ||
|
||
delay(2000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2021 by M5Stack | ||
* Equipped with M5Stick-C sample source code | ||
* 配套 M5Stick-C 示例源代码 | ||
* Visit the website for more information:https://docs.m5stack.com/en/core/m5stickc | ||
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/m5stickc | ||
* | ||
* describe:Hall sensor. 霍尔传感器 | ||
* date:2021/7/27 | ||
******************************************************************************* | ||
The ESP32 MCU has build in Hall sensor. ESP32 MCU内置霍尔传感器 | ||
It is not very suscescible but if you bring a magnet close to the | ||
upper screen you will see the influence on the measurement. | ||
In this example we use some low pass filters to get rid of the noise. | ||
*/ | ||
#include <M5StickC.h> | ||
|
||
#define HORIZONTAL_RESOLUTION 80 //屏幕水平分辨率 | ||
#define VERTICAL_RESOLUTION 160 //屏幕竖直分辨率 | ||
#define POSITION_OFFSET_Y 20 | ||
|
||
uint16_t oldSignal[HORIZONTAL_RESOLUTION]; | ||
|
||
float ESP32_hallRead() //ESP32 hall value read. ESP32霍尔值读取 | ||
{ | ||
float value = 0; | ||
int count = 400; | ||
// mean value filter. 数据低通滤波器 | ||
for (int n = 0; n < count; n++) value += hallRead(); | ||
return value / count * 10; | ||
} | ||
|
||
float HallOffset = 0; ////Store the initial value of magnetic force. 存储磁力的初值 | ||
|
||
void setup() | ||
{ | ||
M5.begin(); //Init M5Stick-C. 初始化M5Stick-C | ||
M5.Lcd.printf("\nESP32 Hall sensor:"); //Screen printout. 屏幕打印输出 | ||
HallOffset = ESP32_hallRead(); // callibrate the output value to the magnetic field at start up. 在启动时将输出值校准到磁场 | ||
} | ||
|
||
float LowPassFilteredValue=0; | ||
void showSignal() | ||
{ | ||
int n; | ||
|
||
int oldx; | ||
int oldy; | ||
int oldSig; | ||
int x, y; | ||
|
||
for (n = 0; n < HORIZONTAL_RESOLUTION; n++) //在水平分辨率内,每个像素点根据计算得到的磁力大小绘制 | ||
{ //Within the horizontal resolution, each pixel is drawn according to the calculated magnetic force | ||
x = n; | ||
float value = ESP32_hallRead()- HallOffset; //Reduce the influence of own magnetism. 减少自身磁力的影响 | ||
LowPassFilteredValue+=(value-LowPassFilteredValue)*0.05; | ||
M5.Lcd.setCursor(30, 17); | ||
M5.Lcd.print((int)LowPassFilteredValue); | ||
M5.Lcd.print(" "); | ||
M5.Lcd.setCursor(0, 40); | ||
y = map(value , -127, 127, VERTICAL_RESOLUTION, POSITION_OFFSET_Y); //将value映射至-30~30的范围内,以免绘制超出屏幕 | ||
|
||
if (n > 0) | ||
{ | ||
// delete old line element. 删除上次画的线 | ||
M5.Lcd.drawLine(oldx , oldSig, x, oldSignal[n], BLACK ); | ||
|
||
// draw new line element. 画新的线 | ||
if (n < HORIZONTAL_RESOLUTION - 1) // don't draw last element because it would generate artifacts. 不能绘制最后一个像素 | ||
{ | ||
M5.Lcd.drawLine(oldx,oldy,x,y, GREEN); | ||
} | ||
} | ||
oldx = x; | ||
oldy = y; | ||
oldSig = oldSignal[n]; | ||
oldSignal[n] = y; | ||
} | ||
} | ||
|
||
void loop(void) | ||
{ | ||
showSignal(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2021 by M5Stack | ||
* Equipped with M5Stick-C sample source code | ||
* 配套 M5Stick-C 示例源代码 | ||
* Visit the website for more information:https://docs.m5stack.com/en/core/m5stickc | ||
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/m5stickc | ||
* | ||
* describe:MultSerial. 多串口 | ||
* date:2021/8/5 | ||
****************************************************************************** | ||
*/ | ||
#include <M5StickC.h> | ||
|
||
void setup() { | ||
M5.begin(); //Init M5StickC. 初始化 M5StickC | ||
// Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert) | ||
Serial2.begin(115200, SERIAL_8N1, 16, 17); //Init serial port 2. 初始化串口2 | ||
} | ||
|
||
void loop() { | ||
if(Serial.available()) { //If the serial port reads data. 如果串口读到数据 | ||
int ch = Serial.read(); // Copy the data read from the serial port to the CH. 把串口读取到的数据复制给ch | ||
Serial2.write(ch); //Serial port 2 Outputs the CH content. 串口2输出ch的内容 | ||
} | ||
|
||
if(Serial2.available()) { | ||
int ch = Serial2.read(); | ||
Serial.write(ch); | ||
} | ||
} |
Oops, something went wrong.