Innehållsförteckning:

聲納: 4 steg
聲納: 4 steg

Video: 聲納: 4 steg

Video: 聲納: 4 steg
Video: Baleno AUDIO UPGRADE. #pioneer #steg #cardio #carmodification #pioneer5290 2024, Juli
Anonim
聲納
聲納

改作:

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

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

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

Steg 1: Steg 1 電路圖

Steg 1
Steg 1

這 是 電路圖

Steg 2: Steg 2 寫 程式 (arduino)

Steg 2 寫 程式 (arduino)
Steg 2 寫 程式 (arduino)

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

Steg 3: Steg 3 寫 程式 (bearbetning)

import bearbetning. serie.*;

importera java.awt.event. KeyEvent; importera java.io. IOException;

Seriell myPort; PFont orcFont; int iAngle; int iDistance; void setup () {size (1000, 500); slät(); myPort = new Serial (detta, "COM7", 9600); myPort.clear (); myPort.bufferUntil ('\ n');

} void draw () {fill (98, 245, 31); noStroke (); fyllning (0, 4); rekt (0, 0, bredd, 0,935 * höjd); fyllning (98, 245, 31); DrawRadar (); Rita linje(); DrawObject (); DrawText (); } void serialEvent (Serial myPort) {try {String data = myPort.readStringUntil ('\ n'); if (data == null) {return; } int commaIndex = data.indexOf (","); Strängvinkel = data.substring (0, commaIndex); Strängavstånd = data.substring (commaIndex+1, data.length ()-1); iAngle = StringToInt (vinkel); iDistance = StringToInt (avstånd); } catch (RuntimeException e) {}} void DrawRadar () {pushMatrix (); translate (bredd/2, 0,926 * höjd); noFill (); strokeWeight (2); stroke (98, 245, 31); // ritar båglinjerna DrawRadarArcLine (0.9375); DrawRadarArcLine (0,7300); DrawRadarArcLine (0,5210); DrawRadarArcLine (0,3130); // ritar vinkellinjerna slutliga int halfWidth = bredd/2; line (-halfWidth, 0, halfWidth, 0); för (int vinkel = 30; vinkel <= 150; vinkel+= 30) {DrawRadarAngledLine (vinkel); } line (-halfWidth * cos (radianer (30)), 0, halfWidth, 0); popMatrix (); } void DrawRadarArcLine (slutlig flottörskoefficient) {båge (0, 0, koefficient * bredd, koefficient * bredd, PI, TWO_PI); } void DrawRadarAngledLine (sista int vinkel) {rad (0, 0, (-bredd/2) * cos (radianer (vinkel)), (-bredd/2) * sin (radianer (vinkel))); } void DrawObject () {pushMatrix (); translate (bredd/2, 0,926 * höjd); strokeWeight (9); stroke (255, 10, 10); int pixsDistance = int (iDistance * 0.020835 * höjd); if (iDistance 40? "Out of Range": "In Range"), 0,125 * bredd, 0,9723 * höjd); text ("Vinkel:" + iAngle + "°", 0,52 * bredd, 0,9723 * höjd); text ("Avstånd:", 0,74 * bredd, 0,9723 * höjd); if (iDistance <40) {text ("" + iDistance + "cm", 0,775 * bredd, 0,9723 * höjd); } textSize (25); fyllning (98, 245, 60); translate (0,5006 * bredd + bredd/2 * cos (radianer (30)), 0,9093 * höjd - bredd/2 * sin (radianer (30))); rotera (-radianer (-60)); text ("30 °", 0, 0); resetMatrix (); translate (0,497 * bredd + bredd/2 * cos (radianer (60)), 0,9112 * höjd - bredd/2 * sin (radianer (60))); rotera (-radianer (-30)); text ("60 °", 0, 0); resetMatrix (); translate (0,493 * bredd + bredd/2 * cos (radianer (90)), 0,9167 * höjd - bredd/2 * sin (radianer (90))); rotera (radianer (0)); text ("90 °", 0, 0); resetMatrix (); translate (0,487 * bredd + bredd/2 * cos (radianer (120)), 0,92871 * höjd - bredd/2 * sin (radianer (120))); rotera (radianer (-30)); text ("120 °", 0, 0); resetMatrix (); translate (0,4896 * bredd + bredd/2 * cos (radianer (150)), 0,9426 * höjd - bredd/2 * sin (radianer (150))); rotera (radianer (-60)); text ("150 °", 0, 0); popMatrix (); }

int StringToInt (String string) {int värde = 0; för (int i = 0; i = '0' && string.charAt (i) <= '9') {värde *= 10; värde += (string.charAt (i) - '0'); }} returvärde;}

Rekommenderad: