乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Arduino教程:按鍵消抖

       山峰云繞 2019-06-17

      【【計(jì)算機(jī)大俠】Arduino教程:按鍵消抖】https://toutiao.com/group/6703127408653894152/?app=explore_article&timestamp=1560724254&req_id=201906170630530101520170937899F97&group_id=6703127408653894152&tt_from=copy_link&utm_source=copy_link&utm_medium=toutiao_ios&utm_campaign=client_share 


      防抖當(dāng)按下時(shí),按鍵經(jīng)常產(chǎn)生錯(cuò)誤的開/關(guān)變遷,這是機(jī)械物理的問題:這些變遷可能被讀取為在短時(shí)間內(nèi)多次按下,從而使程序變笨。這個(gè)例子示范了怎樣使一個(gè)輸入防抖,這意味著在一個(gè)短時(shí)間內(nèi)檢查兩次來確保這個(gè)按鍵是確實(shí)被按下了。如果沒有防抖,按一次這個(gè)按鍵可能會(huì)引起不可預(yù)測(cè)的結(jié)果。這個(gè)程序利用millis()函數(shù)來保持按下的時(shí)間間隔。

      按鍵消抖原理

      當(dāng)按下時(shí),按鍵經(jīng)常產(chǎn)生錯(cuò)誤的開/關(guān)變化,這是機(jī)械物理的問題:這些變化可能被讀取為在短時(shí)間內(nèi)多次按下,從而使程序變笨。這個(gè)例子示范了怎樣使一個(gè)輸入防抖,這意味著在一個(gè)短時(shí)間內(nèi)檢查兩次來確保這個(gè)按鍵是確實(shí)被按下了。如果沒有防抖,按一次這個(gè)按鍵可能會(huì)引起不可預(yù)測(cè)的結(jié)果。這個(gè)程序利用millis()函數(shù)來保持按下的時(shí)間間隔。

      硬件要求

      • Arduino or Genuino 開發(fā)板
      • 即時(shí)按鍵或者開關(guān)
      • 10k ohm 電阻
      • 連接線
      • 面包板

      代碼

      例子里,當(dāng)閉合時(shí)開關(guān)為低電平,而斷開時(shí)開關(guān)未高電平。這里當(dāng)按下開關(guān)時(shí)為高電平,沒有按下時(shí)為低電平。

      // constants won't change. They're used here to// set pin numbers:const int buttonPin = 2; // the number of the pushbutton pinconst int ledPin = 13; // the number of the LED pin// Variables will change:int ledState = HIGH; // the current state of the output pinint buttonState; // the current reading from the input pinint lastButtonState = LOW; // the previous reading from the input pin// the following variables are long's because the time, measured in miliseconds,// will quickly become a bigger number than can be stored in an int.long lastDebounceTime = 0; // the last time the output pin was toggledlong debounceDelay = 50; // the debounce time; increase if the output flickersvoid setup() { pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); // set initial LED state digitalWrite(ledPin, ledState);}void loop() { // read the state of the switch into a local variable: int reading = digitalRead(buttonPin); // check to see if you just pressed the button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: // if the button state has changed: if (reading != buttonState) { buttonState = reading; // only toggle the LED if the new button state is HIGH if (buttonState == HIGH) { ledState = !ledState; } } } // set the LED: digitalWrite(ledPin, ledState); // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading;}

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多