update api en ja

This commit is contained in:
塩入孔章
2019-02-27 11:57:45 +08:00
parent 2e0383b8b7
commit f362e178ab
15 changed files with 1245 additions and 99 deletions
+129
View File
@@ -0,0 +1,129 @@
# ボタン
## read()
**説明:**
この関数はボタンの状態を直接読み出します。 1: pressed, 0: released.
**構文:**
```arduino
uint8_t read();
```
**使用例:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
}
void loop() {
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("Button A Status: ");
M5.Lcd.println(M5.BtnA.read());
}
```
## isPressed()
**説明:**
この関数は最後にM5.Button.read()を呼び出した時のボタンの状態を読み出します。1: pressed, 0: released.
**構文:**
```arduino
uint8_t isPressed();
```
**使用例:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
}
void loop() {
M5.update(); // update()を呼び出す必要があります。
M5.Lcd.setCursor(0, 0);
if (M5.BtnA.isPressed()) {
M5.Lcd.printf("A button is pressed.");
} else {
M5.Lcd.printf("A button is released.");
}
}
```
## wasPressed()
**構文:**
```arduino
uint8_t wasPressed();
```
**説明:**
この関数はボタンが押される度に一度だけ1を返します。 1: pressed, 0: released.
**使用例:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
}
void loop() {
M5.update();
M5.Lcd.clear();
M5.Lcd.setCursor(0, 0);
if (M5.BtnA.wasPressed()) {
M5.Lcd.printf("Button A was pressed.");
delay(1000);
}
}
```
## pressedFor()
**構文:**
```arduino
uint8_t pressedFor(uint32_t ms);
```
**説明:**
この関数は引数で指定した時間以上ボタンが押し続けられたら1を返します。 1: pressed, 0: released.
| argument | 説明 | type |
| --- | --- | -- |
| ms | pressing time (ms) | uint32_t |
**使用例:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
}
void loop() {
M5.update();
M5.Lcd.clear();
M5.Lcd.setCursor(0, 0);
if (M5.BtnA.pressedFor(2000)) {
M5.Lcd.printf("Button A was pressed for more than 2 seconds.");
delay(1000);
}
}
```
+31 -31
View File
@@ -8,7 +8,7 @@
引数で指定した色で画面を塗りつぶします。
**構文**
**構文:**
```arduino
fillScreen(uint16_t color);
@@ -18,7 +18,7 @@ fillScreen(uint16_t color);
| --- | --- | -- |
| color | 塗りつぶしの色 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -33,7 +33,7 @@ M5.Lcd.fillScreen(RED);
文字の色や文字の背景色を引数で指定した色に変更します。
**構文**
**構文:**
```arduino
setTextColor(uint16_t color, [uint16_t backgroundcolor]);
@@ -44,7 +44,7 @@ setTextColor(uint16_t color, [uint16_t backgroundcolor]);
| color | テキストの色 | uint16_t |
| backgroundcolor| テキストの背景色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -55,11 +55,11 @@ M5.Lcd.setTextColor(RED);
## setCursor()
**機能**
**機能:**
カーソルの位置を設定します。
**構文**
**構文:**
```arduino
setCursor(uint16_t x, uint16_t y);
@@ -70,7 +70,7 @@ setCursor(uint16_t x, uint16_t y);
| x | x位置 | uint16_t |
| y | y位置 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -82,11 +82,11 @@ M5.Lcd.print("Hello");
## drawPixel()
**機能**
**機能:**
指定した位置に指定色のピクセルを描画します。
**構文**
**構文:**
```arduino
drawPixel(int16_t x, int16_t y, [uint16_t color]);
@@ -98,7 +98,7 @@ drawPixel(int16_t x, int16_t y, [uint16_t color]);
| y | y位置 | int16_t |
| color | ピクセルの色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -109,11 +109,11 @@ M5.Lcd.drawPixel(22, 22, RED);
## drawLine()
**機能**
**機能:**
指定した始点から終点まで指定色の直線を描画します。
**構文**
**構文:**
```arduino
drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, [uint16_t color]);
@@ -127,7 +127,7 @@ drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, [uint16_t color]);
| y1 | 終点のy位置 | int16_t |
| color | 線の色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -138,11 +138,11 @@ M5.Lcd.drawLine(0, 0, 12, 12, WHITE);
## drawTriangle()
**機能**
**機能:**
指定した3点を結ぶ三角形を指定色で描画します。
**構文**
**構文:**
```arduino
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, [uint16_t color]);
@@ -158,7 +158,7 @@ drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t
| y2 | 点2のy位置 | int16_t |
| color | 線の色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -169,11 +169,11 @@ M5.Lcd.drawTriangle(22, 22, 69, 98, 51, 22, RED);
## fillTriangle()
**機能**
**機能:**
指定した3点を結ぶ三角形を指定色で塗りつぶして描画します。
**構文**
**構文:**
```arduino
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, [uint16_t color]);
@@ -189,7 +189,7 @@ fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t
| y2 | 点2のy位置 | int16_t |
| color | 塗りつぶしの色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -200,11 +200,11 @@ M5.Lcd.fillTriangle(22, 22, 69, 98, 51, 22, RED);
## drawRect()
**機能**
**機能:**
指定の点から指定の幅と高さの四角形を指定色で描画します。
**構文**
**構文:**
```arduino
drawRect(int16_t x, int16_t y, int16_t w, int16_t h, [uint16_t color]);
@@ -218,7 +218,7 @@ drawRect(int16_t x, int16_t y, int16_t w, int16_t h, [uint16_t color]);
| h | 四角形の高さ | int16_t |
| color | 線の色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -229,11 +229,11 @@ M5.Lcd.drawRect(180, 12, 122, 10, BLUE);
## fillRect()
**機能**
**機能:**
指定の左上の点(x,y)と幅と高さの四角形を指定色で塗りつぶして描画します。
**構文**
**構文:**
```arduino
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, [uint16_t color]);
@@ -247,7 +247,7 @@ fillRect(int16_t x, int16_t y, int16_t w, int16_t h, [uint16_t color]);
| h | 四角形の高さ | int16_t |
| color | 塗りつぶしの色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -258,11 +258,11 @@ M5.Lcd.fillRect(180, 12, 122, 10, BLUE);
## drawRoundRect()
**機能**
**機能:**
左上の点(x,y)と幅と高さを指定して、かど丸の四角形を描画します。
**構文**
**構文:**
```arduino
drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, [uint16_t color]);
@@ -277,7 +277,7 @@ drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, [uint16_t c
| r | コーナー半径 | int16_t |
| color | 四角形の線の色。省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
@@ -288,17 +288,17 @@ M5.Lcd.fillRoundRect(180, 70, 122, 10, 4, BLUE);
## print()
**機能**
**機能:**
指定の文字列を描画します。
**構文**
**構文:**
```arduino
print("表示する文字列");
```
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
+259
View File
@@ -0,0 +1,259 @@
# 姿态传感器 MPU9250
*姿态传感器 MPU9250 是一款多芯片模块,集成两个芯片,一个芯片是 MPU6500,由 3 轴陀螺仪和 3 轴加速度计组成,另外一个是 AK8963 是 3 轴磁力计。*
## initMPU9250()
**函数原型:**
<mark>void initMPU9250();</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:初始化 MPU6500 芯片。**
**例程:**
```arduino
#include <M5Stack.h>
#include "utility/MPU9250.h"
MPU9250 IMU; // new a MPU9250 object
void setup(){
M5.begin();
Serial.begin(115200);
IMU.initMPU9250();
byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX);
}
```
## initAK8963()
**函数原型:**
<mark>void initAK8963(float * destination);</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:初始化 AK8963 芯片。**
| 参数 | 描述 |
| --- | --- |
| destination | 出厂预设于 AK8963 芯片内缺省值的数组指针 |
**例程:**
```arduino
#include <M5Stack.h>
#include "utility/MPU9250.h"
MPU9250 IMU; // new a MPU9250 object
void setup(){
M5.begin();
Serial.begin(115200);
// "magCalibration[3] = {0};" was defined at file "MPU9250.h"
IMU.initAK8963(IMU.magCalibration);
Serial.println("AK8963 initialized for active data mode....");
if (Serial)
{
// Serial.println("Calibration values: ");
Serial.print("X-Axis sensitivity adjustment value ");
Serial.println(IMU.magCalibration[0], 2);
Serial.print("Y-Axis sensitivity adjustment value ");
Serial.println(IMU.magCalibration[1], 2);
Serial.print("Z-Axis sensitivity adjustment value ");
Serial.println(IMU.magCalibration[2], 2);
}
}
```
## calibrateMPU9250()
**函数原型:**
<mark>void calibrateMPU9250(float * gyroBias, float * accelBias);</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:初始化芯片后,执行该函数以读取静止状态下的陀螺仪和加速度值偏移,并保存到各自的偏移寄存器。**
| 参数 | 描述 |
| --- | --- |
| gyroBias | 保存静止下陀螺仪值的数组的地址 |
| accelBias | 保存静止下加速度值的数组的地址 |
**例程:**
```arduino
#include <M5Stack.h>
#include "utility/MPU9250.h"
MPU9250 IMU; // new a MPU9250 object
void setup(){
M5.begin();
Serial.begin(115200);
IMU.initMPU9250();
byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX);
// "gyroBias[3] = {0};" was defined at file "MPU9250.h"
// "accelBias[3] = {0};" was defined at file "MPU9250.h"
IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(0, 0); M5.Lcd.print("MPU9250 bias");
M5.Lcd.setCursor(0, 16); M5.Lcd.print(" x y z ");
M5.Lcd.setCursor(0, 32); M5.Lcd.print((int)(1000*IMU.accelBias[0]));
M5.Lcd.setCursor(32, 32); M5.Lcd.print((int)(1000*IMU.accelBias[1]));
M5.Lcd.setCursor(64, 32); M5.Lcd.print((int)(1000*IMU.accelBias[2]));
M5.Lcd.setCursor(96, 32); M5.Lcd.print("mg");
M5.Lcd.setCursor(0, 48); M5.Lcd.print(IMU.gyroBias[0], 1);
M5.Lcd.setCursor(32, 48); M5.Lcd.print(IMU.gyroBias[1], 1);
M5.Lcd.setCursor(64, 48); M5.Lcd.print(IMU.gyroBias[2], 1);
M5.Lcd.setCursor(96, 48); M5.Lcd.print("o/s");
}
void loop(){
}
```
## readByte()
**函数原型:**
<mark>uint8_t readByte(uint8_t address, uint8_t subAddress);</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:读取指定寄存器内数据。返回值:寄存器值,长度为8 位。**
| 参数 | 描述 |
| --- | --- |
| address | 芯片 (MPU9250/AK8963)地址 |
| subAddress | 芯片内寄存器地址 |
**例程:**
```arduino
#include <M5Stack.h>
#include "utility/MPU9250.h"
MPU9250 IMU; // new a MPU9250 object
void setup(){
M5.begin();
Serial.begin(115200);
byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX);
}
```
## readGyroData()
**函数原型:**
<mark>void readGyroData(int16_t * destination);</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:读取三个方向的陀螺仪值。**
| 参数 | 描述 |
| --- | --- |
| destination | 保存陀螺仪值的数组的地址 |
**例程:**
```arduino
#include <M5Stack.h>
#include "utility/MPU9250.h"
MPU9250 IMU; // new a MPU9250 object
void setup(){
M5.begin();
Serial.begin(115200);
IMU.initMPU9250();
byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX);
IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias);
}
void loop(){
// If intPin goes high, all data registers have new data
// On interrupt, check if data ready interrupt
if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01)
{
// "gyroCount[3] = {0};" was defined at file "MPU9250.h"
IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values
IMU.getGres(); // get Gyro scales saved to "gRes"
IMU.gx = (float)IMU.gyroCount[0]*IMU.gRes;
IMU.gy = (float)IMU.gyroCount[1]*IMU.gRes;
IMU.gz = (float)IMU.gyroCount[2]*IMU.gRes;
Serial.print("X-gyro rate: "); Serial.print(IMU.gx, 3);
Serial.print(" degrees/sec ");
Serial.print("Y-gyro rate: "); Serial.print(IMU.gy, 3);
Serial.print(" degrees/sec ");
Serial.print("Z-gyro rate: "); Serial.print(IMU.gz, 3);
Serial.println(" degrees/sec");
}
}
```
## readAccelData()
**函数原型:**
<mark>void readAccelData(int16_t * destination);</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:读取三个方向的加速度值。**
| 参数 | 描述 |
| --- | --- |
| destination | 保存加速度值的数组的地址 |
**例程:**
```arduino
#include <M5Stack.h>
#include "utility/MPU9250.h"
MPU9250 IMU; // new a MPU9250 object
void setup(){
M5.begin();
Serial.begin(115200);
IMU.initMPU9250();
byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX);
IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias);
}
void loop(){
// If intPin goes high, all data registers have new data
// On interrupt, check if data ready interrupt
if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01)
{
// "accelCount[3] = {0};" was defined at file "MPU9250.h"
IMU.readAccelData(IMU.accelCount);
IMU.getAres(); // get accelerometer scales saved to "aRes"
IMU.ax = (float)IMU.accelCount[0]*IMU.aRes; // - accelBias[0];
IMU.ay = (float)IMU.accelCount[1]*IMU.aRes; // - accelBias[1];
IMU.az = (float)IMU.accelCount[2]*IMU.aRes; // - accelBias[2];
Serial.print("X-acceleration: "); Serial.print(1000*IMU.ax);
Serial.print(" mg ");
Serial.print("Y-acceleration: "); Serial.print(1000*IMU.ay);
Serial.print(" mg ");
Serial.print("Z-acceleration: "); Serial.print(1000*IMU.az);
Serial.println(" mg ");
}
}
```
+4 -4
View File
@@ -1,12 +1,12 @@
# Speaker
# スピーカー
## tone()
**機能**
**機能:**
指定した音と長さでスピーカーを鳴らします。
**函数原型:**
**構文:**
```arduino
tone(uint16_t freq, [uint32_t duration]);
@@ -17,7 +17,7 @@ tone(uint16_t freq, [uint32_t duration]);
| freq | 音の高さ(周波数Hz | uint16_t |
| duration | 鳴動時間 (ms)、 省略可能。 | uint16_t |
**使用例**
**使用例:**
```arduino
#include <M5Stack.h>
+130
View File
@@ -0,0 +1,130 @@
# 系统函数
## begin()
**函数原型:**
<mark>void begin(bool LCDEnable=true, bool SDEnable=true, bool SerialEnable=true);</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:清串口缓冲区,设置串口波特率为 115200;初始化 LCD;初始化 SD 卡;设置按键 A 是睡眠唤醒按键。**
**函数实现**
```arduino
void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable) {
if (isInited) return;
else isInited = true;
if (SerialEnable) {
Serial.begin(115200);
Serial.flush();
delay(50);
Serial.print("M5Stack initializing...");
}
if (LCDEnable) {
Lcd.begin();
}
if (SDEnable) {
SD.begin(TFCARD_CS_PIN, SPI, 40000000);
}
setWakeupButton(BUTTON_A_PIN);
}
```
**例程**
```arduino
#include <M5Stack.h>
void setup(){
M5.begin();
}
```
## update()
**函数原型:**
<mark>void update();</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:读取按键 A, B, C 的状态。**
**函数实现**
```arduino
void M5Stack::update() {
//Button update
BtnA.read();
BtnB.read();
BtnC.read();
//Speaker update
Speaker.update();
}
```
**例程**
```arduino
#include <M5Stack.h>
void setup(){
M5.begin();
}
void loop(){
M5.update();
}
```
## powerOFF()
**函数原型:**
<mark>void powerOFF();</mark>
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**功能:系统进入深度睡眠状态。**
**函数实现**
```arduino
void M5Stack::powerOFF() {
#ifdef M5STACK_FIRE
// Keep power keep boost on
setPowerBoostKeepOn(true);
#endif
// power off the Lcd
Lcd.setBrightness(0);
Lcd.sleep();
// ESP32 into deep sleep
esp_sleep_enable_ext0_wakeup((gpio_num_t)_wakeupPin , LOW);
while(digitalRead(_wakeupPin) == LOW) {
delay(10);
}
esp_deep_sleep_start();
}
```
**例程**
```arduino
#include <M5Stack.h>
void setup(){
M5.begin();
M5.Lcd.println("This is software power off demo");
M5.Lcd.println("Press the button A to power off.");
M5.setWakeupButton(BUTTON_A_PIN);
}
void loop() {
if(M5.BtnA.wasPressed()) {
M5.powerOFF();
}
M5.update();
}
```
+62
View File
@@ -0,0 +1,62 @@
# TF 卡
## begin()
**函数原型:**
<mark>begin(cspin);</mark>
**功能:TF 卡初始化。**
| 参数 | 描述 |
| --- | --- |
| cspin | TF 的片选引脚 (默认是 SPI 的 SS 引脚),可选 |
**例程**
```arduino
#include <M5Stack.h>
M5.begin();
SD.begin();
```
## open()
**函数原型:**
<mark>File open(const char *filepath, uint8_t mode;</mark>
**功能:以指定模式打开指定文件。返回值:文件句柄。**
| 参数 | 描述 |
| --- | --- |
| filepath | 文件路径 |
| mode | 打开模式 |
**例程**
```arduino
/*
提前通过 PC 将 datalog.txt 文件拷贝到 TF 卡内
*/
#include <M5Stack.h>
void setup(){
M5.begin();
Serial.begin(115200);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
while(1);
}
Serial.println("card initialized.");
File dataFile = SD.open("/datalog.txt", FILE_WRITE);
if (dataFile)
Serial.println("open datalog.txt successfully");
else
Serial.println("error opening datalog.txt");
}
void loop(){
}
```