厨房定时器用户界面流程
打开电源后,设备将显示“arduino kitchen timer”消息3秒钟。
然后计时器将提示您设置时间。您可以通过按左右键将光标移动到分钟和小时。
您可以使用向上和向下箭头键调整分钟和小时设置。
设置了所需的时间后,按下选择按钮,计时器将启动。
如果您想再次设置时间,请再次按下选择按钮。
一旦时间结束,蜂鸣器将发出蜂鸣声。
要停止蜂鸣器,请按键盘护罩上的重置按钮。
厨房定时器所需的组件
arduino
lcd键盘护盾
蜂鸣器
厨房定时器的电路图
首先,对齐并放置l cd keypad直接屏蔽arduino。然后将蜂鸣器的正极连接到arduino上的引脚12,将蜂鸣器的负极连接到地面。
arduino厨房定时器项目代码
将以下代码复制并上传到arduino ide中。代码的每个部分都有一个附带的解释,以帮助您了解它的功能。
#include
// select the pins used for the lcd keypad
liquidcrystal lcd(8, 9, 4, 5, 6, 7);
// define some variables
int lcd_key = 0;
int adc_key_in = 0;
int hrs = 0;
int mins = 0;
int set_mins = 0;
int set_hrs = 1;
int secs = 60;
int cursor_pos = 1;
int buzzer_pin = 12;
bool starttimer = false;
bool settimer = true;
bool get_time = false;
unsigned long interval=1000; // the time we need to wait
unsigned long previousmillis=0; // millis() returns an unsigned long.
// defining button used by the lcd keypad
#define btnright 0
#define btnup 1
#define btndown 2
#define btnleft 3
#define btnselect 4
#define btnnone 5
// read the buttons
int read_lcd_buttons()
{
adc_key_in = analogread(0); // reading the button value from the lcd keypad
// checking which button is pressed
if (adc_key_in 》 1000) return btnnone; // we make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in 《 50) return btnright;
if (adc_key_in 《 250) return btnup;
if (adc_key_in 《 450) return btndown;
if (adc_key_in 《 650) return btnleft;
if (adc_key_in 《 850) return btnselect;
return btnnone; // when all others fail, return this.。.
}
void setup()
{
serial.begin(115200);
pinmode(buzzer_pin, output);
lcd.begin(16, 2); // start communication with lcd keypad shield
lcd.setcursor(0,0);
lcd.print(“arduino kitchen”);
lcd.setcursor(0, 1);
lcd.print(“ timer”);
delay(3000);
}
void loop(){
// checking which condition is true based on the button pressed
if(starttimer == true){
start_timer();
}
else if (settimer == true){
set_timer();
}
}
// this function will count the time and will beep the buzzer when the time will be up.
void start_timer(){
// checking whether time is up or not
if(hrs == 0 && mins == 0 && secs == 0){
lcd.setcursor(0, 0);
lcd.print(“ time is up”);
lcd.setcursor(0, 1);
lcd.print(“ beep beep”);
digitalwrite(buzzer_pin, high);
delay(500);
digitalwrite(buzzer_pin, low);
delay(500);
}
else if(secs 《 0){
secs = 59;
mins = mins - 1;
}
else if(mins 《 0){
mins = 59;
hrs = hrs - 1;
}
else
{
get_time = true;
counter();
lcd.setcursor(0, 0);
lcd.print(“timer is on”);
lcd.setcursor(0, 1);
lcd.print(hrs);
lcd.print(“:”);
lcd.setcursor(4, 1);
lcd.print(mins);
lcd.print(“:”);
lcd.setcursor(8, 1);
lcd.print(secs);
}
lcd_key = read_lcd_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
// if select button is pressed, move back to set time
case btnselect:
{
starttimer = false;
settimer = true;
delay(300);
lcd.clear();
break;
}
case btnnone:
{
break;
}
}
}
// this function will set the time
void set_timer(){
counter();
lcd.setcursor(0, 0);
lcd.print(“set time”);
lcd.setcursor(0, 1);
lcd.print(“hrs:”);
lcd.print(hrs);
lcd.setcursor(8, 1);
lcd.print(“mins:”);
lcd.print(mins);
lcd.setcursor(0,1);
lcd_key = read_lcd_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
// if right button is pressed, then move the cursor to minutes
case btnright:
{
cursor_pos = set_mins;
break;
}
// if left button is pressed, then move the cursor to hours
case btnleft:
{
cursor_pos = set_hrs;
break;
}
// if up button is pressed, add 1 to the minutes or hours
case btnup:
{
delay(300);
if(cursor_pos == set_mins){
mins++;
if(mins 》 59){
mins = 0;
}
}
else if(cursor_pos == set_hrs){
hrs++;
if(hrs 》 24){
hrs = 0;
}
}
break;
}
// if down button is pressed, minus 1 from the minutes or hours
case btndown:
{
delay(300);
if(cursor_pos == set_mins){
mins--;
if(mins 《 0){
mins = 60;
}
}
else if(cursor_pos == set_hrs){
hrs--;
if(hrs 《 0){
hrs = 24;
}
}
break;
}
// if select button is pressed, start the timer
case btnselect:
{
starttimer = true;
settimer = false;
mins = mins - 1;
delay(300);
break;
}
case btnnone:
{
break;
}
}
}
void counter() {
unsigned long currentmillis = millis(); // grab current time
// check if “interval” time has passed (1000 milliseconds)
if ((unsigned long)(currentmillis - previousmillis) 》= interval) {
lcd.clear();
if(get_time == true){
secs--;
get_time = false;
}
previousmillis = millis();
}
}
创建厨房计时器只是一个开始!
您已经创建了自己的厨房计时器!该项目的最佳部分是能够调整该模块以构建其他项目,这些项目需要lcd和按钮或蜂鸣器之间的简单接口。您还可以为模块设计自定义3d打印的外壳,并使其成为您自己的。
LT5571-620MHz-1100MHz高线性度直接正交调
荣誉 | 助力数字经济发展 百望云入选“2022数字经济创新企业100强”
2017年手机照相技术可能的创新点
2019年全球智能手表市场报告分析
低至70μW | 国芯发布超低功耗AI芯片,助力智能穿戴「芯」升级
如何创建一个Arduino控制的厨房计时器
手持PDA的使用步骤介绍
使用1,200V碳化硅数字栅极驱动器降低开关损耗
赋能千行百业数字化转型,OpenHarmony生态新成果即将亮相HDC2022
电线电缆塑化塑化不良的现象及排除方法
OPPO R9s玩完配色再玩配置,你还会一如既往的喜爱它吗?OPPO R11能否成功为OPPO R9续命?
人工智能芯片趋向于软硬件协同设计的模式
网络搜索也能赚钱?区块链或许能帮你实现!
smt与dip生产步骤介绍
红色iPhone7 Plus 和它的红色伙伴们!都在这里
生物医药智能工厂数字孪生可视化平台,推进医药产业数字化转型
iphone7将搭配紫色是真的?
企业应该怎样管理云平台
特斯拉股东指控特斯拉和马斯克存在证券欺诈,向法院寻求集体诉讼
市场分析:苹果手机的竞争基础是什么?