LED Display

M5Atom库中将在M5.begin函数中初始化LED Display(默认为禁用), 参考下方示例可配置启用或禁用。


#include "M5Atom.h"

void setup() {
    // SerialEnable: true, I2CEnable: false, DisplayEnable: true
    M5.begin(true, false, true);
    delay(50);
    M5.dis.drawpix(0, 0x00ff00);
}

void loop() {
}

drawpix

功能:

以指定RGB颜色点亮某个LED (Number : 0~24)(Atom-Lite has only one light)

以指定RGB颜色点亮(x,y)坐标处的灯LED

函数原型:

void drawpix(uint8_t xpos, uint8_t ypos, CRGB Color)

void drawpix(uint8_t Number, CRGB Color)

参数 类型 描述
xpos uint8_t x坐标(0~5)
ypos uint8_t y坐标(0~5)
Number uint8_t 点亮第*个灯(0~24)
Color CRGB 灯的颜色

使用示例:

#include "M5Atom.h"
void setup(){
    M5.begin(true, false, true);    //初始化 M5Atom
    delay(50);   //延迟50ms
    M5.dis.drawpix(0, 0xBBFFFF);  //以RBG颜色0xBBFFFF点亮第0个LED
    //M5.dis.drawpix(0,0, 0xBBFFFF);  //以RBG颜色0xBBFFFF点亮(0,0)处的LED
}

void loop(){
}

注意:
1. RGB转换工具下载

fillpix

功能:

将某个RBG颜色填充至整个LED点阵

函数原型:

void fillpix(CRGB Color)

使用示例:

#include "M5Atom.h"
void setup(){
  M5.begin(true, false, true); //初始化 M5Atom
}

void loop(){
  M5.dis.fillpix(0xffffff);  //以RBG颜色0xffffff点亮整个LED点阵
}

clear

功能:

熄灭所有点亮的LED

函数原型:

void clear()

使用示例:

#include "M5Atom.h"
void setup(){
    M5.begin(true, false, true);    //初始化 M5Stack
    delay(50);   //延迟50ms
    M5.dis.drawpix(0, 0xBBFFFF);
  //M5.dis.drawpix(0,0, 0xBBFFFF);
}

void loop(){
  M5.update();  //读取按键按下状态
  if (M5.Btn.wasPressed()){
    M5.dis.clear();  //熄灭所有点亮的LED
  }
}

setBrightness

功能:

设置点亮LED的亮度

函数原型:

void setBrightness(uint8_t brightness)

使用示例:

#include "M5Atom.h"
void setup(){
  M5.begin(true, false, true); //初始化 M5Atom
}

void loop(){
  M5.dis.fillpix(0xffffff); //以RBG颜色0xffffff点亮整个LED点阵
  M5.dis.setBrightness(10); //设置点亮LED的亮度
  delay(1000);

  M5.dis.fillpix(0xFFFF00);
  M5.dis.setBrightness(100);
  delay(1000);
}

setWidthHeight

功能:

设置图案的宽和高

函数原型:

void setWidthHeight(uint16_t xColumns, uint16_t yRows)

run()

功能:

开始播放LED显示

函数原型:

void run()

注意:
1.如果您不想使用M5.begin() 初始化LED,且要用到animation(),请在使用animation()之前调用此功能

使用示例:

#include <M5Atom.h>

void setup() {
  M5.Lcd.begin();  //初始化Atom LED点阵
  M5.Lcd.run();
}

void loop() {
}

animation

功能:

将某个图案以指定速度向指定方向移动步

函数原型:

void animation(uint8_t *buffptr, uint8_t amspeed, uint8_t ammode, int64_t amcount)

参数 类型 描述
buffptr uint8_t * 图案
amspeed uint8_t 移动速度(0~255)
ammode uint8_t 移动方向
amcount int64_t 移动步数

移动方向:

常量 描述
kMoveRight 0x01 向右移动图像
kMoveLeft 0x02 向左移动图像
kMoveTop 0x04 向上移动图像
kMoveButtom 0x08 向底部移动图像

使用示例:

#include "M5Atom.h"
extern const unsigned char AtomImageData[375 + 2];  //外部引用存储所示图像的数组(点击下方image.c下载并存储至与.ino同一目录下)

void setup(){
    M5.begin(true, false, true);   //清空串口缓冲区,设置串口波特率为 115200;初始化LED矩阵
    delay(50);
}

void loop(){
    //将某个图案AtomImageData以指定速度200向指定方向kMoveLeft移动25步
    M5.dis.animation((uint8_t *)AtomImageData, 200, LED_DisPlay::kMoveLeft, 25);
    delay(5250);
}

注意:
1. image.c图片下载

animationrunning

功能:

获取图案是否处于运动状态

函数原型:

boolean animationrunning()

返回值:

功能
true 运动
false 静止

displaybuff

功能:

将显示的内容向某个方向移动

函数原型:

void displaybuff(uint8_t *buffptr, int8_t offsetx = 0, int8_t offsety = 0)

参数 类型 描述
buffptr uint8_t * 图案存储的数组
offsetx int8_t 往x方向移动的格数
offsety int8_t 往y方向移动的格数

注意:
1.x>0向右移动,y>0向下移动

使用示例:

#include "M5Atom.h"

extern const unsigned char AtomImageData[375 + 2];//数组点击上方image.c下载
void setup(){
  M5.begin(true, false, true);
  delay(50);
}

void loop(){
  M5.dis.displaybuff((uint8_t *)AtomImageData,-2, 0);    //将图案向左移动2格
  delay(100);
}
On This Page