0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何創(chuàng)建一個(gè)Arduino控制的廚房計(jì)時(shí)器

454398 ? 來(lái)源:工程師吳畏 ? 2019-08-05 10:39 ? 次閱讀

廚房定時(shí)器用戶界面流程

打開電源后,設(shè)備將顯示“Arduino Kitchen Timer”消息3秒鐘。

然后計(jì)時(shí)器將提示您設(shè)置時(shí)間。您可以通過(guò)按左右鍵將光標(biāo)移動(dòng)到分鐘和小時(shí)。

您可以使用向上和向下箭頭鍵調(diào)整分鐘和小時(shí)設(shè)置。

設(shè)置了所需的時(shí)間后,按下選擇按鈕,計(jì)時(shí)器將啟動(dòng)。

如果您想再次設(shè)置時(shí)間,請(qǐng)?jiān)俅伟聪逻x擇按鈕。

一旦時(shí)間結(jié)束,蜂鳴器將發(fā)出蜂鳴聲。

要停止蜂鳴器,請(qǐng)按鍵盤護(hù)罩上的重置按鈕。

廚房定時(shí)器所需的組件

Arduino

LCD鍵盤護(hù)盾

蜂鳴器

廚房定時(shí)器的電路圖

首先,對(duì)齊并放置L CD Keypad直接屏蔽Arduino。然后將蜂鳴器的正極連接到Arduino上的引腳12,將蜂鳴器的負(fù)極連接到地面。

Arduino廚房定時(shí)器項(xiàng)目代碼

將以下代碼復(fù)制并上傳到Arduino IDE中。代碼的每個(gè)部分都有一個(gè)附帶的解釋,以幫助您了解它的功能。

#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();

}

}

創(chuàng)建廚房計(jì)時(shí)器只是一個(gè)開始!

您已經(jīng)創(chuàng)建了自己的廚房計(jì)時(shí)器!該項(xiàng)目的最佳部分是能夠調(diào)整該模塊以構(gòu)建其他項(xiàng)目,這些項(xiàng)目需要LCD和按鈕或蜂鳴器之間的簡(jiǎn)單接口。您還可以為模塊設(shè)計(jì)自定義3D打印的外殼,并使其成為您自己的。

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 計(jì)時(shí)器
    +關(guān)注

    關(guān)注

    1

    文章

    426

    瀏覽量

    32912
  • Arduino
    +關(guān)注

    關(guān)注

    188

    文章

    6477

    瀏覽量

    188113
收藏 0人收藏

    評(píng)論

    相關(guān)推薦

    EE-109:ADSP2106x:使用2106x SPORT作為計(jì)時(shí)器

    電子發(fā)燒友網(wǎng)站提供《EE-109:ADSP2106x:使用2106x SPORT作為計(jì)時(shí)器.pdf》資料免費(fèi)下載
    發(fā)表于 01-07 14:11 ?0次下載
    EE-109:ADSP2106x:使用2106x SPORT作為<b class='flag-5'>計(jì)時(shí)器</b>

    單個(gè) MSP430? 計(jì)時(shí)器模塊的多時(shí)基應(yīng)用說(shuō)明

    電子發(fā)燒友網(wǎng)站提供《單個(gè) MSP430? 計(jì)時(shí)器模塊的多時(shí)基應(yīng)用說(shuō)明.pdf》資料免費(fèi)下載
    發(fā)表于 09-13 11:09 ?0次下載
    單個(gè) MSP430? <b class='flag-5'>計(jì)時(shí)器</b>模塊的多時(shí)基應(yīng)用說(shuō)明

    MSPM0-高級(jí)控制計(jì)時(shí)器有助于實(shí)現(xiàn)更好的控制和更好的數(shù)字輸出

    電子發(fā)燒友網(wǎng)站提供《MSPM0-高級(jí)控制計(jì)時(shí)器有助于實(shí)現(xiàn)更好的控制和更好的數(shù)字輸出.pdf》資料免費(fèi)下載
    發(fā)表于 08-28 11:30 ?0次下載
    MSPM0-高級(jí)<b class='flag-5'>控制</b><b class='flag-5'>計(jì)時(shí)器</b>有助于實(shí)現(xiàn)更好的<b class='flag-5'>控制</b>和更好的數(shù)字輸出

    用于電源門控的TPL5110毫微功耗系統(tǒng)計(jì)時(shí)器數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《用于電源門控的TPL5110毫微功耗系統(tǒng)計(jì)時(shí)器數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 08-23 11:26 ?0次下載
    用于電源門控的TPL5110毫微功耗系統(tǒng)<b class='flag-5'>計(jì)時(shí)器</b>數(shù)據(jù)表

    用于電源門控應(yīng)用的TPL5111毫微功耗系統(tǒng)計(jì)時(shí)器數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《用于電源門控應(yīng)用的TPL5111毫微功耗系統(tǒng)計(jì)時(shí)器數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 08-23 11:25 ?0次下載
    用于電源門控應(yīng)用的TPL5111毫微功耗系統(tǒng)<b class='flag-5'>計(jì)時(shí)器</b>數(shù)據(jù)表

    TLC555-Q1 LinCMOS?計(jì)時(shí)器數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《TLC555-Q1 LinCMOS?計(jì)時(shí)器數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 08-23 11:19 ?0次下載
    TLC555-Q1 LinCMOS?<b class='flag-5'>計(jì)時(shí)器</b>數(shù)據(jù)表

    TLC555 LinCMOS?技術(shù)計(jì)時(shí)器數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《TLC555 LinCMOS?技術(shù)計(jì)時(shí)器數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 08-20 11:15 ?0次下載
    TLC555 LinCMOS?技術(shù)<b class='flag-5'>計(jì)時(shí)器</b>數(shù)據(jù)表

    LMC555 CMOS計(jì)時(shí)器數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《LMC555 CMOS計(jì)時(shí)器數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 08-20 09:16 ?0次下載
    LMC555 CMOS<b class='flag-5'>計(jì)時(shí)器</b>數(shù)據(jù)表

    spi_flash期間的計(jì)時(shí)器中斷導(dǎo)致崩潰怎么解決?

    這是我遇到的 SDK 中的個(gè)小錯(cuò)誤 (esp_iot_sdk_v0.9.5_b1): 我在 Timer1 上使用計(jì)時(shí)器中斷: ets_frc_timer1_intr_attach
    發(fā)表于 07-12 11:54

    在esp8266中構(gòu)建了個(gè)HTTP服務(wù),功處理HTTP請(qǐng)求后,軟件計(jì)時(shí)器停止了,為什么?

    定時(shí)回調(diào)中創(chuàng)建的任務(wù)中的連接工作,都失敗了。我在HTTP處理后設(shè)置了個(gè)新的軟件計(jì)時(shí)器,也失敗了...... 在處理HTTP請(qǐng)求的任務(wù)中,
    發(fā)表于 07-10 06:15

    TLE986x如何定期重新啟動(dòng)計(jì)時(shí)器

    我在模式 0-13 位定時(shí)模式下運(yùn)行 T3。 達(dá)到溢出時(shí),計(jì)時(shí)器停止。 請(qǐng)問如何定期重新啟動(dòng)計(jì)時(shí)器?
    發(fā)表于 07-03 07:13

    雙路精密計(jì)時(shí)器選購(gòu)指南:準(zhǔn)確選擇,高效工作

    在快節(jié)奏的現(xiàn)代生活中,準(zhǔn)確的時(shí)間管理對(duì)于個(gè)人和團(tuán)隊(duì)的成功至關(guān)重要。雙路精密計(jì)時(shí)器作為種高效的計(jì)時(shí)工具,受到了越來(lái)越多人的青睞。那么,如何選購(gòu)款適合自己的雙路精密
    的頭像 發(fā)表于 06-26 16:06 ?431次閱讀

    SNx5DPHY440SS CSI-2/DSI DPHY 重計(jì)時(shí)器數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《SNx5DPHY440SS CSI-2/DSI DPHY 重計(jì)時(shí)器數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 06-25 11:07 ?1次下載
    SNx5DPHY440SS CSI-2/DSI DPHY 重<b class='flag-5'>計(jì)時(shí)器</b>數(shù)據(jù)表

    帶看門狗計(jì)時(shí)器的TPS382x電壓監(jiān)視數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《帶看門狗計(jì)時(shí)器的TPS382x電壓監(jiān)視數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 03-25 09:52 ?0次下載
    帶看門狗<b class='flag-5'>計(jì)時(shí)器</b>的TPS382x電壓監(jiān)視<b class='flag-5'>器</b>數(shù)據(jù)表

    具有使能功能的 TPS3431 標(biāo)準(zhǔn)可編程監(jiān)視計(jì)時(shí)器數(shù)據(jù)表

    電子發(fā)燒友網(wǎng)站提供《具有使能功能的 TPS3431 標(biāo)準(zhǔn)可編程監(jiān)視計(jì)時(shí)器數(shù)據(jù)表.pdf》資料免費(fèi)下載
    發(fā)表于 03-13 14:31 ?0次下載
    具有使能功能的 TPS3431 標(biāo)準(zhǔn)可編程監(jiān)視<b class='flag-5'>器</b><b class='flag-5'>計(jì)時(shí)器</b>數(shù)據(jù)表

    電子發(fā)燒友

    中國(guó)電子工程師最喜歡的網(wǎng)站

    • 2931785位工程師會(huì)員交流學(xué)習(xí)
    • 獲取您個(gè)性化的科技前沿技術(shù)信息
    • 參加活動(dòng)獲取豐厚的禮品