Cov txheej txheem:

Arduino HMI Siv Lub Xeev Machine: 9 Kauj Ruam
Arduino HMI Siv Lub Xeev Machine: 9 Kauj Ruam

Video: Arduino HMI Siv Lub Xeev Machine: 9 Kauj Ruam

Video: Arduino HMI Siv Lub Xeev Machine: 9 Kauj Ruam
Video: MECHANIC ITOUCH DM DIGITAL MULTIMETER TOUCH SCREEN (TONY VISION CHENNAI) 2024, Kaum ib hlis
Anonim
Arduino HMI Siv Lub Xeev Machine
Arduino HMI Siv Lub Xeev Machine

Hauv Cov Lus Qhia no, Kuv yuav qhia koj yuav siv YAKINDU Daim Ntawv Qhia Xeev Li Cas kom paub qhov yooj yim thiab nthuav dav HMI los ntawm kev siv 16x2 LCD Keypad Shield rau Arduino.

Finite State Machines (FSM) yog tus qauv tsim muaj zog los tsim cov Tib Neeg Lub Tshuab Sib Txuas (HMI). Raws li kev ua haujlwm ntawm HMI tuaj yeem nce ntxiv, nws muaj txiaj ntsig zoo los siv cov qauv tsim qauv zoo li lub xeev cov tshuab.

Qhov ua piv txwv tiav yog kos rau hauv YAKINDU Statechart Cov Cuab Yeej. Ib qho ntxiv, Eclipse C ++ IDE rau Arduino Plugin tau siv los ua ke thiab ua rau pom hauv IDE.

Cov Lus Qhia luv luv ntawm YAKINDU Cov Ntawv Qhia Hauv Xeev

Nrog rau cov cuab yeej no, nws muaj peev xwm los tsim cov tshuab hauv xeev. Nws tso cai rau tus neeg siv tsim C, C ++ lossis Java code los ntawm lub xeev tshuab. Nrog rau txoj hauv kev no, tus qauv tuaj yeem hloov pauv lossis nthuav dav thiab tus neeg siv tuaj yeem yooj yim rov tsim cov cai thiab tsis tas yuav sau qhov chaws yooj yim.

Khoom siv

Qhov:

  • Arduino (Ua, Mega)
  • USB Cable
  • 16x2 LCD Keypad Shield

Cov Cuab Yeej:

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

Kauj ruam 1: Kho vajtse

Image
Image

LCD Keypad Shield tuaj yeem yooj yim ntsaws rau hauv Arduino. Nws muaj 16x2 LCD Zaub thiab ntxiv tau rau rau lub khawm:

  • Sab laug
  • Txoj cai
  • Saum
  • Nqis
  • Xaiv
  • (Pib dua)

Pom tseeb, tsib ntawm lawv tuaj yeem siv tau. Cov yuam sij tau xaim mus rau qhov sib faib hluav taws xob thiab kuaj pom los ntawm kev siv Pin A0 nyob ntawm qhov hluav taws xob. Kuv tau siv software debouncing los txheeb xyuas lawv kom raug.

Kauj Ruam 2: Txheeb Xyuas Nws Yuav Tsum Ua Haujlwm Li Cas

HMI Tswj
HMI Tswj

Daim ntawv thov yuav tsum muaj peev xwm ua peb yam.

  1. Kuaj Lub Xeev Ntawm no Kuv xav siv cov nyees khawm los ntawm tsib lub xeev: Sab Saum, Nruab Nrab, Hauv Qab, Sab laug thiab Txoj Cai
  2. Stopwatch Lub moos yooj yim, uas tuaj yeem pib, nres thiab rov pib dua. Nws yuav tsum tau nce ntxiv txhua 100 milliseconds
  3. CounterQhov thib peb muaj qhov yooj yim nce/nqis txee. Nws yuav tsum muaj peev xwm suav tus lej zoo thiab nws yuav tsum rov teeb tsa tau

Cov ntawv qhia zaub mov nquag (lossis lub xeev) yuav tshwm rau ntawm 16x2 LCD ntawm kab saum toj kawg nkaus. Daim ntawv thov (Xeev, Timer lossis Counter) yuav muab tso rau ntawm kab hauv qab. Txog kev taw qhia, yuav tsum siv lub pob nyem sab laug thiab sab xis.

Kauj Ruam 3: cuam tshuam nrog Lub Xeev Tshuab

Cov nyees khawm yuav raug nthuav tawm thiab txuas mus rau lub xeev tshuab. Lawv tuaj yeem siv tau raws li cov xwm txheej hauv lub xeev tshuab. Ib qho ntxiv, cov haujlwm tau piav qhia kom pom cov ntawv qhia zaub mov tam sim no. Thiab tsawg kawg ob qhov sib txawv, ib qho rau lub sijhawm thiab ib qho rau lub txee, tau hais tseg.

interface:

// cov nyees khawm raws li cov xwm txheej hauv qhov xwm txheej sab xis hauv qhov tshwm sim hauv qhov xwm txheej hauv qhov xwm txheej xaiv // tso saib HMI cov txiaj ntsig tshwj xeeb ua haujlwm displayLCDString (tus nqi: hlua, ntev: integer, txoj haujlwm: integer) ua haujlwm displayLCDInteger (tus nqi: integer, txoj haujlwm: integer) lag luam clearLCDRow (txoj hauj lwm: integer) sab hauv: // hloov pauv rau cia var cnt: integer var timeCnt: integer = 0

Tom qab tsim cov cai C ++, cov xwm txheej yuav tsum tau nthuav tawm thiab txuas mus rau lub interface. Tsab ntawv xov xwm no qhia pom yuav ua li cas.

Thaum xub thawj, cov nyees khawm yuav raug txhais:

#define NONE 0 #txhais SELECT 1 #define LEFT 2 #define DOWN 3 #define UP 4 #define RIGHT 5

Tom qab ntawd muaj lub luag haujlwm txhais los nyeem lub pob. Tus nqi yuav txawv, nyob ntawm tus tsim LCD Shield.

zoo li qub int readButton () {int tshwm sim = 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; }

Thaum kawg, cov nyees khawm yuav raug nthuav tawm. Kuv tau ua tiav zoo nrog 80 ms. Thaum lub pob yuav raug tso tawm, nws yuav nce raws li qhov tshwm sim.

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-> raise_select (); tawg; } rooj LEFT: {stateMachine-> lift_left (); tawg; } case DOWN: {stateMachine-> raise_down (); tawg; } rooj plaub UP: {stateMachine-> raise_up (); tawg; } rooj plaub RIGHT: {stateMachine-> raise_right (); tawg; } default: {tawg; }}}}

Kauj Ruam 4: HMI Tswj

Txhua lub xeev tau siv rau ib feem ntawm cov ntawv qhia zaub mov. Muaj cov xeev me, qhov twg daim ntawv thov - piv txwv li lub moos nres - yuav ua tiav.

Nrog rau qhov kev tsim no, lub interface tuaj yeem nthuav dav tau yooj yim. Cov ntawv ntxiv tuaj yeem yooj yim ntxiv los ntawm kev siv tib tus qauv tsim. Nyeem tus nqi ntawm lub ntsuas thiab pom nws hauv kab ntawv thib plaub yam tsis muaj teeb meem loj.

Txog tam sim no, tsuas yog sab laug thiab sab xis yog siv los ua kev tswj hwm. Tab sis nce thiab nqis kuj tseem tuaj yeem siv ua qhov txuas ntxiv hauv cov ntawv qhia zaub mov tseem ceeb. Tsuas yog khawm xaiv yuav raug siv los nkag rau cov khoom tshwj xeeb.

Kauj Ruam 5: Tuav Xeev

Kov Xeev
Kov Xeev

Lub xeev cov ntawv qhia zaub mov tsuas yog siv ua piv txwv ntxiv ntawm kev taw qhia. Kev siv nce, nqis, sab xis lossis sab laug tso cai hloov pauv ntawm cov xeev. Lub xeev tam sim no ib txwm yuav luam tawm ntawm kab thib ob ntawm LCD Zaub.

Kauj ruam 6: Stopwatch

Stopwatch
Stopwatch

Lub stopwatch yog qhov yooj yim heev. Thaum xub thawj, tus nqi timer yuav rov pib dua. Lub sijhawm tuaj yeem pib los ntawm kev siv khawm sab laug thiab toggled los ntawm kev siv sab laug thiab sab xis. Siv nce lossis nqis rov ua timer. Lub sijhawm tuaj yeem tuaj yeem teeb tsa rov qab rau xoom los ntawm kev siv khawm xaiv ob zaug - tawm hauv cov ntawv qhia zaub mov thiab nkag mus rau nws ib zaug ntxiv, raws li lub sijhawm yuav raug teem rau xoom los ntawm kev nkag mus rau lub tswb.

Kauj Ruam 7: Txee

Counter
Counter

Tsawg kawg, muaj lub txee siv. Nkag mus rau lub xeev txee rov pib dua lub txee. Nws tuaj yeem pib los ntawm kev siv ib lub pob nyem, tshwj tsis yog xaiv lub pob. Nws tau ua raws li qhov yooj yim nce/nqis txee, uas tus nqi tsis tuaj yeem me dua 0.

Kauj Ruam 8: Simulation

Kauj Ruam 9: Tau Piv Txwv

Koj tuaj yeem rub tawm IDE ntawm no: YAKINDU Statechart Cov Cuab Yeej

Thaum koj tau rub tawm IDE, koj pom qhov piv txwv ntawm File -> N ew -> Piv txwv

Nws siv dawb rau cov nyiam ua haujlwm, tab sis koj kuj tuaj yeem siv 30 hnub sim.

Pom zoo: