Orodha ya maudhui:

4: 4 Hatua
4: 4 Hatua

Video: 4: 4 Hatua

Video: 4: 4 Hatua
Video: Шалаш за 1$ vs 1000$ *Бюджетный Челлендж* 2024, Novemba
Anonim
聲納
聲納

: Https: //aboutsciences.com/blog/arduino-radar-using…

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

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

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

Hatua ya 1: Hatua ya 1 電路圖

Hatua ya 1 電路圖
Hatua ya 1 電路圖

這 是 電路圖

Hatua ya 2: Hatua ya 2 程式 程式 (arduino)

Hatua ya 2 寫 程式 (arduino)
Hatua ya 2 寫 程式 (arduino)

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

Hatua ya 3: Hatua ya 3 程式 程式 (usindikaji)

usindikaji wa kuagiza.serial. *;

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

Serial myPort; PFont orcFont; int iAngle; int iDistance; usanidi batili () {saizi (1000, 500); Nyororo(); myPort = mpya Serial (hii, "COM7", 9600); safiPort.clear (); myPort.bufferUntil ('\ n');

} sare batili () {kujaza (98, 245, 31); Stroke (); jaza (0, 4); rect (0, 0, upana, 0.935 * urefu); jaza (98, 245, 31); DrawRadar (); DrawLine (); DrawObject (); DrawText (); } batili serialEvent (Serial myPort) {jaribu {String data = myPort.readStringUntil ('\ n'); ikiwa (data == null) {kurudi; } int commaIndex = data.indexOf (","); Angu ya kamba = data.substring (0, commaIndex); Kamba ya umbali = data.substring (commaIndex + 1, data.length () - 1); iAngle = StringToInt (pembe); iDistance = StringToInt (umbali); } kukamata (RuntimeException e) {}} batili DrawRadar () {pushMatrix (); kutafsiri (upana / 2, 0.926 * urefu); noFill (); kiharusi Uzito (2); kiharusi (98, 245, 31); // huchota mistari ya arc DrawRadarArcLine (0.9375); DrawRadarArcLine (0.7300); DrawRadarArcLine (0.5210); DrawRadarArcLine (0.3130); // huchota mistari ya pembe mwisho int nusu Upana = upana / 2; mstari (upana wa nusu, 0, upana wa nusu, 0); kwa (int angle = 30; angle <= 150; angle + = 30) {DrawRadarAngledLine (angle); } laini (upana wa nusu * cos (radians (30)), 0, nusu upana, 0); popMatrix (); } batili DrawRadarArcLine (mgawo wa mwisho wa kuelea) {arc (0, 0, mgawo wa upana *, upana wa mgawo *, PI, TWO_PI); } batili DrawRadarAngledLine (mwisho int angle) {line (0, 0, (-width / 2) * cos (radians (angle)), (-width / 2) * dhambi (radians (angle))); } batili DrawObject () {pushMatrix (); kutafsiri (upana / 2, 0.926 * urefu); kiharusi Uzito (9); kiharusi (255, 10, 10); int pixsDistance = int (iDistance * 0.020835 * urefu); ikiwa (iDistance 40? "Kati ya Masafa": "Kwa Masafa"), 0.125 * upana, 0.9723 * urefu); maandishi ("Angle:" + iAngle + "°", 0.52 * upana, 0.9723 * urefu); maandishi ("Umbali:", 0.74 * upana, 0.9723 * urefu); ikiwa (iDistance <40) {maandishi ("" + iDistance + "cm", 0.775 * upana, 0.9723 * urefu); } maandishiSize (25); jaza (98, 245, 60); kutafsiri (0.5006 * upana + upana / 2 * cos (radians (30)), 0.9093 * urefu - upana / 2 * dhambi (radians (30))); zungusha (-radians (-60)); maandishi ("30 °", 0, 0); resetMatrix (); kutafsiri (0.497 * upana + upana / 2 * cos (radians (60)), 0.9112 * urefu - upana / 2 * dhambi (radians (60))); zungusha (-radians (-30)); maandishi ("60 °", 0, 0); resetMatrix (); kutafsiri (0.493 * upana + upana / 2 * cos (radians (90)), 0.9167 * urefu - upana / 2 * dhambi (radians (90))); zunguka (radians (0)); maandishi ("90 °", 0, 0); resetMatrix (); kutafsiri (0.487 * upana + upana / 2 * cos (radians (120)), 0.92871 * urefu - upana / 2 * dhambi (radians (120))); zunguka (radians (-30)); maandishi ("120 °", 0, 0); resetMatrix (); kutafsiri (0.4896 * upana + upana / 2 * cos (radians (150)), 0.9426 * urefu - upana / 2 * dhambi (radians (150))); zunguka (radians (-60)); maandishi ("150 °", 0, 0); popMatrix (); }

int StringToInt (Kamba ya kamba) {int value = 0; kwa (int i = 0; i = '0' && string.charAt (i) <= '9') {value * = 10; thamani + = (kamba.charAt (i) - '0'); }} thamani ya kurudisha;}

Ilipendekeza: