System & Button

System

begin()

功能: 初始化 E-Ink,I2C,Speaker,RTC,串口

函数原型:int begin(bool InkEnable, bool wireEnable, bool SpeakerEnable)

例程:

#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()

mute()

功能: 将蜂鸣器设置为静音

函数原型:void mute()

setBeep()

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

函数原型:void setBeep(uint16_t frequency, uint16_t duration)

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.setBeep(1000,1000);
  M5.Speaker.beep();
  delay(1000);
  M5.update();
}

playMusic()

功能: 让蜂鸣器播放音乐

函数原型:void playMusic(const uint8_t *music_data, uint16_t sample_rate)

On This Page