91欧美超碰AV自拍|国产成年人性爱视频免费看|亚洲 日韩 欧美一厂二区入|人人看人人爽人人操aV|丝袜美腿视频一区二区在线看|人人操人人爽人人爱|婷婷五月天超碰|97色色欧美亚州A√|另类A√无码精品一级av|欧美特级日韩特级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

Arduino單位轉(zhuǎn)換器的制作

454398 ? 來源:網(wǎng)絡(luò)整理 ? 作者:佚名 ? 2019-11-08 14:15 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

第1步:成分:

電子產(chǎn)品

Arduino

面包板

LCD *

2個50k電位器

150歐姆電阻

跳線,以及成噸的跳線!

如果您不想使用LCD,則必須使用串行監(jiān)視器。無論在哪里看到lcd.print,只需將其更改為Serial.print即可。而不是lcd.begin更改為Serial.begin(9600);。

步驟2:LCD

Arduino單位轉(zhuǎn)換器的制作

所以我要做的第一件事是去Arduino網(wǎng)站,看看如何連接我的LCD屏幕。我已附上原理圖。

要使LCD上的背光引腳(K)接地,并通過150歐姆電阻將LCD上的引腳(A)連接到Arduino上的引腳10。

了解如何使用此LCD屏幕,因此我在此提供了一些信息。 Arduino已經(jīng)為LCD提供了一個庫,因此我們需要包含它。為此,我們可以在設(shè)置之前輸入代碼, #include ?,F(xiàn)在包括我們的LCD庫。接下來要做的是告訴Arduino我們將哪些引腳連接到LCD。為此,請在設(shè)置功能 LiquidCrystal lcd(12,11,5,5,4,3,2);之前鍵入此代碼; 這些是Arduino通過PIN將數(shù)據(jù)發(fā)送到LCD的引腳。

所以這是到目前為止的草圖。 #include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

現(xiàn)在,讓我們學習一些有關(guān)使用LCD功能的知識。

lcd.begin(16,2);//這是用于設(shè)置列數(shù)和行數(shù)。如果您查看圖片2和3,則可以看到列的數(shù)量,而在圖片3中,可以看到行的數(shù)量。

lcd.print(“”);//這就是我們在屏幕上打印文本的方式。您的文字放在引號之間。引號是必需的。

lcd.clear();//這就是我們清除屏幕上所有文本的方式。

lcd.setCursor(0,1);//這就是我們將文本放在第二行的方式。

因此,請充分利用所有這些。連接屏幕,然后輸入此代碼。 #include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10

void setup()

{

lcd.begin(16,2);

digitalWrite(lcdbl, HIGH); // turning on the backlight

pinMode(lcdbl, OUTPUT); // set pin 11 to output

lcd.print(“I‘m cool!”);

}

void loop()

{

}

如果將其復制,粘貼到草圖中并上傳到板上,則應該會看到LCD亮起,并且出現(xiàn)文本“我很酷”。

我所看到的只是白色方塊,或者屏幕只是藍色(或您的LCD背光顏色)!

屏幕不亮!

解決方案:

將電位器一直轉(zhuǎn)到一側(cè),然后再轉(zhuǎn)到另一側(cè)。您應該看到文本出現(xiàn)。如果是這樣,請慢慢調(diào)整電位器,直到文本清除為止

確保所有連接正確。

確保將[lcdbl]設(shè)置為[OUTPUT]

現(xiàn)在,讓我們在底部一行添加一些文本。如果您還記得,我們需要偏移光標。通過鍵入lcd.setCursor(0,1);

請參閱修改后的代碼。 #include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10

void setup()

{

lcd.begin(16,2);

digitalWrite(lcdbl, HIGH);

pinMode(lcdbl, OUTPUT); // set pin 11 to output

lcd.print(“I’m cool!”);

lcd.setCursor(0,1); // set the text below to the second row

lcd.print(“In my dreams :(”);

}

void loop()

{

}

將此上傳到您的Arduino,看看會發(fā)生什么!

步驟3:連接第二個電位計

好吧,既然我們知道如何使用LCD,我們需要移動一個。第一步是連接第二個電位器。我們將兩個外部引腳連接到5v和GND,將中間引腳連接到Arduino引腳A0。

現(xiàn)在,我們當然需要使用Arduino進行設(shè)置。方法如下:

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a value (0-500);

讓我們更詳細地檢查這一行

int sensorValue = AnalogRead(A0)-我們將單詞‘sensorValue’設(shè)置為相等從引腳A0到模擬讀數(shù)。

浮點英寸= sensorValue *(500/1023.0); -我們將“英寸”一詞設(shè)置為等于我們的新讀數(shù)(0-500);如果您想要鍋調(diào)整腳的數(shù)量,可以將“ inches”(英寸)改為“ feet”(英尺)。

基本上,所有這些操作都告訴Arduino我們在引腳A0處有一個模擬讀數(shù)(從0-1023開始)。下一行用于將讀數(shù)(0-1023)轉(zhuǎn)換為我們喜歡的值,在這種情況下為500。我們需要將其放入循環(huán)塊中。到目前為止,這就是我們的代碼。

#include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10

void setup()

{

lcd.begin(16,2);

digitalWrite(lcdbl, HIGH);

pinMode(lcdbl, OUTPUT); // set pin 11 to output

}

void loop()

{

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023);

}

注意,我已經(jīng)擺脫了測試文本。我真的不認為我們會需要它:D。

步驟4:將底池值打印到LCD

我們需要告訴LCD打印一些東西,但是我們告訴它打印什么呢?我們要做的是鍵入 lcd.print( inches );現(xiàn)在為什么要英寸?好吧,請記住,我們將A0的模擬讀取命名為“英寸”,這就是我們應該輸入的內(nèi)容。請勿使用引號,因為引號僅用于放置文本。

#include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10

void setup()

{

lcd.begin(16,2);

digitalWrite(lcdbl, HIGH);

pinMode(lcdbl, OUTPUT); // set pin 11 to output

}

void loop()

{

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

lcd.print(inches);

}

因此,我們應該將讀數(shù)打印到LCD上!!因此,上傳代碼!但是,哦,不!整個屏幕上只是一大堆數(shù)字!為什么會這樣呢?仔細研究我們的代碼,我們看到此函數(shù)在循環(huán)部分中,因此其中的任何操作都將不斷重復。如果您注意到,沒有延遲或中斷,那么它將瘋狂地打印到我們的LCD上。這就是我們要解決的難題。我們將使用一個簡單的lcd.clear函數(shù)來清除屏幕,然后添加一個小的延遲?,F(xiàn)在它將打印英寸數(shù),等待一秒鐘,清除屏幕,然后重復上述步驟直到下一次重置。因此,我們的新代碼將如下所示。

#include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10

void setup()

{

lcd.begin(16,2);

digitalWrite(lcdbl, HIGH);

pinMode(lcdbl, OUTPUT); // set pin 11 to output

}

void loop()

{

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

lcd.print(inches);

delay(100);

lcd.clear();

}

因此,現(xiàn)在要做的是打印數(shù)量AnalogRead值(英寸),將其在LCD上放置100毫秒,清除它,然后重新開始?,F(xiàn)在,您應該可以轉(zhuǎn)動電位計,并實時了解最新情況?,F(xiàn)在將旋鈕調(diào)大,例如350。

第5步:數(shù)學!

現(xiàn)在是時候做一點數(shù)學了。我希望我的Arduino告訴我有幾英寸,然后讓屏幕變黑,然后告訴我有幾英尺。為了找出以英寸為單位的英尺,我們需要除以12。因此,這就是我們要設(shè)置代碼行的方式。

feet = (inches / 12);

如果我們想將英寸轉(zhuǎn)換為厘米,我們可以這樣做:

centimeters = (inches * 2.54);

所以我們的代碼看起來像這樣。注意,我已將草圖插入 int英尺; 如果您不這樣做,則會收到一條錯誤消息,如圖所示。您必須定義什么是“腳”。下面的代碼應執(zhí)行以下操作:

顯示英寸數(shù),其后帶有單詞“ inchs”。

清除屏幕

在其后顯示帶有“ foot”字樣的英尺數(shù)。

如果像我一樣將英寸保留為350英寸步驟4,每英尺的數(shù)量應為29。

#include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10

int feet;

int wait = 3000; // assign the word “wait” to 3000 milliseconds

void setup()

{

lcd.begin(16,2);

digitalWrite(lcdbl, HIGH);

pinMode(lcdbl, OUTPUT); // set pin 11 to output

}

void loop()

{

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

delay(1000);

lcd.print(inches);

lcd.print(“ inches:”);

delay(wait);

lcd.clear();

delay(1000);

feet = (inches / 12); // conversion from feet to inches Here this is telling Arduino that

// feet is equal to inches divided by 12

lcd.print(feet);

lcd.print(“ feet:”);

delay(wait);

lcd.clear();

delay(1000);

}

步驟6:更多編程。 。

到目前為止,草圖的問題是無法通過實時更新更改英寸。上面的代碼只會打印一次英寸數(shù)?,F(xiàn)在,這對于英尺的數(shù)量或我們要轉(zhuǎn)換的尺寸都可以,但是對于我們的變量,這太可怕了!我們甚至無法選擇想要的英寸數(shù)!為了解決這個問題,我使用了一個小程序?qū)?shù)據(jù)(英寸)打印到LCD上并將其清除了50次,這使我根據(jù)鍋的轉(zhuǎn)動次數(shù)有了一個相當不錯的數(shù)字變化。下面的代碼將塊之間的所有代碼重復50次,并且將延遲設(shè)置為100,即大約5秒(50 * 100)。

for(int i=0; i《50; ++i)

{

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

lcd.print(“Adjust the knob”);

lcd.setCursor(0,1);

lcd.print(inches);

delay(100);

lcd.clear();

}

在上面的草圖中,僅看到一次英寸數(shù),它將重復多次,使您可以在更新時看到它(與轉(zhuǎn)動第二個底池一致)。

上傳以下代碼應執(zhí)行以下操作:

“歡迎使用單位轉(zhuǎn)換器!”

“調(diào)整旋鈕”,使其下方具有英寸數(shù)。這將顯示5秒鐘。開鍋!

打印英寸數(shù)

清除

打印英寸數(shù)

返回“調(diào)整旋鈕”

#include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int lcdbl = 10; // lcdbl=LCD Backlight: hooking up the lcdbacklight to pin 10

int feet;

int wait = 3000; // assign the word “wait” to 3000 milliseconds

void setup()

{

lcd.begin(16,2);

digitalWrite(lcdbl, HIGH);

pinMode(lcdbl, OUTPUT); // set pin 11 to output

lcd.print(“Welcome to the”);

lcd.setCursor(0,1); // the cursor is like the rows on your LCD. After this, it will print

// the text on the bottom line of your LCD screen.

lcd.print(“unit converter!”);

delay(wait); /* if you look here, intead of the usual time in milliseconds

it says “wait”。 If we look what “wait” is, at the beginning of the code,

we see that “wait” is assigned to 3000 milliseconds, so whenever I type in

delay(wait); it wil have a delay of 3000 milliseconds, or 3 seconds. */

lcd.clear();

delay(1000);

}

void loop()

{

for(int i=0; i《50; ++i)

{

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

lcd.print(“Adjust the knob”);

lcd.setCursor(0,1);

lcd.print(inches);

delay(100);

lcd.clear();

}

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

delay(1000);

lcd.print(inches);

lcd.print(“ inches:”);

delay(wait);

lcd.clear();

delay(1000);

feet = (inches / 12); // conversion from feet to inches Here this is telling Arduino that

// feet is equal to inches divided by 12

lcd.print(feet);

lcd.print(“ feet:”);

delay(wait);

lcd.clear();

delay(1000);

}

步驟7:添加更多數(shù)學!

這是Arduino將英寸的長度轉(zhuǎn)換為英尺,碼,厘米和米。然后返回“調(diào)整旋鈕”。繼續(xù)閱讀整個代碼,并確保您理解所有內(nèi)容。

我將英尺,碼,厘米和米的換算值添加了。不要忘記在草圖的開頭定義這些內(nèi)容。

yards = (feet / 3);

centimeters = (inches * 2.54);

meters = (centimeters * 100);

Iint feet;

int yards;

long inches;

long centimeters;

long meters;

int lcdbl = 10; // set the backlight pin to pin 10

int wait = 3000; // assign the word “wait” to 3000 milliseconds

#include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()

{

lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.

pinMode(lcdbl, OUTPUT); // setting the lcdbl (lcd backlight) pin to an OUPUT

analogWrite(lcdbl, 255); // set the backlight brightness to on

lcd.print(“Welcome to the”);

lcd.setCursor(0,1); // the cursor is like the rows on your LCD. After this, it will print

// the text on the bottom line of your LCD screen.

lcd.print(“unit converter!”);

delay(wait); /* if you look here, intead of the usual time in milliseconds

it says “wait”。 If we look what “wait” is, at the beginning of the code,

we see that “wait” is assigned to 3000 milliseconds, so whenever I type in

delay(wait); it wil have a delay of 3000 milliseconds, or 3 seconds. */

lcd.clear();

delay(1000);

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (100 / 1023.0); // Convert the analog reading

}

// the loop routine runs over and over again forever:

void loop()

{

for(int i=0; i《50; ++i)

{

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

lcd.print(“Adjust the knob”);

lcd.setCursor(0,1);

lcd.print(inches);

delay(100);

lcd.clear();

}

int sensorValue = analogRead(A0); // read the input on analog pin 0:

float inches = sensorValue * (500 / 1023.0);

// for feet

lcd.print(inches);

lcd.print(“ inches:”);

delay(wait);

lcd.clear();

delay(1000);

// for feet

feet = (inches / 12); // conversion from feet to inches Here this is telling Arduino that

// inches is equal to feet times 12

lcd.print(feet);

lcd.print(“ feet:”);

delay(wait);

lcd.clear();

delay(1000);

yards = (feet / 3); // conversion to yards

lcd.print(yards);

lcd.print(“ yards:”);

delay(wait);

lcd.clear();

delay(1000);

centimeters = (inches * 2.54); // conversion to centimeters

lcd.print(centimeters);

lcd.setCursor(0,1);

lcd.print(“centimeters”);

delay(wait);

lcd.clear();

delay(1000);

meters = (centimeters / 100); // conversion to meters

lcd.print(meters);

lcd.print(“ meters”);

delay(wait);

lcd.clear();

delay(1000);

}

以下是上述草圖的概述:

啟動時,“歡迎使用單位轉(zhuǎn)換器”

“調(diào)整旋鈕”,其下方的英寸數(shù)。轉(zhuǎn)動旋鈕!

顯示英寸數(shù)

顯示英尺數(shù)

顯示厘米數(shù)

顯示數(shù)量或米

責任編輯:wv

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 轉(zhuǎn)換器
    +關(guān)注

    關(guān)注

    27

    文章

    9427

    瀏覽量

    156523
  • Arduino
    +關(guān)注

    關(guān)注

    190

    文章

    6526

    瀏覽量

    197105
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    降壓轉(zhuǎn)換器與LDO的優(yōu)劣對比

    本文將繼續(xù)介紹降壓轉(zhuǎn)換器的自發(fā)熱效應考量、降壓轉(zhuǎn)換器與LDO的優(yōu)劣對比等。
    的頭像 發(fā)表于 02-25 15:37 ?391次閱讀
    降壓<b class='flag-5'>轉(zhuǎn)換器</b>與LDO的優(yōu)劣對比

    振弦信號轉(zhuǎn)換器 多輸出與導軌安裝

    轉(zhuǎn)換器
    穩(wěn)控自動化
    發(fā)布于 :2026年02月05日 14:49:18

    PW2205 芯片 500kHz 同步降壓轉(zhuǎn)換器 SOT23-6 封裝 工業(yè)控制電源管理 IC

    降壓轉(zhuǎn)換器
    jf_66255030
    發(fā)布于 :2026年01月20日 10:44:06

    PW2163 芯片 500kHz 3A 同步降壓轉(zhuǎn)換器 SOT23-6 封裝 消費電子電源管理 IC

    降壓轉(zhuǎn)換器
    jf_66255030
    發(fā)布于 :2026年01月20日 10:19:12

    如何使用多相升壓轉(zhuǎn)換器

    當系統(tǒng)需要的電壓高于可用電壓時,升壓轉(zhuǎn)換器是滿足這一需求的理想選擇。然而,經(jīng)典的標準升壓拓撲結(jié)構(gòu)并非唯一方案。一種更優(yōu)的解決方案或許是移相多相升壓轉(zhuǎn)換器。這類轉(zhuǎn)換器在高負載工況下效率更高,同時能降低輸入及輸出電容值。
    的頭像 發(fā)表于 01-20 10:02 ?3498次閱讀
    如何使用多相升壓<b class='flag-5'>轉(zhuǎn)換器</b>

    8 位、雙路 1.5GSPS 或單路 3.0GSPS 模數(shù)轉(zhuǎn)換器

    模數(shù)轉(zhuǎn)換器
    芯佰微電子
    發(fā)布于 :2026年01月07日 15:50:43

    國產(chǎn)電平轉(zhuǎn)換器雙雄登場!GS0104/GS0108 如何破解多場景電壓適配難題?

    電平轉(zhuǎn)換器
    聚洵半導體科技
    發(fā)布于 :2025年12月22日 14:27:36

    模數(shù)轉(zhuǎn)換器最高使用頻段

    模數(shù)轉(zhuǎn)換器最高使用頻段模數(shù)轉(zhuǎn)換器(ADC)的最高使用頻段取決于其采樣率、輸入帶寬及具體應用場景,部分高性能ADC的最高使用頻段可達W波段(80-100GHz)。一、采樣率與奈奎斯特采樣定理采樣率
    發(fā)表于 12-16 09:58

    422/BISS/SSI轉(zhuǎn)485/232模擬防真信號轉(zhuǎn)換器

    信號轉(zhuǎn)換器
    IBF貝福
    發(fā)布于 :2025年12月06日 15:22:38

    測量DC/DC轉(zhuǎn)換器輸入端的傳導EMI

    如果DC/DC轉(zhuǎn)換器在供電時產(chǎn)生噪聲,是不太理想的。但噪聲多大算大,我們又如何測量?與AC/DC轉(zhuǎn)換器不同,現(xiàn)在還沒有針對DC/DC轉(zhuǎn)換器可接受噪聲水平或測量方式的法定標準。而且,噪聲幅度和頻譜都會隨接地方式和DC/DC
    的頭像 發(fā)表于 10-18 09:24 ?4278次閱讀
    測量DC/DC<b class='flag-5'>轉(zhuǎn)換器</b>輸入端的傳導EMI

    環(huán)網(wǎng)式CANFD轉(zhuǎn)光纖轉(zhuǎn)換器配置流程#三格電子

    光纖轉(zhuǎn)換器
    三格電子科技
    發(fā)布于 :2025年07月03日 14:23:30

    【電磁兼容單位換算】EMC常用單位轉(zhuǎn)換公式推導

    【電磁兼容單位換算】EMC常用單位轉(zhuǎn)換公式推導
    的頭像 發(fā)表于 06-24 17:28 ?4325次閱讀
    【電磁兼容<b class='flag-5'>單位</b>換算】EMC常用<b class='flag-5'>單位</b><b class='flag-5'>轉(zhuǎn)換</b>公式推導

    【EMC單位換算】磁場單位轉(zhuǎn)換關(guān)系

    【EMC單位換算】磁場單位轉(zhuǎn)換關(guān)系
    的頭像 發(fā)表于 04-16 17:44 ?1419次閱讀
    【EMC<b class='flag-5'>單位</b>換算】磁場<b class='flag-5'>單位</b>的<b class='flag-5'>轉(zhuǎn)換</b>關(guān)系

    USB轉(zhuǎn)485/422轉(zhuǎn)換器拆解

    前兩天群里的好大哥給我寄了兩個他設(shè)計的USB轉(zhuǎn)485/422轉(zhuǎn)換器,制作的初衷也很簡單,就是消耗一下他手頭的物料,設(shè)計的關(guān)鍵就是電子丐幫,面向庫存設(shè)計,探索低成本!在這里先感謝胡博設(shè)計的轉(zhuǎn)換器。
    的頭像 發(fā)表于 04-10 10:33 ?3076次閱讀
    USB轉(zhuǎn)485/422<b class='flag-5'>轉(zhuǎn)換器</b>拆解