本网页已闲置超过3分钟,按键盘任意键或点击空白处,即可回到网页
最热资讯


亲,“电路城”已合并升级到更全、更大、更强的「新与非网」。点击查看「新与非网」
该项目主要是通过Arduino Nano和LCD制作秒表,秒表执行三个基本功能,即启动,暂停/停止,重置,并且可以计数到23:59:59。
硬件:
原理图:
将开关的一端连接至Nano的数字I / O引脚,将另一端(对角端)连接至+ 5V。(可以根据使用的开关类型将另一端连接到GND)。其次连接16x2 LCD。
代码:
/ *带有停止,开始,重置和圈速按钮的简单LCD秒表程序。* /
//包括LCD的库
#include <LiquidCrystal.h>
//设置LCD INPUT引脚
LiquidCrystal lcd(12,11,10,9,8,7);//(RS,E D4,D5,D6,D7)
//将小时,分钟,秒和毫秒设置为0
int h=0;
int m=0;
int s=0;
int ms=0;
//定义所有按钮的针脚
const int startPin = 3;
const int stopPin = 4;
const int resetPin = 5;
//定义起点
int start=0;
int stop1=0;
int reset=0;
void stopwatch()
{
lcd.setCursor(3,0); //在LCD上设置起点
lcd.print("TIME:"); //显示时间
lcd.print(h); //显示时
lcd.print(":");
lcd.print(m); //显示分钟
lcd.print(":");
lcd.print(s); //显示秒
lcd.setCursor(3,1);
lcd.print(" ");
ms=ms+10;
delay(10);
if(ms==590)
{
ms=0;
s=s+1;
}
if(s==60) //如果是分钟计数状态
{
s=0;
m=m+1;
}
if(m==60) //如果状态为小时数
{
m=00;
h=h+01;
}
stop1 = digitalRead(stopPin); //读取buton状态
if(stop1 == HIGH) //检查是否按下了按钮
{
stopwatch_stop(); //调用stopwatch_stop函数
}
else
{
stopwatch(); //调用秒表功能
}
}
void stopwatch_stop()
{
lcd.setCursor(3,0);
lcd.print("TIME:");
lcd.print(h);
lcd.print(":");
lcd.print(m);
lcd.print(":");
lcd.print(s);
lcd.setCursor(3,1);
lcd.print(" ");
start = digitalRead(startPin); //读取buton状态
if(start == HIGH)
{
stopwatch(); //调用秒表功能
}
}
reset = digitalRead(resetPin); //读取buton状态
if(reset == HIGH)
{
stopwatch_reset(); //调用stopwatch_reset函数
loop();
}
if(reset == LOW)
{
stopwatch_stop(); //调用stopwatch_stop函数
}
}
void stopwatch_reset()
{
lcd.clear();
h = 00 ; //将小时数设为0
m = 00 ; //将分钟设置为0
s = 00 ; //将秒设置为0
return; //退出程序并返回到输入程序的位置
}
void setup()
{
lcd.begin(16 ,2); //启动 LCD
//定义输入或输出引脚
pinMode(startPin, INPUT);
pinMode(stopPin, INPUT);
pinMode(resetPin, INPUT);
}
void loop()
{
lcd.setCursor(3,1);
lcd.print("STOPWATCH");
lcd.setCursor(3,0);
lcd.print("TIME:");
lcd.print(h);
lcd.print(":");
lcd.print(m);
lcd.print(":");
lcd.print(s);
start = digitalRead(startPin); //读取buton状态
if(start == HIGH)
{
stopwatch(); //调用秒表功能
}
}
基于Arduino的温控风扇
2021-07-06
如何将超声波传感器与 Arduino 连接
2021-07-02
基于esp8266的便携式无线PM2.5检测电路设计
2020-02-07
基于MEMS的惯性测量装置 (IMU) 检测电路设计
2020-02-06
硬实力,游戏机自己做,十个经典游戏机方案合集
2020-08-24
如何将按钮与 Arduino 连接起?
2021-07-13
基于树莓派和Arduino打造的PLC EtherCAT电路设计
2020-02-25
入门指南:TFT彩色显示屏,带Arduino和ESP8266
2020-04-23
Arduino最小系统板设计PCB板及原理图
2020-01-17
带有Arduino和ESP32的实时时钟
2020-04-17
讨论