当前位置:网站首页>玩转OLED,U8g2动画,增长数字和随机三角形等
玩转OLED,U8g2动画,增长数字和随机三角形等
2022-06-27 00:10:00 【arenascat】
1.动态数字显示
从逻辑上来说,就是绘制一个实心方块,遮挡上一次绘制的内容,然后再绘制这一次的。
//动画数字效果
void dynamicNum(int x, int y, int num)
{
int i;
for (i = 0; i < num; i++)
{
u8g2.setDrawColor(0);
u8g2.drawBox(x, 10, 60, 60);
u8g2.setCursor(x, y);
u8g2.setDrawColor(1);
u8g2.print(i);
u8g2.drawBox(0, 63 - 3, (127 / 100) * i, 3);
u8g2.sendBuffer();
delay(2);
}
}2.三角形的绘制
这一个算法就是画一个等边三角形,本来是这样的,但我加了伪随机数,于是就变成了一个乱飞的三角形
random(int i)函数,用于生成从0到i的一个数字
void animateG(int x, int y, int r)
{
int rd1 = random(2);
int rd2 = random(3);
int rd3 = random(3);
int rd4 = random(3);
int rd5 = random(3);
int rd6 = random(2);
u8g2.drawLine(x * rd1, (y - r * 2 / 3) * rd2, (x + r / sqrt(3)) * rd3, (y + r / 3) * rd4);
u8g2.drawLine((x + r / sqrt(3)) * rd3, (y + r / 3) * rd4, (x - r / sqrt(3)) * rd5, (y + r / 3) * rd6);
u8g2.drawLine((x - r / sqrt(3)) * rd5, (y + r / 3) * rd6, x * rd1, (y - r * 2 / 3) * rd2);
}3.屏幕关闭效果
类似老电视的那种显像管失电后十字关闭的效果,我是想模仿这个的。
void close()
{
u8g2.clear();
u8g2.drawBox(0, 63 / 2 - 3, 127, 6);
u8g2.drawBox(127 / 2 - 3, 0, 6, 63);
u8g2.sendBuffer();
delay(3);
u8g2.clear();
u8g2.drawBox(0, 63 / 2 - 2, 127, 4);
u8g2.drawBox(127 / 2 - 2, 0, 4, 63);
u8g2.sendBuffer();
delay(3);
u8g2.clear();
u8g2.drawBox(0, 63 / 2 - 1, 127, 2);
u8g2.drawBox(127 / 2 - 1, 0, 2, 63);
u8g2.sendBuffer();
delay(3);
u8g2.clear();
}边栏推荐
- 安利!如何提优质的ISSUE?学霸是这样写的!
- JS library for number formatting
- Target tracking shooting? Target occlusion shooting? With 1.9 billion installed petal apps, what unique features attract users?
- Record a bug caused by a line break
- Can I open an account for stock trading on my mobile phone? Is it safe to open an account for stock trading on the Internet
- 技术干货|什么是大模型?超大模型?Foundation Model?
- MindSpore新型轻量级神经网络GhostNet,在ImageNet分类、图像识别和目标检测等多个应用场景效果优异!
- These 10 copywriting artifacts help you speed up the code. Are you still worried that you can't write a copywriting for US media?
- 2022年地理信息系统与遥感专业就业前景与升学高校排名选择
- 小白看MySQL--windows环境安装MySQL
猜你喜欢

Redis detailed tutorial

Ten thousand words explanation - mindarmour Xiaobai tutorial!

墨者学院-SQL注入漏洞测试(报错盲注)

Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario

Memorizing byte order of big and small end

这3个并发编程的核心,竟然还有人不知道?

Big guys talk about the experience sharing of the operation of the cutting-edge mindspore open source community. Come up with a small notebook!

1+1<2 ?! Interpretation of hesic papers

Com. Faster XML. Jackson. DataBind. Exc.mismatchedinputexception: tableau ou chaîne attendu. At [Source: X

Lambda表达式
随机推荐
滑环选型选购时需要注意的技巧
Great health industry annual must attend event, 2022 Shandong International Great Health Industry Expo
How to control the quality of HD slip ring in the production process
05 | 規範設計(下):commit 信息風格迥异、難以閱讀,如何規範?
2022年地理信息系统与遥感专业就业前景与升学高校排名选择
redis详细教程
这3个并发编程的核心,竟然还有人不知道?
05 | standard design (Part 2): how to standardize the different styles of commit information, which are difficult to read?
剑指 Offer 10- II. 青蛙跳台阶问题
How to open an account on the mobile phone? Is it safe to open an account online and speculate in stocks
Mindspire, a domestic framework, cooperates with Shanshui nature conservation center to find and protect the treasure life in the "China water tower"
运用物理信息神经网络求解流体力学方程
Cve-2022-30190 follina office rce analysis [attached with customized word template POC]
Can I open an account for stock trading on my mobile phone? Is it safe to open an account for stock trading on the Internet
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
Lwip之ARP模块实现
Simple and fast digital network (network dolls in the network)
Technical dry goods | what is a big model? Oversized model? Foundation Model?
【Mysql】时间字段默认设置为当前时间
从位图到布隆过滤器,C#实现