Тёмный
No video :(

Ep. 58 - Arduino Advanced Input & Button Control, Debouncing, Counters & Multitasking 

EEEnthusiast
Подписаться 41 тыс.
Просмотров 49 тыс.
50% 1

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 89   
@jamesmoon5632
@jamesmoon5632 Месяц назад
This has taken me ages to understand how this works. Very smart design of the software
@Pedenmoeller
@Pedenmoeller 7 лет назад
I think your channel is fairly underestimated. It's good material you post. Well argument and well explained! thank you for the good work! you especially inspired me in Ep 59 (LCD ep) were I got stock with my own OLED project. I would love to see more from you in this regard! keep it up! cheers
@brianfischer2424
@brianfischer2424 5 лет назад
The video is 2 years old now, but is still incredibly helpful. Hope you continue to put out more videos. You explain it very clearly which is really tough to find on RU-vid. Keep up the good work!
@EEEnthusiast
@EEEnthusiast 5 лет назад
Thank you for the feedback Brian, I really appreciate it. Although I do still make videos on RU-vid, I've decided to switch gears and focus on industrial automation, which is where I ended up with my experience. Here's a link to said channel if you're curious: ru-vid.com
@danljohnston
@danljohnston 7 лет назад
I watch all the Arduino videos on YT, never seen some of this covered. Thanks for sharing.
@rickcreamer8193
@rickcreamer8193 2 года назад
Thank you for the video. I like the way you break down and explain how the code is operating at each step along the way. It definitely helps with understand what the program is doing!
@eatonasher3398
@eatonasher3398 6 лет назад
THANK YOU. Most helpful video/code I've come across. All I wanted to do is have 4 buttons turn 4 different LEDs on/off... who knew this would be so complicated lol
@ricardochirino4543
@ricardochirino4543 4 года назад
For someone new on Arduino like me this is easy to understand , thanks
@Liam-ey2gs
@Liam-ey2gs 4 года назад
I believe you can also use pinMode(intputPins[i], INPUT_PULLUP); to enable the internal pull-up instead of digitalWrite(inputPins[i], HIGH); .
@BerndSchmitt-Martinique
@BerndSchmitt-Martinique Год назад
Very good video. Useful for those, who don't want to use libraries like ONE BUTTON ...for example, if you don't have physical buttons but instead soft-buttons created by an MPR121 capacitive sensor. Greetings from Germany.
@klausnielsen1537
@klausnielsen1537 3 года назад
Sweet! I like the precise structure of thw code and the well explained walkthrough style of the video. Not many can or will do this. TY 😀👍
@mattamath9837
@mattamath9837 4 года назад
Thanks for the video! Learning how to structure the program in an ordered and "modular" way was extremely helpful for my project!
@VasilisKarastergios
@VasilisKarastergios 7 лет назад
Excellent thanks for sharing, that cleared some of the fog! Waiting for more Arduino tutorials, keep it up!!!
@EEEnthusiast
@EEEnthusiast 7 лет назад
Thank you sir! Anything in particular you'd like to see demonstrated on Arduino?
@CamObserver
@CamObserver 4 года назад
I have been viewing a ton of adurino code. I am a programmer. Saw this and went right to the code and not watching the cast. I have to say like the style of coding you have. Liked the video too good for beginners that need to learn how to code simple activities with good coding structure.
@karlis6932
@karlis6932 7 лет назад
I would like to see detailed commenting in your code. That would help to understand it better. Thanks for video.
@alekspesic8783
@alekspesic8783 2 года назад
Amazing!! Thank You.
@nosafetyswitch9378
@nosafetyswitch9378 5 лет назад
Freaking amazing! Hopefully I will be able to input some values to my battery capacity checker so it can discharge the batteries with arbitrary data without the need to connect it to a PC. Currently it reads the Serial to set the discharge current.Thank you! EDIT: 4 Hours later and really short on blood glucose but managed to make it work using 4 buttons to set the discharge voltage and current and navigate through the setting. It does not look pretty but it works, thanks!
@ivarengel8565
@ivarengel8565 3 года назад
Thanks , super interesting ! Helping me solving issues which i didn't know how to resolve !
@kaissandezmomosadoh723
@kaissandezmomosadoh723 3 года назад
Thanks you so much for all what you are doing. You are the best.
@fifaham
@fifaham 3 года назад
The use of Enum (like in C) and Array[ ] will simplify this design.
@mail87523
@mail87523 3 года назад
THANKS FOR BRILLIANT TUTORIAL !!! VERY USEFUL FOR PROJECTS !!!
@tr3kn3rd
@tr3kn3rd 7 лет назад
Nice! check out neopixel LED strips, could make for a fun topic for a future video :)
@adithmart
@adithmart 6 лет назад
I hope that I can manipulate this into....Count inputs (5 or 10 counts). Then an action (100 steps of a 200 step stepper motor)...Then repeat. It is hard for me as a beginner, to understand the code.. I started writing some simple example code onto paper and that seems to help. I wish that I had more code to Frankenstein from.
@ngulikaquaponik376
@ngulikaquaponik376 4 года назад
This is great to learn about input and buttons control. I would like to know how to create scratch if we use lcd keypad shield?
@ezequielmarino
@ezequielmarino 5 лет назад
Before anything THANKS. I learn much with yours videos. I want to do this, but with one little difference. I need to detect short and long pulse. How do you think that i can do it?
@surenderkumar-yi1ig
@surenderkumar-yi1ig 11 месяцев назад
thank you
@rosewald1987
@rosewald1987 5 лет назад
thank you very much bro,really helpful,GOD BLESS YOU.
@zulfqarali8603
@zulfqarali8603 5 лет назад
Very well structured code. Thanks for the video .
@melickon
@melickon 5 лет назад
Sorry to say, but it is "well structured" compared with other Arduino programers that mostly experts in electronics and not programming. This code shows several bad software design patters. One of them is using a lot of global variables and not using structures/classes to encapsulate data related to one button. Secondly, it is mixing low level part (debouncing) with high level logic. Code uses bytes and ints instead of bits to store flags. It is waste of RAM. Code uses structures like: if (LEDState == 0 ) { LEDState = 1; } else { LEDState = 0; } All this logic can be implemented in only one line: LEDState = LEDState == 0 ? 1 : 0; Or even shorter: LEDState = !LEDState; Bottom line: This code is not well structured because it is hard to take it as it is and adopt slightly different without breaking something.
@gedtoon6451
@gedtoon6451 Год назад
@@melickon please post your improved code.
@sushildamle3449
@sushildamle3449 3 года назад
I am very much impressed with the programming skill you have especially the use of two buttons. Could you guide me as I want to use RELAY (could be 4 channel or as needed) along with 4 buttons. Each button has to be associated with different task(s) for example say Button 1 when pressed changes relay 1 and when repressed relay 1 is brought back to original position. Button 2 when pressed servo 90G rotates to angle 90 degrees and when repressed comes back to 0 degrees. Similarly Button 3 when pressed some other position servo motors operates as above. Could you give the code or guidelines on this issue. I am totally new to electronics, a retired from the field of ceramic industry. Kindly help. Thanks and have a great day ahead.
@davejuliano5348
@davejuliano5348 6 лет назад
Excellent video, very helpful!!
@GiiForce
@GiiForce 6 лет назад
Thank you. Very helpful!
@EEEnthusiast
@EEEnthusiast 6 лет назад
Glad it helped!
@danutdarauta3582
@danutdarauta3582 5 лет назад
Very useful ! All the best for you!! :)
@mb106429
@mb106429 5 лет назад
For the switch case part, could you use an array instead? ..... because all of those case results do the same thing, except for having changes of the number value for the LED brightness....
@simonwinczlav5706
@simonwinczlav5706 7 лет назад
Great thank u for these explanations ! clear and useful :)
@EEEnthusiast
@EEEnthusiast 7 лет назад
Thanks Simon. Any recommendations as to what else you would like to see in the future videos?
@simonwinczlav5706
@simonwinczlav5706 7 лет назад
I take anything as it come, it give's me new ideas ;-)
@JimBeshears
@JimBeshears 7 лет назад
Nice job, thanks for your work!
@EEEnthusiast
@EEEnthusiast 7 лет назад
Thanks Jim!
@SKElectronics
@SKElectronics 7 лет назад
Really help full video. Thanks .
@stephenreeves4898
@stephenreeves4898 3 года назад
Great video, I've learnt a lot, Would this work in the same way with a PCF8574 ?
@jarrod-smith
@jarrod-smith 5 лет назад
Very helpful, thank you. Is there a technical reason why you set (inputFlags[i] = HIGH) upon *releasing* the button, i.e. when (inputState[i] == HIGH) is true? I think I would prefer for that to occur on a (debounced) button *press* so that if you continue to hold down the button, the action has already occurred once ((millis() - lastDebounceTime[i]) > debounceDelay) becomes true. For that behavior, I think I should just set (inputFlags[i] = HIGH) when (inputState[i] == LOW) is true. I tested and that seems to work but I wondered if there is a reason to do it your way besides just preference. Thanks again.
@pklicov
@pklicov 5 лет назад
Shouldn't if statement on line 39 be inputState[i]==LOW, and initial LastinputState=HIGH. With your initial statement codes jumps to flag=HIGH on all input as you are using pullups
@spherebotics
@spherebotics 3 года назад
This fixes the false input on startup problem. thanks!
@tuhoang6609
@tuhoang6609 6 лет назад
Great Video. Thanks
@EEEnthusiast
@EEEnthusiast 6 лет назад
Thank you for the feedback sir! Is there anything else you'd like to see me cover?
@jynkotech
@jynkotech 2 года назад
Hey sir I want to increment with the push button but it is very tedious process let say i want to increment 0 to 50,000 and i will press the button 50,000 times and i search all over the places that how to press a button that increment by it self and when i release it will stop incrementing. Can you guide me or make a code or tutorial? Please sir
@jynkotech
@jynkotech 2 года назад
If any one want to help me
@dalwindersingh5061
@dalwindersingh5061 2 года назад
Line 36 inputState[i] is not initialized Please can you clarify? Thanks
@theman83744
@theman83744 4 года назад
great vid. tnx
@KBera
@KBera 6 лет назад
Shouldn't the lastInputState be initialized to HIGH since you are using pull-up resistor?
@namgyallhawang4128
@namgyallhawang4128 5 лет назад
Dear Vlad I have a project that i want to make for very long time, but it's not so easy, fortunately today I found your Ep. 58 - Arduino Advanced Input & Button Control, Debouncing, Counters & Multitasking. I found this very interesting, because i want a code like your 1st button code, and also i have a request. Could you tell me how can i use the 1st button code in opposite direction for the 2nd button? Opposite function of button 1 for the button 2 for my project of 6 buttons with 9 LEDs 2 buttons for 3 RED LEDs in a row 2 buttons for 3 BLUE LEDs in a row 2 buttons for 3 WHITE LEDs in a row 1st button RED LED is as usual Press one - 1st LED goes to HIGH, rest of the 2nd and 3rd LEDs should remain at LOW press second - 2nd LED also goes to HIGH, and now both 1st and 2nd LEDs should stay at HIGH and press for the third time - 3rd LED also goes to HIGH, and now all 3 LEDs should be at HIGH. 2nd button RED LED. Now this should be in opposite direction Press one - 3rd LED goes to LOW, rest of the 1st and 2nd LEDs remain at HIGH press second - 2nd LED also goes to LOW, and now both 3rd and 2nd LEDs remain at LOW and press for the third time- 3rd LED also goes to LOW, and now all 3 LEDs should be at LOW
@martinspence4783
@martinspence4783 5 лет назад
Hi your lesson is very great i learn a lot but my arduino ide is giving me a lot of problem it when i write const int or int or define button it keep saying button = 2; was not initialize
@FactPulse-f4k
@FactPulse-f4k 6 лет назад
awesome...simply awesome.. very clever….
@HiranChathurangaband
@HiranChathurangaband 4 года назад
thank you !!!!!!
@ztrain10289
@ztrain10289 5 лет назад
is there a way with this same debouncing example to recognize pressing two buttons at the same time?
@taranagnew436
@taranagnew436 6 лет назад
Could you use flags if you're working with 1 button and not 2 and could I do 2 switch cases to write to a LCD screen and read the analog pin A0
@OctainDesign
@OctainDesign 3 года назад
What font is this and how can I change it?
@deathmetallica2nd
@deathmetallica2nd 4 года назад
HI...I made a code kinda same as yours for debouncing and in there I created different functions to be called with onebutton as per the number of pushes. Then I want functions to interrupt in btw as per the number of Pushes. For reference : singleTap() = // executes the following steps etc doubleTap() =// perform some other steps etc. Now, here while singleTap function is being executed, i push double Taps and singleTap function should stop and doubleTap be function must be executed and vice-versa. In short the functions must be independent of each other. I did attach pushbutton as Interrupt so as to read continuously from it to avoid polling reading through the Pushbutton but the program did not perform as expected. How would you make this program?
@MadBrothersRacing
@MadBrothersRacing 6 лет назад
Awesome!!
@benjaminbeckwith1335
@benjaminbeckwith1335 3 года назад
I have the Chinese clone and I love it. I didn't have a lot of money when Arduino was young so I purchased it. Aside from the mild inconvenience of downloading the CH340 driver it has held up well and I've been having a blast with it! Does anyone know if it has he internal 10k resister for each pin?
@cjmendoza8599
@cjmendoza8599 4 года назад
EEEnthusiast sir i dont know how to program because im electronics graduate but i think im asking with the right guy..this is sequence i have 3 LED LED1,LED2 and LED3 and 1 push button 1st press of PB LED1 and LED2 will HIGH then after 5 secs LED1 will stay HIGH and LED2 will go LOW and LED3 will go HIGH and 2nd press of PB all LED will turn it OFF..thats all..thansk for your help...
@matthewgale2575
@matthewgale2575 4 года назад
Do you have any idea why the program thinks that all four buttons are pressed as soon as the code runs? It makes the screen switch starting menus and adjust the starting value
@lionblackifications
@lionblackifications 4 года назад
OMG please tell me if you have solved it, I'm pretty sure that's caused by the initial difference between the input_pull up and the lastInputState [] = {LOW, LOW} on the header. I've been all day trying to justify why this wouldn't happen in the example but it may seem it does.
@kesavanram3657
@kesavanram3657 3 года назад
reading = digitalRead(inputPin[i]); when button is pressed the reading goes LOW. before button press the reading is HIGH due to internal pull up resistor. you globally declared lastInputState[i] to all LOW. at starting i.e., before button press the reading will be HIGH and lastInputState[i] is LOW as globally declared. the if condition (reading!=lastInputState[i]) will work without button press. that is HIGH!=LOW at start of the program. then it will change the flag without button press is it? then if i press the button the reading reads the pin to LOW. and if condition (reading!=lastInputState[i]) is now LOW!=LOW at start. some one help me to understand this.
@dalwindersingh5061
@dalwindersingh5061 2 года назад
I am thing same thing
@dalwindersingh5061
@dalwindersingh5061 2 года назад
I am thinking same way
@VLandrew
@VLandrew 7 лет назад
How do u do the line numbers
@momsuntvserial
@momsuntvserial 6 лет назад
hey, thanks for your tutorial on switches. I have a project where i need to monitor the state change of 36 switches and log it in file with time and date stamp. i have a arduino, and plan to use a mega with 54 i/o. so can you please help me with a code. thanks in advance. rajeev
@patrickmclaughlin6013
@patrickmclaughlin6013 3 года назад
it's a button without delay or bounce
@outssss2171
@outssss2171 7 лет назад
I don't understand any thing
@ser7ser7i
@ser7ser7i 5 лет назад
Just believe yourself and keep on moving then you may appreciate progress. Peace and love.
@poweredbysergey
@poweredbysergey 7 лет назад
Usefull
@EEEnthusiast
@EEEnthusiast 7 лет назад
Thanks Sergey, I checked out some of your videos and I must say I'm pretty impressed. We should do a collab video if you're interested when I'm back in Montreal (I saw that you are from there? I grew up there myself.)
@poweredbysergey
@poweredbysergey 7 лет назад
Thanks, that would be great. But currently I'm on long term (multi ears) assignment in San Francisco. If you will be in San Francisco then let's make join video/project!
@EEEnthusiast
@EEEnthusiast 7 лет назад
I might take you up on that. I'm in LA, so not too far away. Cheers
@UpcycleElectronics
@UpcycleElectronics 6 лет назад
Thanks again. I think you did really well with these two examples on video's 58 and 59. Perhaps you could go a little further into this subject. What I'm working on is fairly fundamental and would work well with these uploads. Perhaps an explanation of my challenges will inspire you to do something along these lines at some point. I'm not asking you to solve my problems here or write my code. I'm just trying to share something I have found challenging as a simple hobbyist and viewer. The issue I had yesterday, and mentioned a few minutes ago on your upload 59, was trying to use someone else's example from Instructables. That example can be found here (no affiliation): www.instructables.com/id/Easy-Arduino-Menus-for-Rotary-Encoders/ I was trying to add a 1602 lcd to his code but had a lot of problems getting it to work. His example is a rotary encoder and menu but the menu is only implemented on the serial monitor. Also, I don't understand how or why he has used a button press timer to 'change modes' or settings. It's like a solution without a problem as far as I understand it. I was really interested in trying to understand the lack of pullup resistors and code delay/debounce he used. I really liked your example with a relatable, real world application in video 59. I am looking to build a similar type of design. I have an old flatscreen TV I tore apart and I am turning into a light box type of overhead bench light. I have a bunch of LED strips I used to replace the CCFL's. I have 3 different types of LEDs, Neutral, Cold, and Warm White. I want to have a small 1602 display and rotary encoder that can control the different White LED colors. I also want to use a few PWM channels to control the main light's output. Ideally I should probably use PWM on all channels but I don't know if that's even possible at this point. Anyways...my point is that I haven't found anyone that explained how to use this combination, a rotary encoder, lcd, and control an output. The output part is fairly easy. I'm using a simple circuit I picked up from Lewis Loflin (another YT CC's website) here (no affiliation): www.bristolwatch.com/ele/tr3.htm I have a bunch of cheap AliEx TIP127's (PNP Darlington[100v/5A]) transistors already so I figured I'd use them. I'm mentioning it because I haven't seen any content that covers these 3 elements together, a rotary encoder, lcd, and versatile switching application. It seems so fundamental, I'm surprised I'm finding it challenging to find an example. My project is probably going to use a temperature sensor and fan along with an attempt at adding a few WS2811 RGB's too but that's not my point here. Another aspect I would really like to understand better is how to make this kind of code modular. Let's say you designed a product with a 4 button interface and the customer decided they want a rotary encoder or touchscreen, how would you write code that could be changed without a complete rewrite? Anyways, those are just some ideas and real world challenges I'm facing as a code noob. Perhaps you'll find some use for such a perspective ;) Thanks for the upload. -Jake
@EEEnthusiast
@EEEnthusiast 6 лет назад
Jake, thank you for the kind comment as well as detailed info about the challenges you're facing. I'm definitely interested in making a detailed tutorial on what you're asking. Could you send me some more info about the final project outcome? I'm not exactly sure what you're trying to do with the LCD, LED and an encoder. Are you just varying the intensity of the LED or am I missing something??
@UpcycleElectronics
@UpcycleElectronics 6 лет назад
EEEnthusiast Sure, no problem :) I'm using 15 meters of neutral white leds, 5 meters of cold white, and 5 meters of warm white. I'm interested in seeing the general "Color Render Index" aka CRI of some cheap led strip lights. A few years ago I built a budget product photography studio for myself professionally. I am interested in creating something for my bench that I might double as a photography light too. I still have a Macbeth color chart laying around somewhere so I should be able to see what parts of the spectrum are missing from these cheap LEDs with a little bit of software. The different led types I'm using should help fill in the gaps. The TV I'm using is an old 42in, so that's a decent size photography light. If you haven't taken a flatscreen TV apart before, the actual LCD is a thin layer on the outside of a stack of several sheets of material. All of these layers are loose and are held together by a frame/clips/screws. Once the entire TV is taken apart, behind the LCD is a thick plastic diffuser and 2 or 3 thin polarized filter sheets. If you remove the outer LCD and reassemble the plastic sheets, diffuser, and TV enclosure your left with a perfect white lightbox. Most TV's people throw out use CCFL's. The one I have had issues and no datasheet for the CCFL/SMPS driver IC. I couldn't get the stupid thing to start up without the main processor board attached. Seriously it was getting stupid. It wasn't a simple enable line or anything. There was a dual smps circuit with 2 separate controllers but with 2 transformers in series. I've never seen anything like that before. I think it needed a considerable load resistance to start up...so... LED strips it is! As far as the different color lights... I was disabled in 2014 riding a bike to work. I play with electronics now just to stay busy and engaged. I built a work bench in my room to make use of what I have available and optimize my time. I prefer to work in an environment that has a 4500-5k white color temperature, but I would prefer to have a 2700-3k warm white light in the evening. Lastly I am looking to run 3 power supplies. I want to use a small 5Volt-ish independent supply for the microcontroller. This supply will always be on, like a standby supply. The other 2 supplies will be controlled via relay. I imagine I will not need to use all of the light's 220 watts (measured) all the time. I'm also barely familiar with what power factor correction is in practice. Building a proper SMPS supply for 12v and 18-20Amps is a bit outside of my comfort zone. I have some cheap Chinese supplies to try, but by building/wiring the thing in a modular way I have some additional options. I have several spare 60Hz mains transformers I could use to build a supply rail if need be. I have one transformer capable of powering the whole system but don't want to use it here. I have several others that could power 1/2 of the system. So if I happen to have noise issues with bench measurements on my scope or whatnot due to my light/feedback harmonics, I should be able to replace the SMPS junk fairly easily with stuff I already have. ... It was a curb side TV, with lots of good spares, and $40 in lights and power supplies so no big deal. I'm more interested in learning code by working on a useful application as I'm not going to start building some trinket from a kid's 'learn to code' book. I'm also trying to use Arduino and slap something together because my bench is torn apart to build this. I'm actually trying to explore PIC's, 8051's, and etching but if I try to build something with any of those here this project is going to turn into weeks or months with how slow I am. ...anyways...the point I was trying to make before was that a rotary encoder and LCD is probably the easiest way to make a human control interface as far as fabrication and practical applications. It's much easier to drill a hole for an encoder than it is to add several buttons on a panel, and make it look nice, at least as far as prototypes and one off hobbyist stuff. By also adding info about high and low side switching of voltages outside of the uC supply rail, your enabling the beginner to do a lot more than what most tutorials show, at least that's been my experience. The more you can explain code in a modular way the more adaptable it becomes and in turn useful to more people. If you want a challenge, the 1602 display is the status quo for sure, but think about how you would use a ST7920 (mono-graphic/5v/serial/128×64) with the same code with simple changes, or how you might use FETs instead of darlingtons in the circuit hardware or even triacs or IGBT's. Last last thing to note.... W/ a rotary encoder i was trying to figure out the whole integer/decimal thing and never found the solution. Getting the dumb thing to output 0-9 on a 1602 seems like more of a pain than it should be imo. I kept getting the full ascii character set instead of numbers like the serial monitor example and didn't understand why. -Jake
@abdulazeez.98
@abdulazeez.98 7 лет назад
First!
@abdulazeez.98
@abdulazeez.98 7 лет назад
Yeah that's true. Actually it's the first time I comment "first" 😂
@EEEnthusiast
@EEEnthusiast 7 лет назад
Cheers!
Далее
Level Up Your Arduino Code: Registers
21:09
Просмотров 184 тыс.
Секрет фокусника! #shorts
00:15
Просмотров 44 млн
How To Debounce Buttons? Seven Best Ways
8:46
Просмотров 8 тыс.
Level Up Your Arduino Code: External Interrupts
18:55
Просмотров 173 тыс.
6 Horribly Common PCB Design Mistakes
10:40
Просмотров 191 тыс.
Arduino Sketch with millis() instead of delay()
14:27
Просмотров 227 тыс.
Level Up Your Arduino Code: Timer Interrupts
17:22
Просмотров 228 тыс.