Cov txheej txheem:

Txuas Kev Ua Haujlwm thiab Arduino thiab Ua 7 Segment thiab Servo GUI Controller: 4 Cov Kauj Ruam
Txuas Kev Ua Haujlwm thiab Arduino thiab Ua 7 Segment thiab Servo GUI Controller: 4 Cov Kauj Ruam

Video: Txuas Kev Ua Haujlwm thiab Arduino thiab Ua 7 Segment thiab Servo GUI Controller: 4 Cov Kauj Ruam

Video: Txuas Kev Ua Haujlwm thiab Arduino thiab Ua 7 Segment thiab Servo GUI Controller: 4 Cov Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Hlis ntuj nqeg
Anonim
Kev Sib Txuas Ua Haujlwm thiab Arduino thiab Ua 7 Segment thiab Servo GUI Controller
Kev Sib Txuas Ua Haujlwm thiab Arduino thiab Ua 7 Segment thiab Servo GUI Controller

Rau qee qhov haujlwm koj yuav tsum tau siv Arduino raws li nws muab cov txheej txheem yooj yim ua qauv tab sis tso saib cov duab hauv kev saib xyuas ntawm Arduino tuaj yeem siv sijhawm ntev zoo nkauj thiab txawm tias nyuaj rau ua. Koj tuaj yeem tso saib cov kab ntawm Arduino Serial Monitor tab sis kab ntawv tsis yog tib yam uas koj xav tau los tso saib. Txhua yam khoom sib tham zoo li sliders, khawm, cov haujlwm nrog 2D, 3D, PDF, lossis SVG tso tawm thiab koj tseem tuaj yeem tsim cov duab ua kom yooj yim. Lub hom phiaj txheej txheem rau kev ua yog Java tab sis koj tuaj yeem hloov nws Android, p5.js, REPL, CoffeeScript thiab JavaScript. Hauv Cov Lus Qhia no txawm li cas los xij peb yuav siv hom Java programming.

Txhua cov ntsiab lus thiab cov cai kuj tseem muaj nyob ntawm kuv github nyob ntawm no.

Kauj ruam 1: Siv Processing.serial

Ua Txoj Cai

Thawj ob kab ntawm txoj cai yuav yog

ntshuam ua.serial.*; Serial myPort;

Nov yog thawj kab peb tab tom ntshuam lub tsev qiv ntawv - ua tiav thiab hauv kab thib ob peb tab tom tsim cov khoom ntawm chav kawm Serial npe myPort, koj tuaj yeem tso npe nws xijpeem koj nyiam ua raws cov cai ntawm kev teev npe tus cim.

Hauv kev ua peb muaj qhov tsis muaj teeb tsa () thiab kos tsis tau () qhov twg tsis muaj dab tsi yog hom rov ua haujlwm koj tuaj yeem hloov nws mus rau kev teeb tsa () thiab int kos () lossis lwm yam ntaub ntawv yam koj nyiam tab sis koj yuav tsum tau xa rov qab tus nqi uas muaj cov ntaub ntawv tib yam li hom ntaub ntawv koj siv ua ntej ua haujlwm.

hauv kev teeb tsa () peb sau cov lus peb xav tau kom ua tiav ib zaug thaum kos () peb sau cov lus peb xav tau kom ua ntau tus lej. Ob kab ntawm cov cai hais los saum no yuav tsum tau sau saum toj no tsis muaj teeb tsa () vim tias lawv yuav tsum muaj kev nkag mus thoob ntiaj teb.

Hauv qhov tsis muaj teeb tsa teeb tsa () peb yuav pib qhov khoom myPort.

void teeb tsa () {

loj (800, 800);

myPort = Serial tshiab (qhov no, "COM18", 9600);

}

Kab loj (800, 800); txhais qhov loj me ntawm lub vijtsam uas yog 800 pixels los ntawm 800 pixels.

Lo lus tseem ceeb tshiab hauv kab thib ob yog siv los khaws qhov chaw rau qhov khoom hauv kev nco, kev sib cav qhov no yog qhov siv sib txawv uas hais txog cov khoom tam sim no. Kev sib cav COM18 yog qhov chaw nres nkoj ntawm Arduino txuas nrog, peb xav tau qhov no raws li peb yuav tau thauj cov ntaub ntawv ntawm cov ntawv sib txuas. Tus lej 18 tej zaum yuav txawv hauv koj rooj plaub, koj tuaj yeem pom nws hauv Cov Cuab Yeej> Chaw Nres Nkoj hauv Arduino IDE thiab 9600 yog tus lej baud koj tuaj yeem hloov qhov no hauv ob qho Arduino thiab Kev Ua Haujlwm.

Kauj Ruam 2: Nkag Siab Txog Chav Kawm Serial

Tus tsim rau Serial

Serial (niam txiv, portName, baudRate, sib npaug, dataBits, stopBits)

Cov lus sib cav:

niam txiv: feem ntau siv "qhov no"

baudRate (int): 9600 yog lub neej ntawd

portName (Txoj hlua): lub npe chaw nres nkoj (COM1 yog lub neej ntawd)

parity (char): 'N' rau tsis muaj, 'E' rau txawm tias, 'O' rau khib, 'M' rau cim, 'S' rau qhov chaw ('N' yog lub neej ntawd)

dataBits (int): 8 yog lub neej ntawd

stopBits (ntab): 1.0, 1.5, lossis 2.0 (1.0 yog lub neej ntawd)

Txoj Kev Tseem Ceeb:

  1. myPort.available () - rov qab tus naj npawb ntawm bytes muaj.
  2. myPort.clear () - tshem tawm qhov tsis thiab tshem tawm txhua cov ntaub ntawv khaws cia rau ntawd.
  3. myPort.read () - Rov qab tus lej nruab nrab ntawm 0 thiab 255 rau tom ntej byte uas tos hauv qhov tsis.
  4. myPort.readString () - Rov qab txhua cov ntaub ntawv los ntawm qhov tsis raws li Txoj hlua lossis tsis muaj yog tias tsis muaj dab tsi muaj.
  5. myPort.write ("test") - Sau bytes, chars, ints, bytes , Cov hlua mus rau qhov chaw nres nkoj.
  6. myPort.stop () - Nthuav cov ntaub ntawv hais txog qhov chaw nres nkoj.

Kauj Ruam 3: Arduino Serial Class

Koj tsis tas yuav ntshuam Serial Class hauv Arduino ua ntej siv nws.

Hauv Arduino muaj 2 lub luag haujlwm hu ua teeb tsa () thiab lub voj () teeb tsa tsuas yog ib zaug tab sis lub voj ua haujlwm ntau zaus. Hauv Arduino tsis zoo li kev ua peb tsis tas yuav hais txog qhov chaw nres nkoj raws li cov lus sib cav ntawm pib () txoj kev raws li peb tau hais qhia qhov chaw nres nkoj thaum rub tawm daim duab hauv Arduino.

Yog li teeb tsa () yuav zoo li no:

void teeb tsa () {

Serial.begin (9600); // pib kev sib txuas lus

}

9600 ntawm no qhia meej txog tus nqi baud peb kuj tau hais txog qhov no hauv cov ntaub ntawv ua tiav. Txog kev sib txuas lus kom raug ob qho baud tus nqi yuav tsum yog sib npaug lossis koj tuaj yeem pom cov ntawv tso tawm raws li qee yam tsis txaus ntseeg.

Tam sim no cia saib lub voj () ib feem. Ib feem ntawm txoj cai no khiav ntau zaus. Yog tias peb xav nyeem qee cov ntaub ntawv los ntawm chaw nres nkoj peb yuav siv Serial.read () txoj kev. Txoj haujlwm no rov qab tsis muaj dab tsi yog tias tsis muaj cov ntaub ntawv yog li peb yuav hu rau txoj kev no tsuas yog thaum peb muaj qee cov ntaub ntawv muaj nyob hauv Serial stream.

Txhawm rau txheeb xyuas yog tias muaj qee cov ntaub ntawv muaj peb yuav siv Serial.available () txoj kev. Yog tias nws rov qab tus nqi ntau dua 0 - qee cov ntaub ntawv muaj.

Yog li lub voj () ib feem yuav zoo li no:

void voj () {

yog (Serial.available ()> 0) {// yog tias muaj qee cov ntaub ntawv muaj nyob hauv qhov chaw nres nkoj

char xeev = Serial.read (); // nyeem tus nqi

// yog nqe lus lossis hloov rooj plaub

}

}

Tam sim no peb tuaj yeem siv yog tus ntaiv lossis yog tias muaj ntau qhov ua tau tshwm sim peb tuaj yeem siv cov ntaub ntawv hloov pauv ib yam rau lub xeev sib txawv.

Kauj Ruam 4: Tsim GUI 7 Segment Controller

Tsim GUI 7 Segment Controller
Tsim GUI 7 Segment Controller
Tsim GUI 7 Segment Controller
Tsim GUI 7 Segment Controller
Tsim GUI 7 Segment Controller
Tsim GUI 7 Segment Controller

Cov ntaub ntawv raug txuas ntawm no. Nco tseg: Rau kev ua koj tseem yuav xav tau teeb tsa kev tswj hwm p5 lub tsev qiv ntawv uas kuv tau siv los tsim GUI sib tham sib khawm.

Tus lej lej

7 ntu (nyob rau hauv cov ntawv xaj) xa cov duab

a - tus pin 2

b - tus pin 3

c - tus pin 4

d - tus pin 5

e - tus pin 6

f - tus pin 7

g - tus pin 8

dp - tus pin 9

Txhua cov ntsiab lus thiab cov cai kuj tseem muaj nyob ntawm kuv github nyob ntawm no

Pom zoo: