本文要介绍的是一个由arduino驱动的数字时钟,同时也是一个非常有趣的四冲程发动机模拟器,通过小时和分钟处的数字模拟汽车发动机的活塞运动。
介绍
由arduino驱动的“四冲程数字时钟”是一个有趣的数字时钟内燃机模拟器。小时和分钟数字代表活塞移动并具有精确的rpm控制(100到800),rpm由显示屏中心的两列显示。
另一个有趣的视觉信息是气缸的点火顺序“1-3-4-2”。当活塞在压缩循环中位于气缸顶部时,火花开始。该项目可以作为学习管理点阵像素和引入简单动画功能的一个很好的练习。
四冲程内燃机
该项目中使用的发动机型号是四冲程循环的i4(直列四缸)。四冲程内燃机分为四个步骤(进气-压缩-燃烧-排气),其中一步如下图所示:
注意:更多内燃机的基本信息可以在维基百科上找到。
时钟
在这个项目中,小时和分钟的数字模拟了活塞的运动,并且所有气缸的火花在正确的时间突出显示。
精确计算旋转以表示实际速度,并通过旋转电位计在100至800rpm(每分钟转数)之间调整该值。
材料清单
arduinounor3
led点阵与max7219
ds1307rtc(实时时钟)
旋转电位器-10kohms
面包板
打印模板
跳线
3d打印文件:
示意图:
本文所用到代码:
#include // led 矩阵库 - max72xx
#include // ds1307rtc 库 - arduino uno 的引脚:a4 (sda), a5 (scl)
#include // 实时时钟库
#include // 时间库
#include
// 全局变量
字节 hh, mm ; // 小时,分钟
字节uh,um,dh,dm ; // 单位小时,单位分钟,青少年小时,青少年分钟
字节p = 0 ; // 绘图模式(数字位置:上/下)
int rpm = 0 , lastrpm = 0 , pinrpm = 0 ; // rpm,rpm 的最后值,rpm 的模拟引脚
字节序列 = 1 ; // 开始火序列
/*
用于连接 max72xx的 arduino 引脚号(带 max72xx 控制器的 led 阵列)
引脚5连接到 datain ( din )
引脚6连接到负载( cs )
引脚7连接到 clk ( clk )
*/
ledcontrol lc = ledcontrol ( 5 , 7 , 6 , 2 ) ; // ledcontrol ( int din, int clk, int cs, int numdevices )
// 数字数组 - ( 0到9 ) - 大小 5x3
字节数[ 10 ] [ 3 ] = {
{ 0xf8, 0x88, 0xf8 } , // 0
{ 0x00, 0xf8, 0x40 } , // 1
{ 0xe8, 0xa8, 0xb8 } , // 2
{ 0xf8, 0xa8, 0x88 } , // 3
{ 0x78, 0x20, 0xe0 } , // 4
{ 0xb8, 0xa8, 0xe8 } , // 5
{ 0xb8, 0xa8, 0xf8 } , // 6
{ 0xc0, 0xb8, 0x80 } , // 7
{ 0xf8, 0xa8, 0xf8 } , // 8
{ 0xf8, 0xa0, 0xe0 } , // 9
};
无效设置() {
setsyncprovider(rtc.get); // function to read rtc (real time clock)
setsyncinterval(60); // set the number of seconds between re-sync
//settime(8, 19, 30, 10, 02, 2018); // set the time and date (hour, minute, second, day, month, year)
//rtc.set(now()); // set the rtc time
// setup of display 0
lc.shutdown(0, false); // wakeup display 0
lc.setintensity(0, 4); // set the brightness of display (0 to 15)
lc.cleardisplay(0); // clear display 0
// setup of display 1
lc.shutdown(1, false); // wakeup display 1
lc.setintensity(1, 4); // set the brightness of display (0 to 15)
lc.cleardisplay(1); // clear display 1
}
void loop() {
hh = hour();
mm = minute();
uh = hh % 10;
dh = hh / 10;
um = mm % 10;
dm = mm / 10;
// plot hours
for (byte k = 0; k > (p + 2));
lc.setrow(0, k + 1, num[uh][k] >> (3 - p));
}
// plot minutes
for (byte k = 0; k > (3 - p));
lc.setrow(1, k , num[um][k] >> (p + 2));
}
// plot fire sequence: 1-3-4-2 (4 cyl: 1-3-4-2 or 1-2-4-3 or 1-4-3-2)
if (seq == 1) { // fire cyl #1
lc.setled(0, 6, 0, true);
}
if (seq == 2) { // fire cyl #3
lc.setled(1, 5, 0, true);
}
if (seq == 3) { // fire cyl #4
lc.setled(1, 1, 0, true);
}
if (seq == 4) { // fire cyl #2
lc.setled(0, 2, 0, true);
}
seq = seq % 4 + 1;
// rpm reading
rpm = analogread(pinrpm); // potentiometer reading
rpm = map(rpm, 0, 1023, 1, 9);
if (rpm <= 8) {
lc.setled(1, 7, 8 - rpm, true);
lc.setled(0, 0, 8 - rpm, true);
delay(300 / rpm); // speed setup by potentiometer (100 - 800 rpm)
if (lastrpm != rpm) {
lc.setrow(0, 0, 0);
lc.setrow ( 1 , 7 , 0 ) ;
最后转数 =转数;
}
}
p = !p ; // 切换数字位置(上 x 下)
}
线上教育带领了哪一些领域的发展
基于控制台的通讯录管理系统功能介绍
水文监测设备的应用领域及其特点说明
电位计是什么?都有哪些用途
4G手机芯片 掀起各电子厂商车轮战
一个由Arduino驱动的数字时钟详解
如何建设简单舒适的智能家居的方案
轴承位磨损如何修复
运算放大器和电压比较器详解
教您如何区分单晶硅和多晶硅电池板
CH341与USB接口的基本连接
贸泽电子参加第四届深圳国际嵌入式系统展
掌握开关稳压器的5大基本知识(下)
AI+教育大势所趋,人工智能怎么培养人才?
成型机料位测量常见问题及应对办法
总投资20亿元,泽石固态硬盘模组及芯片封测生产基地签约落户
面对人工智能的发展 人类未来将扮演怎样的角色?
二叉树的统一迭代法
浙江富润与紫光国微达成战略合作 将提升5G用户体验
领跑全球!中国6G那些激动人心的瞬间