chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

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

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

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

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

454398 ? 來源:網(wǎng)絡(luò)整理 ? 作者:網(wǎng)絡(luò)整理 ? 2020-01-29 17:43 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

步驟1:準備工作

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

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

硬件

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

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

接下來是步驟2中的代碼。

步驟2:代碼

這是代碼。通過查看結(jié)構(gòu)和評論,我希望您會發(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!

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

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

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

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

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

操作

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

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

結(jié)論

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

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

責任編輯:wv

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

    關(guān)注

    45

    文章

    4013

    瀏覽量

    143379
  • Arduino
    +關(guān)注

    關(guān)注

    190

    文章

    6527

    瀏覽量

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

掃碼添加小助手

加入工程師交流群

    評論

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

    絕對式旋轉(zhuǎn)編碼器常用什么類型磁鐵?

    絕對式旋轉(zhuǎn)編碼器是一種能夠在任意時刻直接輸出唯一角度位置值的傳感,即使斷電重啟也無需回零,所以被廣泛用于工業(yè)控制,機器人,這種編碼器是需要
    的頭像 發(fā)表于 03-26 13:44 ?220次閱讀
    絕對式<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>常用什么類型磁鐵?

    磁鐵在編碼器中的作用與應(yīng)用

    編碼器中,磁鐵的作用不可小覷,常用的磁性材料主要是釹鐵硼和鐵氧體,今天這篇文章主要介紹下磁鐵用于哪些編碼器類型,以及其具體作用。磁鐵在編碼器中的作用(功能)是什么?在
    的頭像 發(fā)表于 03-19 14:42 ?413次閱讀
    磁鐵在<b class='flag-5'>編碼器</b>中的作用與應(yīng)用

    增量型旋轉(zhuǎn)編碼器:工業(yè)自動化的“精密之眼”

    在鋼鐵廠的高爐旁,滾燙的鋼水在傳送帶上疾馳;在港口的起重機下,集裝箱被精準吊裝;在紡織車間里,紗線以每分鐘數(shù)萬轉(zhuǎn)的速度飛旋……這些場景背后,都藏著一雙“精密之眼”——貝弗德增量型旋轉(zhuǎn)編碼器。它以微米
    的頭像 發(fā)表于 12-31 08:43 ?357次閱讀
    增量型<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>:工業(yè)自動化的“精密之眼”

    探索AEDR - 9930E:三通道反射式增量旋轉(zhuǎn)編碼器的技術(shù)剖析

    探索AEDR - 9930E:三通道反射式增量旋轉(zhuǎn)編碼器的技術(shù)剖析 在當今的電子設(shè)備設(shè)計領(lǐng)域,編碼器的性能和適用性對于系統(tǒng)的整體表現(xiàn)起著至關(guān)重要的作用。今天,我們將深入探討博通(Broadcom
    的頭像 發(fā)表于 12-30 15:40 ?350次閱讀

    旋轉(zhuǎn)編碼器增量:工業(yè)自動化領(lǐng)域的“精密之眼”

    在工業(yè)自動化飛速發(fā)展的今天,每一個細微的精度提升都可能帶來生產(chǎn)效率的巨大飛躍。而旋轉(zhuǎn)編碼器增量,作為工業(yè)自動化領(lǐng)域的核心元件,正以其獨特的優(yōu)勢,成為眾多行業(yè)不可或缺的“精密之眼”。 旋轉(zhuǎn)編碼器
    的頭像 發(fā)表于 12-08 08:41 ?512次閱讀
    <b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>增量:工業(yè)自動化領(lǐng)域的“精密之眼”

    增量旋轉(zhuǎn)編碼器:工業(yè)自動化的“精密之眼”

    在智能制造與工業(yè)4.0的浪潮中,每一次細微的位移、每一輪精準的旋轉(zhuǎn),都關(guān)乎著生產(chǎn)效率與產(chǎn)品品質(zhì)的成敗。在這場精密制造的革命里,增量旋轉(zhuǎn)編碼器以其獨特的魅力,成為工業(yè)自動化領(lǐng)域不可或缺的核心傳感
    的頭像 發(fā)表于 12-02 08:43 ?524次閱讀
    增量<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>:工業(yè)自動化的“精密之眼”

    Vishay RAIK060 旋轉(zhuǎn)絕對感應(yīng)套件編碼器技術(shù)解析

    Vishay RAIK060旋轉(zhuǎn)絕對電感套件編碼器專門用于電機驅(qū)動、機器人位置和具有精確定位的工業(yè)運動控制。這些編碼器通過LED狀態(tài)顏色輕松組裝,對外部磁場、電場和溫度不敏感。RAIK
    的頭像 發(fā)表于 11-11 11:31 ?1226次閱讀
    Vishay RAIK060 <b class='flag-5'>旋轉(zhuǎn)</b>絕對感應(yīng)套件<b class='flag-5'>編碼器</b>技術(shù)解析

    增量式編碼器工作原理是什么?

    增量式編碼器工作原理是什么?增量式編碼器是一種通過輸出脈沖信號來反映旋轉(zhuǎn)位置變化的傳感,廣泛應(yīng)用于電機測速、位置控制等領(lǐng)域。其工作原理可從
    的頭像 發(fā)表于 09-29 11:00 ?2553次閱讀
    增量式<b class='flag-5'>編碼器</b>工作原理是什么?

    國產(chǎn)編碼器在人形機器人領(lǐng)域的進展

    電子發(fā)燒友網(wǎng)綜合報道?編碼器是測量旋轉(zhuǎn)角度、位移及速度的傳感,作為伺服系統(tǒng)的核心部件,在人形機器人領(lǐng)域,其數(shù)據(jù)反饋對實現(xiàn)機器人運動的精密控制與定位至關(guān)重要。 ? 編碼器種類豐富,按技
    的頭像 發(fā)表于 09-24 09:41 ?1714次閱讀

    多圈增量式編碼器:工業(yè)自動化中的“旋轉(zhuǎn)記憶大師”

    在工業(yè)自動化設(shè)備高速運轉(zhuǎn)的場景中,一臺風電齒輪箱的傳動軸持續(xù)旋轉(zhuǎn)了128圈,傳統(tǒng)單圈編碼器早已因數(shù)據(jù)溢出而“失憶”,而多圈增量式編碼器卻能精準記錄每一圈的位移變化,為控制系統(tǒng)提供連續(xù)、可靠的位置反饋
    的頭像 發(fā)表于 09-18 17:14 ?1106次閱讀

    圣邦微電子推出高度集成旋轉(zhuǎn)編碼器芯片VCE2755

    圣邦微電子推出 VCE2755,一款基于各向異性磁阻(AMR)技術(shù)的高度集成旋轉(zhuǎn)編碼器芯片。該器件可應(yīng)用于各種典型的需要角度位置反饋和速度檢測的應(yīng)用場景。
    的頭像 發(fā)表于 08-21 11:51 ?1759次閱讀
    圣邦微電子推出高度集成<b class='flag-5'>旋轉(zhuǎn)</b>磁<b class='flag-5'>編碼器</b>芯片VCE2755

    新品|Unit Step16,16 定位BCD旋轉(zhuǎn)編碼器控制單元

    UnitStep16是一款基于STM32G031G8U6微控制的16定位旋轉(zhuǎn)編碼器控制單元。其核心功能在于實時采集旋轉(zhuǎn)編碼器的BCD
    的頭像 發(fā)表于 08-01 17:35 ?1566次閱讀
    新品|Unit Step16,16 定位BCD<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>控制單元

    增量型旋轉(zhuǎn)編碼器:工業(yè)智能化的“精密羅盤”

    在工業(yè)自動化浪潮席卷全球的今天,每一個精密動作的背后都離不開傳感的精準反饋。作為工業(yè)控制領(lǐng)域的“隱形冠軍”,增量型旋轉(zhuǎn)編碼器憑借其高性價比、高可靠性和靈活適配性,正成為智能制造、機器人、新能源汽車
    的頭像 發(fā)表于 07-30 08:33 ?792次閱讀
    增量型<b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>編碼器</b>:工業(yè)智能化的“精密羅盤”

    增量型編碼器與絕對值型編碼器怎么選擇?

    在選擇增量型編碼器與絕對值型編碼器時,需要考慮多個因素,包括應(yīng)用需求、成本、精度、可靠性以及環(huán)境適應(yīng)性等。以下是對兩種編碼器的詳細比較及選擇建議: 一、增量型編碼器 1. 優(yōu)點: ?
    的頭像 發(fā)表于 07-10 10:34 ?1832次閱讀

    Bourns 擴展增量式編碼器產(chǎn)品線,旋轉(zhuǎn)壽命功能再升級

    組件領(lǐng)導制造供貨商,宣布擴展其 PEC11J 增量式編碼器產(chǎn)品系列,新增功能可提升裝置的旋轉(zhuǎn)壽命。設(shè)計人員現(xiàn)在可選擇每 360° 旋轉(zhuǎn) 24 脈沖的產(chǎn)品,并可選配無定位點選項。旋轉(zhuǎn)脈沖
    發(fā)表于 06-10 14:56 ?1703次閱讀
    Bourns 擴展增量式<b class='flag-5'>編碼器</b>產(chǎn)品線,<b class='flag-5'>旋轉(zhuǎn)</b>壽命功能再升級