機能です:
タッチスクリーンを初期化; TF Card を初期化; シリアルポートバッファをクリアし、シリアルポートのボーレートを 115200 に設定; 電池 ADC の読み込み; I2C を初期化
原型関数です:
void begin(bool touchEnable = true, bool SDEnable = true, bool SerialEnable = true, bool BatteryADCEnable = true, bool I2CEnable = false)
関数実装です:
void M5EPD::begin(bool touchEnable, bool SDEnable, bool SerialEnable, bool BatteryADCEnable, bool I2CEnable) { if (_isInited) { return; } _isInited = true; pinMode(M5EPD_MAIN_PWR_PIN, OUTPUT); enableMainPower(); if (SerialEnable == true) { Serial.begin(115200); Serial.flush(); delay(50); Serial.print("M5EPD initializing..."); } pinMode(M5EPD_EXT_PWR_EN_PIN, OUTPUT); pinMode(M5EPD_EPD_PWR_EN_PIN, OUTPUT); pinMode(M5EPD_KEY_RIGHT_PIN, INPUT); pinMode(M5EPD_KEY_PUSH_PIN, INPUT); pinMode(M5EPD_KEY_LEFT_PIN, INPUT); delay(100); enableEXTPower(); enableEPDPower(); delay(1000); EPD.begin(M5EPD_SCK_PIN, M5EPD_MOSI_PIN, M5EPD_MISO_PIN, M5EPD_CS_PIN, M5EPD_BUSY_PIN); if (SDEnable == true) { SPI.begin(14, 13, 12, 4); SD.begin(4, SPI, 20000000); } if (touchEnable == true) { if (TP.begin(21, 22, 36) != ESP_OK) { log_e("Touch pad initialization failed."); } } else if (I2CEnable == true) { Wire.begin(21, 22, (uint32_t)400000U); } if (BatteryADCEnable == true) { BatteryADCBegin(); } if (SerialEnable == true) { Serial.println("OK"); }}
使用例です:
#include <M5EPD.h> void setup() { M5.begin(true,true,true,true,true);}
機能です:
ボタン状態の変化を検出
原型関数です:
void update()
使用例です:
#include <M5EPD.h>void setup() { M5.begin(false,false,true,false,false);} void loop() { M5.update(); if( M5.BtnL.wasPressed()) { Serial.println("Left button pressed"); } delay(100);}
定義します | ピンです | 記述します |
---|---|---|
M5EPD_KEY_LEFT_PIN | 37 | ダイヤルは上にスクロールします |
M5EPD_KEY_PUSH_PIN | 38 | ダイヤルが押されます |
M5EPD_KEY_RIGHT_PIN | 39 | ダイヤルは下にスクロールします |
M5EPD_PORTA_W_PIN | 32 | PORT-A |
M5EPD_PORTA_Y_PIN | 25 | PORT-A |
M5EPD_PORTA_W_PIN | 32 | PORT-A |
M5EPD_PORTA_Y_PIN | 25 | PORT-A |
M5EPD_PORTB_W_PIN | 33 | PORT-B |
M5EPD_PORTB_Y_PIN | 26 | PORT-B |
M5EPD_PORTC_W_PIN | 19 | PORT-C |
M5EPD_PORTC_Y_PIN | 18 | PORT-C |
M5EPD_PORTC_Y_PIN | 18 | PORT-C |
M5EPD_MISO_PIN | 13 | IT8951E/TF-card MISO |
M5EPD_MOSI_PIN | 12 | IT8951E/TF-card MOSI |
M5EPD_SCK_PIN | 14 | IT8951E/TF-card SCK |
M5EPD_CS_PIN | 15 | IT8951E CS |
M5EPD_MAIN_PWR_PIN | 2 | PWR |
M5EPD_SCK_PIN | 14 | IT8951E/TF-card SCK |
M5EPD_SCK_PIN | 14 | IT8951E/TF-card SCK |
M5EPD_BUSY_PIN | 27 | / |
M5EPD_EXT_PWR_EN_PIN | 5 | / |
M5EPD_EPD_PWR_EN_PIN | 23 | / |
M5EPD_BAT_VOL_PIN | 35 | / |
機能です:
最後の状態変化が発生した時刻を返す
原型関数です:
uint32_t lastChange()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.println("Please pressed Button L.");} void loop() { M5.update(); Serial.printf("The last change at %d ms /n",M5.BtnL.lastChange()); //Print the time of the last state change of key L. 打印按键L最后一次状态变化的时间}
機能です:
ボタンが押下されている状態を返す: 押下中なら true を返す、そうでないなら false を返す
原型関数です:
uint8_t isPressed()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.println("Please pressed Button L.");} void loop() { M5.update(); // Need to add M5.update() to read the state of the button //需添加M5.update()才能读取到按键的状态. if (M5.BtnL.isPressed()) { //If the key is pressed. 如果按键按下 Serial.println("Button is Pressed."); } else { Serial.println("Button is Released."); } delay(20);}
機能です:
ボタンが指定の時間を超えて押下中の状態を返す: 押下中なら true を返す、そうでないなら false を返す
原型関数です:
uint8_t pressedFor(uint32_t ms)
パラメータです | タイプです | 記述します |
---|---|---|
ms | uint32_t | ボタンを押す時間(ミリ秒)です |
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.println("Please pressed Button L.");} void loop() { M5.update(); if (M5.BtnL.pressedFor( 2000)) { // If the button is pushed up for more than 2 seconds. //如果按键被推上超过2秒. Serial.println("Button L was pressed for more than 2 seconds."); delay(1000); }}
機能です:
ボタンが押下中の状態を返す: 押下した瞬間に true を返す、それ以外は false を返す
原型関数です:
uint8_t wasPressed()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.println("Please push on Button L.");} void loop() { M5.update(); if (M5.BtnL.wasPressed()) { //If the button is pushed up. 如果按键被推上 Serial.println("Button is pressed."); } delay(20);}
機能です:
ボタンが離された状態を返す: 離され中なら true を返す、そうでないなら false を返す
原型関数です:
uint8_t isPressed()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); } void loop() { M5.update(); // Need to add M5.update() to read the state of the button //需添加M5.update()才能读取到按键的状态. if (M5.BtnL.isReleased()) { //If the key is released. 如果按键释放. Serial.println("Button is released."); } else { Serial.println("Button is Pressed ."); } delay(20);}
機能です:
ボタンが指定の時間を超えて離され中の状態を返す: 離され中なら true を返す、そうでないなら false を返す
原型関数です:
uint8_t releasedFor(uint32_t ms);
パラメータです | タイプです | 記述します |
---|---|---|
ms | uint32_t | ボタンを押す時間(ミリ秒)です |
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); } void loop() { M5.update(); // Need to add M5.update() to read the state of the button //需添加M5.update()才能读取到按键的状态. if (M5.BtnL.isReleased()) { //If the key is released. 如果按键释放 Serial.println("Button is released."); } else { Serial.println("Button is pressed."); } delay(20);}
機能です:
ボタンが離された状態を返す: 離された瞬間に true を返す、それ以外は false を返す
原型関数です:
uint8_t wasReleased()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.println("Please pressed Button L.");} void loop() { M5.update(); if (M5.BtnL.wasReleased()) { //If the key is released. 如果按键释放 Serial.println("Button is Released."); } delay(20);}
機能です:
ボタンが押下中で指定の時間を超えて離された状態を返す: 離された瞬間に true を返す、それ以外は false を返す
原型関数です:
uint8_t wasReleasefor(uint32_t ms)
パラメータです | タイプです | 記述します |
---|---|---|
ms | uint32_t | ボタンを押す時間(ミリ秒)です |
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.println("Please pressed Button L.");} void loop() { M5.update(); if (M5.BtnL.wasReleasefor( 3000)) { // If button A is pressed for 3s and then released //如果按键A按下3s之后释放. Serial.println("OK"); }}
機能です:
拡張ポートの電源を有効化
原型関数です:
void enableEXTPower()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); M5.enableEXTPower(); //enable external power. 启用拓展端口电源 Serial.println("Expansion port power is on");} void loop() {}
機能です:
拡張端口の電源を切断
原型関数です:
void disableEXTPower()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); M5.disableEXTPower(); //disable external power. 关闭拓展端口电源 Serial.println("Expansion port power is off");} void loop() {}
機能です:
電子インクディスプレイの電源を有効化
原型関数です:
void enableEPDPower()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); M5.enableEPDPower(); //enable EPD power. 启用墨水屏电源 Serial.println("Ink screen power is activated");} void loop() {}
機能です:
電子インクディスプレイの電源を切断
原型関数です:
void disableEPDPower()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); M5.disableEPDPower(); //disable EPD power. 关闭墨水屏电源 Serial.println("Ink screen power off");} void loop() {}
機能です:
主電源を有効化
原型関数です:
void enableMainPower()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); M5.enableMainPower(); //Start main power. 启动主电源 Serial.println("Main power is on");} void loop() {}
機能です:
主電源を切断
原型関数です:
void disableMainPower()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); M5.disableMainPower(); //Turn off the main power. 关闭主电源 Serial.println("Main power is off");} void loop() {}
機能です:
电池 ADC 検出を初期化
原型関数です:
void BatteryADCBegin()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); M5.BatteryADCBegin(); // Initialize battery ADC detection. // 初始化电池ADC检测} void loop() {}
機能です:
电池の原生 ADC 値を読み込み
原型関数です:
uint32_t getBatteryRaw()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.printf("ADC RAW:%d", M5.getBatteryRaw()); // Read battery voltage native ADC values // 读取电池电压原生ADC值} void loop() {}
機能です:
电池の電圧を読み込み
原型関数です:
uint32_t getBatteryVoltage()
使用例です:
#include <M5EPD.h> void setup() { M5.begin(); Serial.printf("Battery Voltage:%d", M5.getBatteryVoltage()); // Read battery voltage // 读取电池电压} void loop() {}
電源を切断し、再び起動するには PWR ボタンを押下する必要がある
void shutdown()
電源を切断し、指定の秒数の遅延後、RTC を通じてデバイスを起動する
int shutdown( int seconds )
電源を切断し、指定の RTC 時間構造体を入力し、その時間に到着したら RTC を通じてデバイスを起動する
int shutdown( const rtc_time_t &RTC_TimeStruct)
電源を切断し、指定の RTC 時間構造体を入力し、その時間に到着したら RTC を通じてデバイスを起動する(詳細の条件を指定できる)
int shutdown( const rtc_date_t &RTC_DateStruct, const rtc_time_t &RTC_TimeStruct)
使用例です:
#include <M5EPD.h> M5EPD_Canvas canvas(&M5.EPD); void setup(){ M5.begin(); M5.EPD.SetRotation(90); M5.TP.SetRotation(90); M5.EPD.Clear(true); M5.RTC.begin(); canvas.createCanvas(540, 960); canvas.setTextSize(3); canvas.drawString("Press PWR Btn for sleep!", 45, 350); canvas.drawString("after 5 sec wakeup!", 70, 450); canvas.pushCanvas(0,0,UPDATE_MODE_DU4);} void loop(){ if(M5.BtnP.wasPressed()){ canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550); canvas.pushCanvas(0,0,UPDATE_MODE_DU4); delay(1000); M5.shutdown(5); } M5.update(); delay(100);}