色哟哟视频在线观看-色哟哟视频在线-色哟哟欧美15最新在线-色哟哟免费在线观看-国产l精品国产亚洲区在线观看-国产l精品国产亚洲区久久

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

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

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

如何設(shè)置用于旋轉(zhuǎn)編碼器的簡(jiǎn)單Arduino菜單

454398 ? 來(lái)源:網(wǎng)絡(luò)整理 ? 作者:網(wǎng)絡(luò)整理 ? 2020-01-29 17:43 ? 次閱讀

步驟1:準(zhǔn)備工作

如何設(shè)置用于旋轉(zhuǎn)編碼器的簡(jiǎn)單Arduino菜單

如果還沒(méi)有,請(qǐng)參閱我的其他Instructable旋轉(zhuǎn)編碼器閱讀,以了解如何設(shè)置硬件和Arduino IDE軟件。

硬件

圖片中顯示了需要使用中心按鈕的其他硬件連接。我使用Fritzing繪制了圖表,但它沒(méi)有代表最可能的引腳布局的旋轉(zhuǎn)編碼器組件,因此只需將該圖表與注釋結(jié)合使用,然后查看旋轉(zhuǎn)編碼器的照片,即可了解更多內(nèi)容。可能正在尋找旋轉(zhuǎn)編碼器引腳布局方面的信息

旋轉(zhuǎn)編碼器一側(cè)(與具有三個(gè)引腳的一側(cè)相對(duì))的兩個(gè)引腳之一需要接地,而另一端則要連接到Arduino的數(shù)字引腳。我已將D4用于示例草圖。如果您選擇其他引腳,請(qǐng)不要忘記更改草圖中的 buttonPin 的值。

接下來(lái)是步驟2中的代碼。

步驟2:代碼

這是代碼。通過(guò)查看結(jié)構(gòu)和評(píng)論,我希望您會(huì)發(fā)現(xiàn)很容易適應(yīng)您的特定需求!

/*******Interrupt-based Rotary Encoder Menu Sketch*******

* by Simon Merrett, based on insight from Oleg Mazurov, Nick Gammon, rt and Steve Spence, and code from Nick Gammon

* 3,638 bytes with debugging on UNO, 1,604 bytes without debugging

*/

// Rotary encoder declarations

static int pinA = 2; // Our first hardware interrupt pin is digital pin 2

static int pinB = 3; // Our second hardware interrupt pin is digital pin 3

volatile byte aFlag = 0; // let‘s us know when we’re expecting a rising edge on pinA to signal that the encoder has arrived at a detent

volatile byte bFlag = 0; // let‘s us know when we’re expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)

volatile byte encoderPos = 0; //this variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255

volatile byte oldEncPos = 0; //stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)

volatile byte reading = 0; //somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent

// Button reading, including debounce without delay function declarations

const byte buttonPin = 4; // this is the Arduino pin we are connecting the push button to

byte oldButtonState = HIGH; // assume switch open because of pull-up resistor

const unsigned long debounceTime = 10; // milliseconds

unsigned long buttonPressTime; // when the switch last changed state

boolean buttonPressed = 0; // a flag variable

// Menu and submenu/setting declarations

byte Mode = 0; // This is which menu mode we are in at any given time (top level or one of the submenus)

const byte modeMax = 3; // This is the number of submenus/settings you want

byte setting1 = 0; // a variable which holds the value we set

byte setting2 = 0; // a variable which holds the value we set

byte setting3 = 0; // a variable which holds the value we set

/* Note: you may wish to change settingN etc to int, float or boolean to suit your application.

Remember to change “void setAdmin(byte name,*BYTE* setting)” to match and probably add some

“modeMax”-type overflow code in the “if(Mode == N && buttonPressed)” section*/

void setup() {

//Rotary encoder section of setup

pinMode(pinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)

pinMode(pinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)

attachInterrupt(0,PinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the “PinA” Interrupt Service Routine (below)

attachInterrupt(1,PinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the “PinB” Interrupt Service Routine (below)

// button section of setup

pinMode (buttonPin, INPUT_PULLUP); // setup the button pin

// DEBUGGING section of setup

Serial.begin(9600); // DEBUGGING: opens serial port, sets data rate to 9600 bps

}

void loop() {

rotaryMenu();

// carry out other loop code here

}

void rotaryMenu() { //This handles the bulk of the menu functions without needing to install/include/compile a menu library

//DEBUGGING: Rotary encoder update display if turned

if(oldEncPos != encoderPos) { // DEBUGGING

Serial.println(encoderPos);// DEBUGGING. Sometimes the serial monitor may show a value just outside modeMax due to this function. The menu shouldn‘t be affected.

oldEncPos = encoderPos;// DEBUGGING

}// DEBUGGING

// Button reading with non-delay() debounce - thank you Nick Gammon!

byte buttonState = digitalRead (buttonPin);

if (buttonState != oldButtonState){

if (millis () - buttonPressTime 》= debounceTime){ // debounce

buttonPressTime = millis (); // when we closed the switch

oldButtonState = buttonState; // remember for next time

if (buttonState == LOW){

Serial.println (“Button closed”); // DEBUGGING: print that button has been closed

buttonPressed = 1;

}

else {

Serial.println (“Button opened”); // DEBUGGING: print that button has been opened

buttonPressed = 0;

}

} // end if debounce time up

} // end of state change

//Main menu section

if (Mode == 0) {

if (encoderPos 》 (modeMax+10)) encoderPos = modeMax; // check we haven’t gone out of bounds below 0 and correct if we have

else if (encoderPos 》 modeMax) encoderPos = 0; // check we haven‘t gone out of bounds above modeMax and correct if we have

if (buttonPressed){

Mode = encoderPos; // set the Mode to the current value of input if button has been pressed

Serial.print(“Mode selected: ”); //DEBUGGING: print which mode has been selected

Serial.println(Mode); //DEBUGGING: print which mode has been selected

buttonPressed = 0; // reset the button status so one press results in one action

if (Mode == 1) {

Serial.println(“Mode 1”); //DEBUGGING: print which mode has been selected

encoderPos = setting1; // start adjusting Vout from last set point

}

if (Mode == 2) {

Serial.println(“Mode 2”); //DEBUGGING: print which mode has been selected

encoderPos = setting2; // start adjusting Imax from last set point

}

if (Mode == 3) {

Serial.println(“Mode 3”); //DEBUGGING: print which mode has been selected

encoderPos = setting3; // start adjusting Vmin from last set point

}

}

}

if (Mode == 1 && buttonPressed) {

setting1 = encoderPos; // record whatever value your encoder has been turned to, to setting 3

setAdmin(1,setting1);

//code to do other things with setting1 here, perhaps update display

}

if (Mode == 2 && buttonPressed) {

setting2 = encoderPos; // record whatever value your encoder has been turned to, to setting 2

setAdmin(2,setting2);

//code to do other things with setting2 here, perhaps update display

}

if (Mode == 3 && buttonPressed){

setting3 = encoderPos; // record whatever value your encoder has been turned to, to setting 3

setAdmin(3,setting3);

//code to do other things with setting3 here, perhaps update display

}

}

// Carry out common activities each time a setting is changed

void setAdmin(byte name, byte setting){

Serial.print(“Setting ”); //DEBUGGING

Serial.print(name); //DEBUGGING

Serial.print(“ = ”); //DEBUGGING

Serial.println(setting);//DEBUGGING

encoderPos = 0; // reorientate the menu index - optional as we have overflow check code elsewhere

buttonPressed = 0; // reset the button status so one press results in one action

Mode = 0; // go back to top level of menu, now that we’ve set values

Serial.println(“Main Menu”); //DEBUGGING

}

//Rotary encoder interrupt service routine for one encoder pin

void PinA(){

cli(); //stop interrupts happening before we read pin values

reading = PIND & 0xC; // read all eight pin values then strip away all but pinA and pinB‘s values

if(reading == B00001100 && aFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin’s rising edge

encoderPos --; //decrement the encoder‘s position count

bFlag = 0; //reset flags for the next turn

aFlag = 0; //reset flags for the next turn

}

else if (reading == B00000100) bFlag = 1; //signal that we’re expecting pinB to signal the transition to detent from free rotation

sei(); //restart interrupts

}

//Rotary encoder interrupt service routine for the other encoder pin

void PinB(){

cli(); //stop interrupts happening before we read pin values

reading = PIND & 0xC; //read all eight pin values then strip away all but pinA and pinB‘s values

if (reading == B00001100 && bFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin’s rising edge

encoderPos ++; //increment the encoder‘s position count

bFlag = 0; //reset flags for the next turn

aFlag = 0; //reset flags for the next turn

}

else if (reading == B00001000) aFlag = 1; //signal that we’re expecting pinA to signal the transition to detent from free rotation

sei(); //restart interrupts

}

// end of sketch!

在任何對(duì)菜單執(zhí)行操作都不重要的行的每個(gè)注釋的開(kāi)頭,我都使用了“ DEBUGGING”。如果您對(duì)菜單功能滿意,則可能需要注釋掉或刪除這些行以縮小編譯的草圖尺寸。

請(qǐng)注意,菜單導(dǎo)航的關(guān)鍵部分是在用戶滾動(dòng)瀏覽選項(xiàng)和設(shè)置時(shí)反饋給用戶。因此,如果您選擇不包括DEBUGGING行,則可能應(yīng)該使用另一個(gè)可視指示器(例如LCD文本顯示器,LED),編碼器輸入正在導(dǎo)航菜單并更改設(shè)置。

如果我注釋掉DEBUGGING行(注意,菜單導(dǎo)航仍需要一些視覺(jué)反饋),Arduino Uno的編譯后代碼約為1,650字節(jié),希望在ATMEGA328P上留出足夠的空間以容納草圖中更令人興奮的部分!

轉(zhuǎn)到步驟3,了解菜單系統(tǒng)的工作原理

步驟3:操作和結(jié)論

操作

如果上傳此草圖后在Arduino中打開(kāi)串行監(jiān)視器,并開(kāi)始轉(zhuǎn)動(dòng)編碼器軸,則應(yīng)該看到頂層菜單在子菜單/選項(xiàng)數(shù)中旋轉(zhuǎn)您擁有(使用 modeMax 變量進(jìn)行限制)。如果按中間的按鈕,您會(huì)看到已選擇要滾動(dòng)到的模式/子菜單,現(xiàn)在可以自由選擇要滾動(dòng)瀏覽該子菜單中的0-255值。現(xiàn)在,如果您按下中央按鈕,則將其設(shè)置為 setting1 或 setting2 或 setting3 等。Arduino自動(dòng)并立即返回

上電后,Arduino會(huì)記住您將每個(gè)設(shè)置設(shè)置為什么,并且如果您返回子菜單以獲取設(shè)置,則您已經(jīng)設(shè)置了一個(gè)值到此為止,它將從您選擇的最后一個(gè)值開(kāi)始進(jìn)行編碼器調(diào)整!

結(jié)論

我著手編寫一些基于草圖的代碼,旋轉(zhuǎn)編碼器導(dǎo)航Arduino的基本菜單。我還嘗試使其具有可讀性,以便與某些替代方案不同,有人可以看到菜單結(jié)構(gòu),并知道他們需要進(jìn)行哪些更改才能根據(jù)自己的需要定制菜單。

此代碼是基本的和通用的,專門用于演示功能,同時(shí)易于適應(yīng)您自己的應(yīng)用程序。它使用串行監(jiān)視器作為基本的調(diào)試工具,如果您想查看代碼的工作原理,也不需要單獨(dú)顯示。希望您發(fā)現(xiàn)它有用,并受到啟發(fā)進(jìn)行編輯,修改和改進(jìn)!

責(zé)任編輯:wv

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

    關(guān)注

    45

    文章

    3664

    瀏覽量

    135051
  • Arduino
    +關(guān)注

    關(guān)注

    188

    文章

    6477

    瀏覽量

    187594
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    二進(jìn)制編碼器與絕對(duì)編碼器的區(qū)別

    編碼器是工業(yè)自動(dòng)化和機(jī)器人技術(shù)中不可或缺的組件,用于將機(jī)械位置或運(yùn)動(dòng)轉(zhuǎn)換為電信號(hào)。二進(jìn)制編碼器和絕對(duì)編碼器是兩種常見(jiàn)的編碼器類型,它們各自有
    的頭像 發(fā)表于 11-06 09:54 ?616次閱讀

    旋轉(zhuǎn)編碼器的類型以及選擇與設(shè)計(jì)注意要點(diǎn)

    應(yīng)用中,需要準(zhǔn)確測(cè)量旋轉(zhuǎn)物體的角度,旋轉(zhuǎn)編碼器可以提供高精度的角度信息,用于導(dǎo)航、定位和控制系統(tǒng)。此外,通過(guò)監(jiān)測(cè)旋轉(zhuǎn)
    的頭像 發(fā)表于 10-02 16:52 ?398次閱讀
    <b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>的類型以及選擇與設(shè)計(jì)注意要點(diǎn)

    旋轉(zhuǎn)編碼器可以收集并發(fā)出什么信號(hào),旋轉(zhuǎn)編碼器信號(hào)異常怎么處理

    旋轉(zhuǎn)編碼器是一種精密的測(cè)量裝置,主要用于旋轉(zhuǎn)運(yùn)動(dòng)轉(zhuǎn)換為可測(cè)量的電信號(hào)。它可以收集并發(fā)出多種信號(hào),但主要的是與旋轉(zhuǎn)運(yùn)動(dòng)相關(guān)的位置、速度或角度
    的頭像 發(fā)表于 10-01 16:55 ?734次閱讀

    增量旋轉(zhuǎn)編碼器

    電子發(fā)燒友網(wǎng)站提供《增量旋轉(zhuǎn)編碼器.pdf》資料免費(fèi)下載
    發(fā)表于 09-03 11:51 ?0次下載
    增量<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>

    編碼器有什么分類?

    編碼器本質(zhì)是一種用于運(yùn)動(dòng)控制的傳感,作用在于測(cè)量機(jī)械旋轉(zhuǎn)的位移。
    的頭像 發(fā)表于 08-10 14:47 ?674次閱讀

    Arduino旋轉(zhuǎn)編碼器設(shè)計(jì) 旋轉(zhuǎn)編碼器的工作原理和特點(diǎn)

    旋轉(zhuǎn)編碼器(Rotary Encoder),也稱為軸編碼器,是一種將旋轉(zhuǎn)的機(jī)械位移量轉(zhuǎn)換為電氣信號(hào)的傳感。這些電氣信號(hào)經(jīng)過(guò)處理后,可以
    的頭像 發(fā)表于 07-04 17:17 ?2997次閱讀
    帶<b class='flag-5'>Arduino</b>的<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>設(shè)計(jì) <b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>的工作原理和特點(diǎn)

    旋轉(zhuǎn)編碼器控制電機(jī)速度

    旋轉(zhuǎn)編碼器控制電機(jī)速度
    發(fā)表于 06-24 09:16 ?4次下載

    怎么看編碼器上的參數(shù)?

    編碼器是一種用于測(cè)量運(yùn)動(dòng)和位置的設(shè)備,常用于工業(yè)控制、機(jī)器人和自動(dòng)化設(shè)備等領(lǐng)域。編碼器的工作原理基于數(shù)碼信號(hào)與機(jī)械旋轉(zhuǎn)之間的特定關(guān)系,可以將
    的頭像 發(fā)表于 06-23 16:16 ?1696次閱讀
    怎么看<b class='flag-5'>編碼器</b>上的參數(shù)?

    變頻編碼器參數(shù)怎么設(shè)置方法

    變頻編碼器參數(shù)設(shè)置是確保變頻編碼器正常工作的關(guān)鍵步驟。本文將詳細(xì)介紹變頻
    的頭像 發(fā)表于 06-17 14:36 ?2382次閱讀

    s120編碼器參數(shù)設(shè)置在哪里

    S120編碼器是一種高精度的旋轉(zhuǎn)編碼器,廣泛應(yīng)用于工業(yè)自動(dòng)化、機(jī)器人、數(shù)控機(jī)床等領(lǐng)域。S120編碼器具有多種型號(hào),不同型號(hào)的
    的頭像 發(fā)表于 06-17 14:33 ?1506次閱讀

    旋轉(zhuǎn)編碼器在PLC中怎么編程

    在工業(yè)自動(dòng)化領(lǐng)域,旋轉(zhuǎn)編碼器與可編程邏輯控制(PLC)的結(jié)合應(yīng)用極為廣泛。旋轉(zhuǎn)編碼器通過(guò)提供精確的旋轉(zhuǎn)
    的頭像 發(fā)表于 06-17 09:24 ?1919次閱讀

    旋轉(zhuǎn)編碼器的常見(jiàn)類型

    在工業(yè)自動(dòng)化和精密測(cè)量領(lǐng)域中,旋轉(zhuǎn)編碼器是一種不可或缺的設(shè)備。它能夠?qū)?b class='flag-5'>旋轉(zhuǎn)位置或旋轉(zhuǎn)量轉(zhuǎn)換成模擬或數(shù)字信號(hào),為控制系統(tǒng)提供精確的位置和速度信息。隨著技術(shù)的不斷發(fā)展,
    的頭像 發(fā)表于 05-29 15:59 ?1033次閱讀

    旋轉(zhuǎn)編碼器的種類和接線方法

    旋轉(zhuǎn)編碼器,作為現(xiàn)代工業(yè)領(lǐng)域中不可或缺的重要傳感,廣泛應(yīng)用于各種機(jī)械設(shè)備、自動(dòng)化系統(tǒng)以及測(cè)量?jī)x器中。它能夠準(zhǔn)確測(cè)量物體的轉(zhuǎn)速、角度等參數(shù),并轉(zhuǎn)換成相應(yīng)的電信號(hào)輸出,為控制系統(tǒng)提供精確
    的頭像 發(fā)表于 05-24 14:50 ?1862次閱讀

    如何將增量旋轉(zhuǎn)編碼器Arduino連接

    在本教程中,您將學(xué)習(xí)如何將增量旋轉(zhuǎn)編碼器Arduino連接,以讀取旋鈕的運(yùn)動(dòng)。這對(duì)于在機(jī)器人和其他應(yīng)用程序中創(chuàng)建用戶界面或讀取機(jī)械位置非常有用。
    的頭像 發(fā)表于 02-11 10:00 ?1560次閱讀
    如何將增量<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>與<b class='flag-5'>Arduino</b>連接

    旋轉(zhuǎn)編碼器的工作原理,旋轉(zhuǎn)編碼器的作用功能及應(yīng)用

    旋轉(zhuǎn)編碼器用于測(cè)量軸或軸旋轉(zhuǎn)的組件。它們通常用于音頻設(shè)備、DIY 游戲控制中的音量旋鈕,或用
    的頭像 發(fā)表于 02-11 09:53 ?5994次閱讀
    <b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>的工作原理,<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>的作用功能及應(yīng)用
    主站蜘蛛池模板: 黄色jjzz| 国产三级在线免费 | 日韩精品专区在线影院重磅 | 男人把女人桶到高潮嗷嗷叫 | 玩弄人妻少妇500系列网址 | 亚洲欧美精品无码大片在线观看 | 亚洲精品一二三 | 一本道本线中文无码 | 日韩AV成人无码久久精品老人 | 忘忧草研究所 麻豆 | 日本无码人妻精品一区二区视频 | 亚洲伊人色 | 扒开腿狂躁女人GIF动态图 | 我的家庭女教师 | 免费在线a| 2020国产成人精品免费视频 | 伊人久久精品AV一区二区 | 艳鉧动漫1~6全集观看在线 | 嫩草电影网嫩草影院 | 国产高清视频免费最新在线 | 亚洲欧美国产综合在线一区 | 亚洲精品无码午夜福利在线观看 | 国产女合集小岁9三部 | 秋霞在线观看视频一区二区三区 | 成人免费网址在线 | 久久精品亚洲热综合一本奇米 | 人人在线碰碰视频免费 | 秋秋影视午夜福利高清 | 用快播看av的网站 | 精品国产乱码久久久久久软件 | 久热这里在线精品 | 久久精品观看影院2828 | 美女脱了内裤张开腿让男人爽 | 国产精一品亚洲二区在线播放 | 国产深夜福利视频在线 | 日韩hd高清xxxⅹ | 色偷偷7777www | 老男人粗大猛 | 一线高清视频在线播放 | 国产小视频免费看 | 日本xxxx裸体xxxx|