diff --git a/docs/zh_CN/api.md b/docs/zh_CN/api.md index 5214aa82..d61e3f0f 100644 --- a/docs/zh_CN/api.md +++ b/docs/zh_CN/api.md @@ -1,8 +1,9 @@ -# API参考 +# API参考 {docsify-ignore-all} ||| |:---:|:---:| |**[LCD](zh_CN/api/lcd)** | **[Speaker](zh_CN/api/speaker)** | +|**[Button](zh_CN/api/button)** | **[MPU9250](zh_CN/api/mpu9250)** | diff --git a/docs/zh_CN/api/button.md b/docs/zh_CN/api/button.md new file mode 100644 index 00000000..ea94577e --- /dev/null +++ b/docs/zh_CN/api/button.md @@ -0,0 +1,102 @@ +# 按键 + +### isPressed() + +**函数原型:** + +isPressed(); // for arduino + + + +**功能:返回键值。如果指定按键奇数次数按下后,一直返回 1,偶数次数按下,一直返回 0。** + +**例程** +```arduino +#include + +void setup(){ + M5.begin(); +} + +void loop(){ + if(M5.BtnA.isPressed()) { // for button A + Serial.printf("A\r\n"); + } + M5.update(); +} +``` + +### wasPressed() + +**函数原型:** + +wasPressed(); // for arduino + + + +**功能:返回键值。如果指定按键按下,则返回 1 一次,然后置位为0,否则一直返回 0。** + +**例程** +```arduino +#include + +void setup(){ + M5.begin(); +} + +void loop(){ + if(M5.BtnA.wasPressed()) { // for button A + M5.Lcd.printf("A"); + Serial.printf("A"); + } + M5.update(); +} +``` + + +* * * + +### pressedFor() + +**函数原型:** + +pressedFor(uint32_t ms); // for arduino + + + +**功能:返回键值。如果指定按键按下超过指定时间之后,则返回 1,否则返回 0。** + +| 参数 | 描述 | +| --- | --- | +| ms | 按键按下时间 (单位:毫秒) | + +**例程** +```arduino +#include + +void setup(){ + M5.begin(); +} + +void loop(){ + if(M5.BtnA.pressedFor(2000)) { // for button A + Serial.printf("A"); + } + M5.update(); +} +``` + + + \ No newline at end of file diff --git a/docs/zh_CN/api/gpio.md b/docs/zh_CN/api/gpio.md deleted file mode 100644 index 879a7088..00000000 --- a/docs/zh_CN/api/gpio.md +++ /dev/null @@ -1,21 +0,0 @@ -# GPIO {docsify-ignore-all} - -*使用Arduino库的GPIO API* - -### digitalRead -> uint32 digitalRead(uint8 pin); - -读取数字引脚电平值 - -| Param | Type | Description | -| --- | --- | --- | -| pin | uint8 | 引脚编号 | - -Return: - 电平值(0/1) - -**例程** -```arduino -uint32_t pin21_data; -pin21_data = digitalRead(21); -``` \ No newline at end of file diff --git a/docs/zh_CN/api/speaker.md b/docs/zh_CN/api/speaker.md index 17467053..171eb32a 100644 --- a/docs/zh_CN/api/speaker.md +++ b/docs/zh_CN/api/speaker.md @@ -1,4 +1,4 @@ -# Speaker +# 喇叭 ### tone > M5.Speaker.tone(uint32_t freq); @@ -12,4 +12,37 @@ **例程** ```arduino M5.Speaker.tone(100); -``` \ No newline at end of file +``` + +### tone() + +**函数原型:** + +tone(uint16_t freq); // for arduino +tone(uint16_t freq, uint32_t duration); // for arduino + + +**功能:喇叭响指定频率的声音持续指定时间。** + +| 参数 | 描述 | +| --- | --- | +| freq | 声音频率 | +| duration | 持续时间 (单位:毫秒) | + +*如果函数的 duration 值没给出,则使用当前的背景颜色。* + +**例程** +```arduino +#include + +M5.begin(); + +M5.Speaker.tone(900, 1000); +``` + \ No newline at end of file