Talaan ng mga Nilalaman:

聲納: 4 na Hakbang
聲納: 4 na Hakbang

Video: 聲納: 4 na Hakbang

Video: 聲納: 4 na Hakbang
Video: Моя работа наблюдать за лесом и здесь происходит что-то странное 2024, Nobyembre
Anonim
.
.

改作:

在 原本 聲納 的 基礎 下 加裝 了 喇叭 以 達到 警告 的 作用

材料: arduino uno, 超音波 感測器, 驅動 馬達, 喇叭

功能: 掃描 到 物品 時 加速 並 傳 述 到 電腦 , 物品 接近 10cm 時 喇叭 會 警告

Hakbang 1: Hakbang 1 電路圖

Hakbang 1 電路圖
Hakbang 1 電路圖

這 是 電路圖

Hakbang 2: Hakbang 2 寫 程式 (arduino)

Hakbang 2 寫 程式 (arduino)
Hakbang 2 寫 程式 (arduino)

create.arduino.cc/editor/dwdawdad/ef6b26a2-3f40-410d-9fdd-3413816090fe/preview

Hakbang 3: Hakbang 3 寫 程式 (pagpoproseso)

pagproseso ng pag-import.serial. *;

import java.awt.event. KeyEvent; i-import ang java.io. IOException;

Serial myPort; PFont orcFont; int iAngle; int iDistance; walang bisa ang pag-setup () {laki (1000, 500); makinis (); myPort = bagong Serial (ito, "COM7", 9600); myPort.clear (); myPort.bufferUntil ('\ n');

} walang bisa na gumuhit () {punan (98, 245, 31); noStroke (); punan (0, 4); tuwid (0, 0, lapad, 0.935 * taas); punan (98, 245, 31); DrawRadar (); DrawLine (); DrawObject (); DrawText (); } void serialEvent (Serial myPort) {subukan ang {String data = myPort.readStringUntil ('\ n'); kung (data == null) {bumalik; } int commaIndex = data.indexOf (","); Angulo ng string = data.substring (0, commaIndex); String distance = data.substring (commaIndex + 1, data.length () - 1); iAngle = StringToInt (anggulo); iDistance = StringToInt (distansya); } catch (RuntimeException e) {}} walang bisa DrawRadar () {pushMatrix (); isalin (lapad / 2, 0.926 * taas); noFill (); strokeWeight (2); stroke (98, 245, 31); // gumuhit ng mga linya ng arko DrawRadarArcLine (0.9375); DrawRadarArcLine (0.7300); DrawRadarArcLine (0.5210); DrawRadarArcLine (0.3130); // gumuhit ang mga linya ng anggulo panghuli int halfWidth = lapad / 2; linya (-halfWidth, 0, halfWidth, 0); para sa (int anggulo = 30; anggulo <= 150; anggulo + = 30) {DrawRadarAngledLine (anggulo); } linya (-halfWidth * cos (radians (30)), 0, halfWidth, 0); popMatrix (); } walang bisa DrawRadarArcLine (pangwakas na float coefficient) {arc (0, 0, koepisyent * lapad, coefficient * lapad, PI, TWO_PI); } walang bisa DrawRadarAngledLine (panghuling int anggulo) {linya (0, 0, (-width / 2) * cos (radians (anggulo)), (-width / 2) * sin (radians (anggulo))); } walang bisa DrawObject () {pushMatrix (); isalin (lapad / 2, 0.926 * taas); strokeWeight (9); stroke (255, 10, 10); int pixsDistance = int (iDistance * 0.020835 * taas); kung (iDistance 40? "Out of Range": "In Range"), 0.125 * width, 0.9723 * taas); teksto ("Angle:" + iAngle + "°", 0.52 * lapad, 0.9723 * taas); teksto ("Distansya:", 0.74 * lapad, 0.9723 * taas); kung (iDistance <40) {text ("" + iDistance + "cm", 0.775 * lapad, 0.9723 * taas); } textSize (25); punan (98, 245, 60); isalin (0.5006 * lapad + lapad / 2 * cos (radians (30)), 0.9093 * taas - lapad / 2 * sin (radians (30))); paikutin (-radians (-60)); teksto ("30 °", 0, 0); resetMatrix (); isalin (0.497 * lapad + lapad / 2 * cos (radians (60)), 0.9112 * taas - lapad / 2 * sin (radians (60))); paikutin (-radians (-30)); teksto ("60 °", 0, 0); resetMatrix (); isalin (0.493 * lapad + lapad / 2 * cos (radians (90)), 0.9167 * taas - lapad / 2 * sin (radians (90))); paikutin (radian (0)); teksto ("90 °", 0, 0); resetMatrix (); isalin (0.487 * lapad + lapad / 2 * cos (radians (120)), 0.92871 * taas - lapad / 2 * sin (radians (120))); paikutin (radians (-30)); teksto ("120 °", 0, 0); resetMatrix (); isalin (0.4896 * lapad + lapad / 2 * cos (radians (150)), 0.9426 * taas - lapad / 2 * sin (radians (150))); paikutin (radians (-60)); teksto ("150 °", 0, 0); popMatrix (); }

int StringToInt (String string) {int halaga = 0; para sa (int i = 0; i = '0' && string.charAt (i) <= '9') {halaga * = 10; halaga + = (string.charAt (i) - '0'); }} halaga ng pagbalik;}

Inirerekumendang: