add button and speaker api doc

This commit is contained in:
LiHuashen
2019-02-14 17:15:34 +08:00
parent 23e8658d56
commit c8556e13d5
4 changed files with 139 additions and 24 deletions
+2 -1
View File
@@ -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)** |
<!-- |[BUTTON](zh_CN/api_reference/micropython/api_lcd) | [BUTTON](zh_CN/api_reference/arduino/api_lcd) |
|[SPEAKER](zh_CN/api_reference/micropython/api_lcd) | [SPEAKER](zh_CN/api_reference/arduino/api_lcd) | -->
+102
View File
@@ -0,0 +1,102 @@
# 按键
### isPressed()
**函数原型:**
<mark>isPressed();</mark> // for arduino
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:返回键值。如果指定按键奇数次数按下后,一直返回 1,偶数次数按下,一直返回 0。**
**例程**
```arduino
#include <M5Stack.h>
void setup(){
M5.begin();
}
void loop(){
if(M5.BtnA.isPressed()) { // for button A
Serial.printf("A\r\n");
}
M5.update();
}
```
### wasPressed()
**函数原型:**
<mark>wasPressed();</mark> // for arduino
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:返回键值。如果指定按键按下,则返回 1 一次,然后置位为0,否则一直返回 0。**
**例程**
```arduino
#include <M5Stack.h>
void setup(){
M5.begin();
}
void loop(){
if(M5.BtnA.wasPressed()) { // for button A
M5.Lcd.printf("A");
Serial.printf("A");
}
M5.update();
}
```
<!-- ```python
# MicroPython
from m5stack import *
from m5ui import *
lcd.fillScreen(lcd.RED)
``` -->
* * *
### pressedFor()
**函数原型:**
<mark>pressedFor(uint32_t ms);</mark> // for arduino
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:返回键值。如果指定按键按下超过指定时间之后,则返回 1,否则返回 0。**
| 参数 | 描述 |
| --- | --- |
| ms | 按键按下时间 (单位:毫秒) |
**例程**
```arduino
#include <M5Stack.h>
void setup(){
M5.begin();
}
void loop(){
if(M5.BtnA.pressedFor(2000)) { // for button A
Serial.printf("A");
}
M5.update();
}
```
<!-- ```python
# MicroPython
from m5stack import *
from m5ui import *
lcd.fillScreen(lcd.RED)
``` -->
<!-- * * * -->
-21
View File
@@ -1,21 +0,0 @@
# GPIO {docsify-ignore-all}
*使用Arduino库的GPIO API*
### <mark>digitalRead</mark>
> uint32 digitalRead(uint8 pin);
读取数字引脚电平值
| Param | Type | Description |
| --- | --- | --- |
| pin | <code>uint8</code> | 引脚编号 |
Return:
电平值(0/1)
**例程**
```arduino
uint32_t pin21_data;
pin21_data = digitalRead(21);
```
+35 -2
View File
@@ -1,4 +1,4 @@
# Speaker
# 喇叭
### <mark>tone</mark>
> M5.Speaker.tone(uint32_t freq);
@@ -12,4 +12,37 @@
**例程**
```arduino
M5.Speaker.tone(100);
```
```
### tone()
**函数原型:**
<mark>tone(uint16_t freq);</mark> // for arduino
<mark>tone(uint16_t freq, uint32_t duration);</mark> // for arduino
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:喇叭响指定频率的声音持续指定时间。**
| 参数 | 描述 |
| --- | --- |
| freq | 声音频率 |
| duration | 持续时间 (单位:毫秒) |
*如果函数的 duration 值没给出,则使用当前的背景颜色。*
**例程**
```arduino
#include <M5Stack.h>
M5.begin();
M5.Speaker.tone(900, 1000);
```
<!-- ```python
# MicroPython
from m5stack import *
from m5ui import *
lcd.fillScreen(lcd.RED)
``` -->