超级炫酷的LED数字变换算法,你能写的出吗?
来源:玩转单片机与嵌入式发布时间:2022-04-021487浏览
询问 AI今天浏览Twitter,发现一个不错的项目,作者Hari Wiguna,对于普通的数字变换,加了一种连贯变化的效果,还是比较有冲击感的,代码开源,公众号后台回复 数字变化 获取源代码!部分代码:
Digit::Digit(PxMATRIX* d, byte value, uint16_t xo, uint16_t yo, uint16_t color) {
_display = d;
_value = value;
xOffset = xo;
yOffset = yo;
_color = color;
}
byte Digit::Value() {
return _value;
}
void Digit::drawPixel(uint16_t x, uint16_t y, uint16_t c)
{
_display->drawPixel(xOffset + x, height - (y + yOffset), c);
}
void Digit::drawLine(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2, uint16_t c)
{
_display->drawLine(xOffset + x, height - (y + yOffset), xOffset + x2, height - (y2 + yOffset), c);
}
void Digit::drawSeg(byte seg)
{
switch (seg) {
case sA: drawLine(1, segHeight * 2 + 2, segWidth, segHeight * 2 + 2, _color); break;
case sB: drawLine(segWidth + 1, segHeight * 2 + 1, segWidth + 1, segHeight + 2, _color); break;
case sC: drawLine(segWidth + 1, 1, segWidth + 1, segHeight, _color); break;
case sD: drawLine(1, 0, segWidth, 0, _color); break;
case sE: drawLine(0, 1, 0, segHeight, _color); break;
case sF: drawLine(0, segHeight * 2 + 1, 0, segHeight + 2, _color); break;
case sG: drawLine(1, segHeight + 1, segWidth, segHeight + 1, _color); break;
}
}新闻来源:玩转单片机与嵌入式,文中所述为作者独立观点,不代表icspec立场。更多精彩资讯请下载icspec App。如对本稿件有异议,请联系微信客服specltkj。

