Arduino uno Toggle button with debounce on and off tutorial

Поделиться
HTML-код
  • Опубликовано: 2 авг 2024
  • Arduino toggle button with debounce on and off (no edge detection yet) will be in the next video!
    Last weeks video with explanation of my code: • Arduino uno Toggle but...
    All my code will be available on my Patreon page:
    / 18294143
    www.patreon.com/asali
    Links:
    Arduino Uno Starter Kit (original version)
    Affiliate link: amzn.to/2H4femD
    Normal link: goo.gl/v4NFAU
    Arduino Uno Starter Kit (cheap version)
    Affiliate link: amzn.to/2R2a6Uu
    Normal link: goo.gl/Z3Ekup
    Arduino Uno
    Affiliate link: amzn.to/2R47IwA
    Normal link: goo.gl/mdSGRH
    Credits:
    Music:
    Classique - Francis Preve
    Thumbnail icon:
    arduino by uizin from the Noun Project
    push button by Hans from the Noun Project

Комментарии • 7

  • @mikeymakes2665
    @mikeymakes2665 Год назад

    Thank you so much! I've been looking for a clear example and this helped me a lot!

  • @hpa4355
    @hpa4355 Год назад

    you can also add a resistor in series and a capacitor in parallel to make an analog debounce :)

  • @saanernst
    @saanernst 2 года назад +1

    It's counter, not debounce. If you want to debounce add delay(100); line before digitalWrite(led, ledState); line.

  • @stormbytes
    @stormbytes 2 года назад +5

    You should post the code for videos you publish to RUclips. If you want to have premium videos on Patreon, that's fine. That's what many publishers do. But this half-here/half-not business is just irritating. Good video. Attitude, not so much.

    • @MUHAMMADYAWARIFRAHEEM
      @MUHAMMADYAWARIFRAHEEM 2 года назад

      Here is best arduino tutorial on youtube ... check the link no patreon shit free for all ruclips.net/p/PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP

  • @stormbytes
    @stormbytes 2 года назад +2

    This is really confusing. I can see that it works but I don't understand how or why. Time is really just an arbitrary value. So let's say the first go around time = 0, so ANY VALUE for millis() - Time > 0; So no debounce there. Lets say next time around time = 443, you just wait long enough for millis() to be greater than 443+debounce and again, anything sets it off. So if I understand this correct, your code doesn't actually "debounce" anything. It just ignores all other 'bounce' signals after the initial contact is made. It doesnt' actually establish a stable signal change.

    • @HyperionBadger
      @HyperionBadger 2 года назад +1

      if 37000 milliseconds have passed since you fired up your arduino, millis() will be 37000. The first time you click the button, "time" will be 0. 37000 - 0 = 37000 which is greater than the debounce value of 200, and it will initiate the counter.
      Now, since you are a human being and not perfect, when you click that button, you're finger is probably pressing down for 158 milliseconds. Let's imagine the arduino reads all input every 1 millisecond. It will think you clicked that button 158 times! But with this function, every millisecond it is doing that computation: millis() - time.
      The first millisecond it will engage the counter since 37000 - 1 = 37000 and that is greater than 200. The second millisecond your finger is still pressed down, however, the computation looks like so: 37001 - 37000 = 1 , which is less than 200, and it doesn't do anything, not even change the "time" variable.
      The second millisecond it will do the same 37002 - 37000 which is 2. Still smaller than 200. Don't do anything.
      By the time you've released your finger 158 milliseconds later, it's gotten to 37158 - 37000, which is equaled to 158, which is still less than 200. So because of this function, even though arduino would've thought you clicked it 158 times, it only registered it as ONCE.
      Now if you hold onto the button for more than 200 milliseconds, it will register it as two clicks, 400 milliseconds as three clicks, and so on..