pdf-icon

System

begin()

功能说明:

初始化 E-Ink; 初始化 I2C; 初始化 扬声器; 初始化 RTC; 清串口缓冲区,设置串口波特率为 115200;

函数原型:

int begin(bool InkEnable, bool wireEnable, bool SpeakerEnable)

函数实现:

int M5CoreInk::begin(bool InkEnable, bool wireEnable, bool SpeakerEnable){
  pinMode(POWER_HOLD_PIN, OUTPUT);
  digitalWrite(POWER_HOLD_PIN, HIGH); // Hold power

  pinMode(LED_EXT_PIN, OUTPUT);

  Serial.begin(115200);
  Serial.printf("initializing.....OK\n");

  if (wireEnable){
    Wire.begin(32, 33, 10000);
  }

  if (SpeakerEnable){
    Speaker.begin();
  }

  rtc.begin();
  rtc.clearIRQ();

  if (InkEnable){
    M5Ink.begin();
    if (!M5.M5Ink.isInit()){
      Serial.printf("Ink initializ is faild\n");
      return -1;
    }
  }

  return 0;
}

案例程序:

#include "M5CoreInk.h"

void setup() {
  M5.begin(true,true,true);
}

update()

功能说明:

刷新设备按键/蜂鸣器状态

函数原型:

void update()

案例程序:

#include "M5CoreInk.h"
void setup() {
  M5.begin(false,false,true);
}

void loop() {
  M5.update();
  M5.Speaker.tone(1000,1000);
  if( M5.BtnPWR.wasPressed()){
    Serial.printf("Btn wasPressed!");
  }
  delay(1000);
}

Button

功能说明:

检测设备各个按键状态

函数列表:

M5.BtnUP.wasPressed()

M5.BtnDOWN.wasPressed()

M5.BtnMID.wasPressed()

M5.BtnEXT.wasPressed()

M5.BtnPWR.wasPressed()

函数 函数功能
BtnUP 拨轮向上滚动
BtnDOWN 拨轮向下滚动
BtnMID 拨轮按下
BtnEXT 顶部按键按下
BtnPWR 右侧按键按下

案例程序:

#include "M5CoreInk.h"
void setup() {
  M5.begin(true,false,false);
}

void loop() {
  if( M5.BtnUP.wasPressed()){
    Serial.printf("BtnUP wasPressed!\n");
  }else if( M5.BtnDOWN.wasPressed()){
    Serial.printf("BtnDOWN wasPressed!\n");
  }else if( M5.BtnMID.wasPressed()){
    Serial.printf("BtnMID wasPressed!\n");
  }else if( M5.BtnEXT.wasPressed()){
    Serial.printf("BtnEXT wasPressed!\n");
  }else if( M5.BtnPWR.wasPressed()){
    Serial.printf("BtnPWR wasPressed!\n");
  }
  M5.update();
}

Speaker

update()

功能说明:

刷新设备按键/蜂鸣器状态

函数原型:

void update()

end()

功能说明:

关闭蜂鸣器

函数原型:

void end()

案例程序:

#include "M5CoreInk.h"
void setup() {
  M5.begin(false,false,true);
}

void loop() {
  delay(1000);
  M5.Speaker.beep();
  delay(1000);
  M5.Speaker.end();
}

mute()

功能说明:

将蜂鸣器设置为静音

函数原型:

void mute()

案例程序:

#include "M5CoreInk.h"
void setup() {
  M5.begin(false,false,true);
}

void loop() {
  M5.Speaker.beep();
  delay(1000);
  M5.Speaker.mute();
  delay(1000);
}

setBeep()

功能说明:

设置蜂鸣器的频率和发声时长

函数原型:

void setBeep(uint16_t frequency, uint16_t duration)

案例程序:

#include "M5CoreInk.h"
void setup() {
  M5.begin(false,false,true);
}

void loop() {
  M5.Speaker.setBeep(1000,1000);
  M5.Speaker.beep();
  delay(1000);
  M5.update();
}

beep()

功能说明:

让蜂鸣器发声

函数原型:

void beep()

案例程序:

#include "M5CoreInk.h"
void setup() {
  M5.begin(false,false,true);
}

void loop() {
  M5.Speaker.setBeep(1000,1000);
  M5.Speaker.beep();
  delay(1000);
  M5.update();
}

tone()

功能说明:

⓵让蜂鸣器以指定频率一直发声 ⓶让蜂鸣器以指定频率发声指定时长

函数原型:

void tone(uint16_t frequency)

void tone(uint16_t frequency, uint32_t duration)

案例程序:

#include "M5CoreInk.h"

void setup() {
  M5.begin(false,false,true);
}

void loop() {
  M5.Speaker.tone(1000);
  delay(1000);
  M5.Speaker.noTone();
  M5.Speaker.tone(1000,1000);
  delay(1000);
  M5.Speaker.update();
}

setVolume()

功能说明:

设置蜂鸣器的音量

函数原型:

void setVolume(uint8_t volume)

案例程序:

#include "M5CoreInk.h"
void setup() {
  M5.begin(false,false,true);
}

void loop() {
  M5.Speaker.volume(1000);
  M5.Speaker.beep();
  delay(1000);
  M5.update();
}

playMusic()

功能说明:

让蜂鸣器播放音乐

函数原型:

void playMusic(const uint8_t *music_data, uint16_t sample_rate)

On This Page