Cov txheej txheem:

Arduino Processing Graphic Transition: 5 Kauj Ruam
Arduino Processing Graphic Transition: 5 Kauj Ruam

Video: Arduino Processing Graphic Transition: 5 Kauj Ruam

Video: Arduino Processing Graphic Transition: 5 Kauj Ruam
Video: Arduino - Processing: serial data 2024, Kaum ib hlis
Anonim
Arduino Ua Cov Duab Hloov
Arduino Ua Cov Duab Hloov

Nyob zoo, txoj haujlwm no yog ua kom pom cov duab los ntawm qhov pom tsis tau uas tuaj yeem hnov los ntawm cov ntsuas. Hauv qhov no, Kuv tau siv lub ntsuas hluav taws xob ultrasonic thiab lub tshuab ntsuas hluav taws xob los tswj lub teeb thiab nrug deb. Kuv pom nws los ntawm kev ua qhov hloov pauv los ntawm lub sensor ua qhov hloov pauv hauv kev ua. Tom qab ntawd kuv txuas Arduino thiab Ua Haujlwm los tswj Arduino nrog Kev Ua Haujlwm. Yog li, cov duab hauv Kev Ua Haujlwm yuav siv qhov sib txawv los ntawm Arduino sensor.

Kauj Ruam 1: Kauj Ruam 1: Npaj Tshooj

Kauj Ruam 1: Npaj Tshooj
Kauj Ruam 1: Npaj Tshooj

Nov yog cov khoom uas koj yuav xav tau los ua qhov haujlwm no:

-10k OHM

- Ultrasonic ntsuas

- Tus kws yees duab

- Arduino Ib

- 7 kab

Kauj Ruam 2: Kauj Ruam 2: Txuas Txhua Lub Cheeb Tsam

Kauj Ruam 2: Txuas Txhua Lub Cheeb Tsam
Kauj Ruam 2: Txuas Txhua Lub Cheeb Tsam

Tus photoresistor thiab Ultrasonic sensor xav tau qhov chaw kom pom tseeb. Txuag qee qhov chaw thiab xav txog lub teeb rau photoresistor.

Kauj Ruam 3: Kauj Ruam 3: Code

Kauj ruam 3: Code!
Kauj ruam 3: Code!

*Ntxiv tsev qiv ntawv hauv Arduino thiab Ua Haujlwm.

Arduino: tshawb "ping tshiab" hauv lub tsev qiv ntawv

Ua: tshawb nrhiav "serial" hauv lub tsev qiv ntawv

Code rau Arduino:

#suav nrog

#define TRIGGER_PIN 12 #define ECHO_PIN 11 #define MAX_DISTANCE 200

NewPing sonar (TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

int lightSensorPin = A0; int analogValue = 0;

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); }

lub voj void () {int Value1 = sonar.ping_cm (); Value1 = daim ntawv qhia (Tus nqi 1, 1, 60, 500, 24); Value1 = txwv (Value1, 24, 500);

analogValue = analogRead (lightSensorPin); int cVal1 = daim ntawv qhia (analogValue, 200, 600, 249, 100);

int cVal2 = daim ntawv qhia (analogValue, 200, 600, 247, 97);

int cVal3 = daim ntawv qhia (analogValue, 200, 600, 243, 101);

int cVal4 = daim ntawv qhia (analogValue, 200, 600, 243, 150);

ncua (50);

Serial.print (Tus nqi 1); Serial.print (",");

Serial.print (cVal1); Serial.print (","); Serial.print (cVal2); Serial.print (","); Serial.print (cVal3); Serial.print (","); Serial.print (cVal4); Serial.print (",");

Serial.println (); }

Txoj Cai Rau Ua:

// chav kawm: (theem pib) //

ntshuam ua.serial.*;

int kawg = 10; Txoj hlua; Serial chaw nres nkoj;

cov pcount = 350; Particle p = tshiab Particle [pcount]; int kab pheeb ces kaum; int ib = 100;

void teeb () {chaw nres nkoj = Tshiab Serial (qhov no, "/dev/cu.usbmodem141101"); chaw.clear (); serial = port.readStringUntil (kawg); serial = tsis muaj; rau (int i = 0; i

ntab ntab = 0;

kos tsis muaj dabtsis () {thaum (port.available ()> 0) {serial = port.readStringUntil (kawg); ncua (10); } yog (serial! = null) {String a = split (serial, ','); println (ib [0]); println (ib [1]); println (ib [2]); println (ib [3]); println (ib [4]); int result1 = Integer.parseInt (a [0]); System.out.println (result1); frameRate (tshwm sim 1); int tshwm sim 2 = Integer.parseInt (a [1]); System.out.println (result2); int result3 = Integer.parseInt (a [2]); System.out.println (result3); int result4 = Integer.parseInt (a [3]); System.out.println (result4); int result5 = Integer.parseInt (a [4]); System.out.println (result5); keeb kwm yav dhau los (tshwm sim 2, tshwm sim 3, tshwm sim 4); txhais lus (dav/2, qhov siab); kev sib hloov- = 0.0005; tig (tig); rau (int i = 0; kuv kab pheeb ces kaum) {p = Particle tshiab (); }}}}

// chav kawm: Particle //

chav kawm Particle {ntab n; ploj r; ploj o; ploj c; ploj d; tus l; Particle () {l = 100; n = random (3, dav/2); r = random (0.10, TWO_PI); o = random (1, random (1, dav/n)); c = random (180, 228); d = random (160, 208); } tsis muaj dab tsi kos () {l ++; pushMatrix (); tig (r); txhais (drawDist (), 1); ellipse (10, 10, dav/o/4, dav/o/4); popMatrix (); o- = 0.06; } ntab drawDist () {rov atan (n/o)*dav/HALF_PI; }}

Kauj Ruam 4: Kauj Ruam 4: Txuas thiab Xeem

Kauj Ruam 4: Txuas thiab Xeem
Kauj Ruam 4: Txuas thiab Xeem

Kauj Ruam 5: Kauj Ruam 5: Pom Qhov Tseeb

Kauj Ruam 5: Pom Qhov Tseeb!
Kauj Ruam 5: Pom Qhov Tseeb!

Qhov nrawm ntawm lub pob txav mus yuav nrawm dua thaum muaj ib yam dab tsi los ze zog rau lub ntsuas hluav taws xob ultrasonic. Ntxiv rau, lub teeb tswj nrog photoresistor yuav tshwm nyob rau hauv kev ua tom qab tsaus ntuj.

Pom zoo: