Cov txheej txheem:

Digital Saib ntawm Arduino Siv Lub Xeev Lub Xeev Tshuab: 6 Cov Kauj Ruam
Digital Saib ntawm Arduino Siv Lub Xeev Lub Xeev Tshuab: 6 Cov Kauj Ruam

Video: Digital Saib ntawm Arduino Siv Lub Xeev Lub Xeev Tshuab: 6 Cov Kauj Ruam

Video: Digital Saib ntawm Arduino Siv Lub Xeev Lub Xeev Tshuab: 6 Cov Kauj Ruam
Video: Computer Vision with Python! Resizing Images 2024, Kaum ib hlis
Anonim
Digital Saib ntawm Arduino Siv Lub Xeev Lub Xeev Tshuab
Digital Saib ntawm Arduino Siv Lub Xeev Lub Xeev Tshuab

Nyob zoo, Kuv yuav qhia koj li cas lub moos saib tau tsim nrog YAKINDU Statechart Cov Cuab Yeej thiab khiav ntawm Arduino, uas siv LCD Keypad Shield.

Thawj tus qauv ntawm cov saib digital tau coj los ntawm David Harel. Nws tau luam tawm ib daim ntawv hais txog

"[…] kev nthuav dav dav dav ntawm kev ua haujlwm zoo ntawm lub xeev cov tshuab thiab lub xeev daim duab."

Hauv daim ntawv no, nws siv tus piv txwv ntawm cov saib digital rau nws qhov kev tshawb fawb. Kuv tau siv nws los ua kev tshoov siab thiab rov kho lub moos nrog YAKINDU Statechart Cov Cuab Yeej (cov cuab yeej tsim cov qauv duab ntawm lub xeev cov tshuab thiab tsim C/C ++ code nrog nws) thiab coj nws rov qab los rau ntawm Arduino.

Khoom siv

Kho vajtse:

  • Arduino Uno lossis Mega
  • LCD Keypad Shield

Software:

  • YAKINDU Statechart Cov Cuab Yeej
  • Dab noj hnub C ++ IDE rau Arduino

Kauj Ruam 1: Lub Digital Watch Ua Haujlwm Li Cas

Image
Image

Cia peb pib los ntawm kev txhais tias lub moos digital yuav tsum ua haujlwm li cas. Koj puas nco qab cov no … cia peb hais … "ultra txias" digital watches txhua tus tau rov qab rau hauv '90s? Lub sijhawm sib koom ua ke, lub tswb sib txawv thiab nws lub suab nrov tsis txaus siab txhua teev. Yog tsis yog, saib: 90's saib digital.

Yog li hauv paus nws yog lub teeb pom kev saib nrog ntau hom. Feem ntau, lub sijhawm tam sim no yuav tshwm sim, tab sis muaj qee qhov ntxiv. Raws li kev tawm tswv yim, koj tau txais/qhib, hom thiab teeb tsa khawm. Ib qho ntxiv, koj tuaj yeem tig lub teeb rau thiab tawm. Nrog khawm hom koj tuaj yeem paub qhov txawv nruab nrab ntawm cov qauv thiab qhib/ua haujlwm lub moos nta:

  • Zaub lub sijhawm (Moos)
  • Zaub hnub tim (Date)
  • Teem lub tswb (Tswb 1, Tswb 2)
  • Pab/lov tes taw chime (Teem Chime)
  • Siv lub stopwatch (Stop Watch)

Hauv cov ntawv qhia zaub mov, koj tuaj yeem siv lub khawm rau/tawm los teeb tsa hom. Lub teeb khawm tso cai rau koj teeb lub sijhawm - piv txwv li rau lub moos lossis lub tswb. Lub stopwatch tuaj yeem tswj tau - pib thiab nres - los ntawm kev siv lub teeb rau thiab lub teeb tawm khawm. Koj tseem tuaj yeem siv lub rooj sib tham ntawm tus ncej puab

Tsis tas li ntawd, muaj lub suab nrov, uas tswb txhua teev, thiab lub teeb pom kev tuaj yeem tswj tau. Thawj kauj ruam, Kuv tsis xaim lawv mus rau Arduino.

Kauj Ruam 2: Lub Xeev Tshuab

LCD Keypad Shield
LCD Keypad Shield

Kuv tsis xav mus ntau hauv kev nthuav dav rau kev piav qhia ntawm qhov piv txwv no. Nws tsis yog vim nws nyuaj dhau, nws tsuas yog me me xwb. Kuv yuav sim piav qhia lub tswv yim yooj yim ntawm nws ua haujlwm li cas. Kev ua tiav yuav tsum piav qhia tus kheej, los ntawm kev saib tus qauv lossis rub tawm thiab simulate nws. Qee qhov ntawm lub xeev cov tshuab tau suav nrog hauv cov cheeb tsam sub, zoo li thaj chaw teev sijhawm. Nrog rau qhov no, kev nyeem tau ntawm lub xeev lub tshuab yuav tsum tau ua kom ntseeg tau.

Tus qauv tau muab faib ua ob ntu - cov duab thiab cov ntawv. Hauv cov ntawv nyeem ib feem ntawm cov xwm txheej, hloov pauv, thiab lwm yam yuav raug piav qhia. Hauv daim duab ib feem - lub xeev daim duab - kev ua kom muaj txiaj ntsig ntawm tus qauv tau teev tseg. Txhawm rau tsim lub xeev lub tshuab, uas ua tiav qhov kev coj ua tshwj xeeb, qee qhov xwm txheej xav tau, uas tuaj yeem siv tau hauv tus qauv: qhib, teeb tsa, hom, teeb, thiab light_r. Tsis pub dhau lub ntsiab lus ntu ib qho kev tshwm sim sab hauv tau siv, uas nce lub sijhawm tus nqi txhua 100 ms:

txhua txhua 100 ms / sijhawm += 1

Raws li 100 ms cov kauj ruam lub sijhawm tam sim no yuav suav nyob hauv HH: MM: SS hom ntawv:

display.first = (lub sijhawm / 36000) % 24;

display.second = (sijhawm / 600) % 60; display.third = (lub sijhawm / 10) % 60;

Cov txiaj ntsig yuav raug txuas mus rau LCD zaub los ntawm kev siv kev hloov kho tshiab LCD txhua lub sijhawm lub xeev lub tshuab yuav raug hu:

display.updateLCD (display.first, display.second, display.third, display.text)

Kev ua haujlwm yooj yim ntawm lub xeev lub tshuab twb tau hais tseg hauv ntu Yuav Ua Li Cas Digital Watch ua haujlwm. Hauv qhov cuab yeej kuv tau siv qee qhov "tshwj xeeb" ua qauv zoo ib yam li CompositeState, Keeb Kwm, Daim Duab Kab Duab, ExitNodes, thiab lwm yam. Cov lus piav qhia ntxaws tuaj yeem pom hauv Phau Ntawv Qhia.

Kauj Ruam 3: LCD Keypad Shield

LCD Keypad Shield yog qhov txias heev rau cov phiaj xwm yooj yim, uas xav tau lub vijtsam rau pom kev thiab qee cov nyees khawm raws li cov tswv yim - ib txwm, yooj yim HMI (Tib Neeg Tshuab Sib Txuas). LCD Keypad Shield muaj tsib tus neeg siv khawm thiab lwm tus rau rov pib dua. Tsib lub khawm txhua tus ua ke txuas nrog A0 tus pin ntawm Arduino. Txhua tus ntawm lawv txuas nrog rau qhov faib hluav taws xob, uas tso cai sib txawv ntawm cov nyees khawm.

Koj tuaj yeem siv analogRead (0) txhawm rau nrhiav cov txiaj ntsig tshwj xeeb, uas tuaj yeem, tau kawg, sib txawv los ntawm cov chaw tsim khoom. Txoj haujlwm yooj yim no qhia tus nqi tam sim no ntawm LCD:

#suav nrog "Arduino.h"

#suav nrog "LiquidCrystal.h" LiquidCrystal lcd (8, 9, 4, 5, 6, 7); teeb tsa tsis muaj dab tsi () {lcd.begin (16, 2); lcd.setCursor (0, 0); lcd.write ("Ntsuas Tus Nqi"); } tsis muaj dab tsi voj () {lcd.setCursor (0, 1); lcd.print (""); lcd.setCursor (0, 1); lcd.print (analogRead (0)); ncua (200); }

Nov yog kuv cov txiaj ntsig ntsuas:

  • Tsis muaj: 1023
  • Xaiv: 640
  • Sab laug: 411
  • Qhov siab: 257
  • Ua ntej: 100
  • Txoj cai: 0

Nrog cov pib no nws muaj peev xwm nyeem cov nyees khawm:

#define NONE 0 #txhais SELECT 1 #define LEFT 2 #define DOWN 3 #define UP 4 #define RIGHT 5 zoo li qub int readButton () {int result = 0; tau = analogRead (0); yog (qhov tshwm sim <50) {rov qab RIGHT; } yog (qhov tshwm sim <150) {rov qab UP; } yog (qhov tshwm sim <300) {rov qab DOWN; } yog (qhov tshwm sim <550) {rov qab LEFT; } yog (qhov tshwm sim <850) {rov SELECT; } rov tsis muaj; }

Kauj Ruam 4: cuam tshuam nrog Lub Xeev Tshuab

Cuam tshuam nrog Lub Xeev Tshuab
Cuam tshuam nrog Lub Xeev Tshuab

Qhov tsim tawm C ++ cov cai ntawm lub xeev tshuab muab kev cuam tshuam, uas yuav tsum tau ua los tswj lub xeev lub tshuab. Thawj kauj ruam yog txuas cov xwm txheej nrog cov yuam sij ntawm Keypad Shield. Kuv twb tau qhia yuav ua li cas nyeem cov nyees khawm, tab sis rau cuam tshuam lawv mus rau lub xeev lub tshuab, debouncing cov nyees khawm yog xav tau - txwv tsis pub, cov xwm txheej yuav raug tsa ntau zaus, uas ua rau tsis paub txog tus cwj pwm. Lub tswv yim ntawm software debouncing tsis yog qhov tshiab. Koj tuaj yeem saib ntawm Arduino cov ntaub ntawv.

Hauv kuv qhov kev coj ua, Kuv pom qhov poob qis (tso lub pob). Kuv nyeem tus nqi ntawm lub pob, tos 80 ms (tau txais txiaj ntsig zoo dua nrog 80 siv 50), txuag qhov tshwm sim thiab nyeem tus nqi tshiab. Yog tias qhov qubResult tsis yog TSIS MUAJ (tsis muaj kev nyuaj siab) thiab qhov tshwm sim tshiab yog TSIS MUAJ, Kuv paub, tias lub pob tau raug nias ua ntej thiab tam sim no tau raug tso tawm. Tom qab ntawd, Kuv tsa qhov kev tshwm sim nkag los ntawm lub tshuab hauv xeev.

int oldState = TSIS MUAJ; zoo li qub tsis muaj dabtsis nceEvents () {int buttonPressed = readButton (); ncua (80); oldState = khawm khawm; if (oldState! = NONE && readButton () == NONE) {hloov (oldState) {case SELECT: {stateMachine-> getSCI_Button ()-> raise_mode (); tawg; } rooj LEFT: {stateMachine-> getSCI_Button ()-> raise_set (); tawg; } case DOWN: {stateMachine-> getSCI_Button ()-> nce_light (); tawg; } rooj plaub UP: {stateMachine-> getSCI_Button ()-> nce_light_r (); tawg; } rooj plaub RIGHT: {stateMachine-> getSCI_Button ()-> raise_onoff (); tawg; } default: {tawg; }}}}

Kauj Ruam 5: Txuas Cov Khoom Ua Ke

Txoj haujlwm tseem ceeb siv peb ntu:

  • Lub Xeev Tshuab
  • Ib Timer
  • Tus Zaub Handler (raug lcd.print (…))

DigitalWatch* stateMachine = tshiab DigitalWatch (); CPPTimerInterface* timer_sct = tshiab CPPTimerInterface (); DisplayHandler* displayHandler = tshiab DisplayHandler ();

Lub xeev lub tshuab siv lub tshuab saib thiab tau txais lub sijhawm, uas yuav raug hloov kho tshiab los tswj cov xwm txheej sijhawm. Tom qab ntawd, lub xeev lub tshuab tau pib thiab nkag mus.

teeb tsa tsis muaj dab tsi () {stateMachine-> setSCI_Display_OCB (displayHandler); stateMachine-> setTimer (timer_sct); stateMachine-> init (); stateMachine-> nkag mus (); }Lub voj ua peb yam:

  • Tsa cov xwm txheej tawm tswv yim
  • Suav lub sijhawm dhau los thiab hloov kho lub sijhawm
  • Hu rau lub xeev tshuab

ntev tam sim no_time = 0; ntev kawg_cycle_time = 0; void loop () {nceEvents (); last_cycle_time = sijhawm tam sim no; current_time = millis (); timer_sct-> updateActiveTimer (stateMachine, tam sim no_time - kawg_cycle_time); stateMachine-> runCycle (); }

Kauj Ruam 6: Tau Piv Txwv

Qhov ntawd yog nws. Tej zaum, kuv tsis tau hais txog txhua yam ntawm kev siv, tab sis koj tuaj yeem saib qhov piv txwv lossis tawm lus tawm tswv yim.

Ntxiv qhov piv txwv rau kev khiav IDE nrog: Cov Ntaub Ntawv -> Tshiab -> Piv txwv -> YAKINDU Xeev Daim Qauv Piv Txwv -> Tom ntej -> Arduino -Digital Watch (C ++)

> Koj tuaj yeem rub tawm IDE ntawm no <<

Koj tuaj yeem pib nrog 30 hnub sim. Tom qab ntawv, koj yuav tsum tau txais daim ntawv tso cai, uas yog pub dawb rau kev siv tsis yog lag luam!

Pom zoo: