Arduino Event-Based Programming

  Рет қаралды 227,780

BP Learning

BP Learning

Күн бұрын

In this inaugural episode of the Tinkerer's Toolbox, I am showing a better way to program Arduinos using the Eventually library. This tutorial shows what is wrong with the traditional method of Arduino programming, and how Eventually can save you from the awful code-mess that plagues all but the simplest Arduino programs.

Пікірлер: 273
@inspiredtiny
@inspiredtiny 4 жыл бұрын
The classic blink code is for those who have no idea in programming or microcontrollers. It is simple enough to be easily understood and have them interested.
@notanigerianprince7011
@notanigerianprince7011 Жыл бұрын
Sometimes, it's also used to test if the device is broken.
@nichtverstehen2045
@nichtverstehen2045 Жыл бұрын
@@notanigerianprince7011 that would be pretty weird way of doing it as it requires extra hardware. you don't need a led stuff to test a device. it's like to test if your car would start you plan a trip making whole family ready for it :)))
@MGL83
@MGL83 4 жыл бұрын
Just use interrupts. It's way simpler. Your event loop thingy makes it way more complicated than it needs to be. The event loop is still polling over all possible events, so you have delays and inneficiencis and possible other timing issues. With interrupts it's 1 line to attach a function to a pin, so the function triggers when button is pressed. Bonus that it works on rising or falling edge, so much less issues with debouncing.
@fallnx3828
@fallnx3828 Жыл бұрын
Interrupts are not viable for everything, the button was example but he was demonstrating the principle
@fjonesjones2
@fjonesjones2 6 жыл бұрын
Being a newbie to programming, it's great to see different methods used, to arrive at a similar basic outcome. Thank you for your time and effort. Nice video mate.
@3dw3dw
@3dw3dw 7 жыл бұрын
That's fantastic. Can't wait to use this library. I want to use a shift registers to scan through the states of various (numerous) inputs from a very few pins on the arduino. I hope eventually will help simplify this process and give my code the elbow room of a c++ environment.
@TraceguyRune
@TraceguyRune 5 жыл бұрын
This may be the answer to my prayers. The one thing I hated about programming for the Arduino vs computer software was everything was stuck in a loop, so button events couldn't be accessed unless the button was pressed at the right time.
@featherbrain7147
@featherbrain7147 5 жыл бұрын
Surely there is nothing stopping you using sub-routines (functions) which are outside Loop? The "main" part of any C program is a loop isn't it? It calls subroutines when things happen.
@RoySATX
@RoySATX 5 жыл бұрын
Well, that was a special treat! I have to admit that I only actually watched the first 90 seconds before opening a new tab and continuing my work. I continued to listen, however, and every so often I would check back in on your video out of curiosity thus inserting delay after delay in my normal workflow, and with each loop came an increase in variables I struggled to fill much less understand. On and on, over and over and over until finally, eyes glazed over, one eyelid slowly blinking, I exited abnormally.
@jwcolby54
@jwcolby54 4 жыл бұрын
You ran out of stack space. 😁
@SusanAmberBruce
@SusanAmberBruce 3 жыл бұрын
Awesome, I just completed a project that's an environment controller for plants, it measures temperature and humidity and switches on a fan, a heater, and lights according to different conditions. I wanted to keep the user interface simple using four buttons and a 1602 display to display time and date aternating with temperature and humidity while no button is pressed, and then on a button press, to go through 13 different menus to set parameters. It's been a real challenge from the point of view of updating the displays and reading and debouncing button presses all in the same loop. Now I have downloaded your library I am planning a rewrite of my code using Eventually, I should now be able to incorporate some new features based on Eventually that will make the project super awesome, so a big thanks.
@taka4059
@taka4059 2 жыл бұрын
Hey, there, any updates? How did it go?
@drumminjeff71
@drumminjeff71 3 жыл бұрын
I absolutely love this code. I'm building a wave maker for an aquarium using this setup and it's working fine. I wanted to add in another pump to run at different times so I created another time listener. The problem is the second time listener I created will not operate at a slower speed than the first operator for some reason. I'm going to post my code eventually but I'm having problems figuring out how to add more time listeners.
@WTF_BBQ
@WTF_BBQ 5 жыл бұрын
Oh god, this went over my head .......
@MGL83
@MGL83 4 жыл бұрын
Don't get discouraged. He made it way too complicated. Just look up interrupts. It's literally 1 line to solve the problem from 1st example.
@tb303wpf1
@tb303wpf1 Жыл бұрын
I was a wizard with Basic and qBasic back when I was in college. That said, it was a long time ago. Switching from Basic to C++ is actually not too difficult. The core control structures and alot of the strings/variables are very similar. It's really awesome to see guys like this show better and more intuitive ways of coding for Arduino specifically. Clearly the OP knows C++ inside and out. This is making my transition to modern coding super fun and exciting for me. Thank you for sharing your knowledge and experience sir. Much appreciated!!! Great video!
@favesongslist
@favesongslist 4 жыл бұрын
I wrote something very similar, integrated with MQTT ; your version has given me food for thought. Well done.
@mj2906
@mj2906 4 жыл бұрын
I think would be great thing if you could make tutorial about creating your eventually library. This would be perfect introduction of concepts for event based programing in others languages like c#.
@BPLearningTV
@BPLearningTV 4 жыл бұрын
That's a great idea! I will try to get that done soon. It would also be good to teach people how to make an Arduino library available.
@mj2906
@mj2906 4 жыл бұрын
Sure, looking forward for it!!!
@variouslifedjak426
@variouslifedjak426 4 жыл бұрын
I would love a video that goes into your library a little more and more examples of usage.
@TatsAndGraphics
@TatsAndGraphics 6 жыл бұрын
Thank you for taking the time to show us the difference between this way and the "old way". For those of us just starting out it really helps.
@bob-ny6kn
@bob-ny6kn 2 жыл бұрын
Using header files and APIs might make YOUR coding "easier" but you lose exact control, increase bloat, slow execution time, and need to learn a one-job set of functions useless in your next project. Start learning as low-level as you can so you know the foundation of what you are building. BTW; in the "old way" we calculated RC time constants to create astable multivibrators using a battery and a few discrete components. We also learned not to make it look like a rat's nest. Neatness counts.
@pperrinuk
@pperrinuk 6 жыл бұрын
Good stuff. Any 'bloat' from using libraries should be cleared out by the compiler, so criticisms about that are irrelevant - if people want the developer to watch every byte, then they should be using assembly language anyway! I see there are a number of event libraries out there, but yours is the first I have looked at and your video shows you are clearly thinking about the right issues and explaining them, so I shall be giving it a whirl. Thanks!
@nuno.picado
@nuno.picado 3 жыл бұрын
Can I like this multiple times? God, clean code is beautiful. I'm starting with Arduino for a personal project, and I was dreading the delay function. For someone used to OOP, this was painful. And then KZbin suggests me this video...
@salehroueimiab2199
@salehroueimiab2199 3 жыл бұрын
Event driven absolutely makes sense here. Thanks for filling the gap!
@jitendracshah
@jitendracshah 4 жыл бұрын
That is the correct way to use it. I use the same technique to do event functions, the advantage is I can change my mind and interrupt the event before its timing finish. Delay puts machine in freeze stage where nothing can be interpreted while event reading is mostly cloak speed and loop dependent.
@dailydriven
@dailydriven Жыл бұрын
You made it a little more complex. It's actually easier then that. But nice to see it a different way. Yes event programming is great. I guess I'll eventually use your method someday. 😆
@Astaldoath
@Astaldoath 7 жыл бұрын
This is so much better than the way arduino uses code, man ive programmed in C and C++ VB , scripting languages and having only a main and a loop function sucks, what about making your own, what if i dont want something looped everytime. Im glad you wrote this library, keep up the grat work
@leeaustex2670
@leeaustex2670 4 жыл бұрын
I think you could take your blink example one step further. replace blinklight() with a blinkOn() and blinkOff() listener, have them call each other, and set false so it only runs once. Then you don't have to keep that blinkState or have the "if" logic that is currently in blinklight()
@JamesHardiman01
@JamesHardiman01 5 жыл бұрын
Brilliant! I've been losing sleep over how to implement this! And I'm glad you took your time explaining it: some of us have brains that have a lower clock cycle than they used to!
@ChrisWilliams-pu8pj
@ChrisWilliams-pu8pj 6 ай бұрын
Thank you! Great video with great functionality!
@Deemooo
@Deemooo 7 жыл бұрын
This could be really helpful for my midi instrument project! Thank you
@jwcolby54
@jwcolby54 4 жыл бұрын
In event driven programming, something raises an event. Zero to N things respond to that event. I think of events like a radio broadcast. The DJ is talking but there can be millions of listeners, or none. Any one who is listening can do whatever they want with the broadcast. A user presses a button on the handle of a white cane, hooked to an arduino. Doing so causes a pin on the arduino to change state, and generates an ev_Btn_Pressed event. The event is "hooked" in various places in an "event handler". Hooking an event simply means that the event handler hook (a function) will be called when the event fires. So... My code hooks the button pressed event and runs logging code, logging the date and time that the button was pressed. That is a valid thing to do when a button is pressed. That is one event handler, and it does some specific thing in response to an event (button pressed). Another event handler hooks the same button pressed event. This event toggles an LED, turning it on if it was off and vv. Notice that these two responses to the button being pressed are not related. Logging the button being pressed doesn't need an led to toggle, and the led toggling doesn't need the button pressed to be logged. I have a third event handler hooking the button pressed event. This event handler pulses an ultrasonic sensor, initiating an external device to try to discover how far away something is. This event handler sets up another event generator. The ultrasonic sensor will raise a pin high when it receives a reflection of the ping. Raising that pin high generates a ev_ping_rcvd event. Zero to N event hooks may or may not respond. IF and only if I hook the event one of my ev_ping_rcvd event handler logs the date / time / distance for the ultrasonic sensor. Another event handler grabs the ev_ping_rcvd event and tells the controller that we are about to crash into a wall, thus the controller vibrates the handle of the cane the blind person is using to move in the world, and generates a tone describing the distance to the wall. Notice that logging the ultrasonic event and vibrating the handle are independent responses to the ev_ping_rcvd event. Neither of them "depends" on the other. As the developer of the cane, I can turn on logging with a boolean and voila, the event handlers which log stuff will magically log the events in the logging event handlers. The other event handlers neither know nor care whether event logging is on. The event logging handlers neither know nor care whether the other activities are happening, or indeed even what those other activities are. OK, so this is a totally made up scenario but it demonstrates how and why we would use events. It demonstrates that events are generated by something, and the events may or may not even be hooked, but if they are, they call one or more event handlers which perform functions logically unrelated to each other. All that said, my problem with the demonstration code in this video is that it was difficult for me (the developer) to figure out how event generation happened. What triggered the event(s) and how do I, the developer, make that happen? Then how do I hook the events that I am setting up to happen? Event driven programming allows me to initialize one or dozens of events to be generated. It then allows me to respond to those events in one or multiple ways. It allows my processor to generate events and respond to events instead of sitting in tight loops reading pins etc. I want this capability. Ping 5 ultrasonic sensors. Go on with what I am doing. When the reflections start to come in, handle each one in an event handler for that sensor. Set up events for proximity sensors. go on with what I am doing. If one of the sensors fires, handle the event. I deal with events if and only if that event actually occurs instead of looping to read whether or not something is happening, or waiting for something to happen. If any given event never occurs, I waste zero time sensing that thing. Yes please.
@thowsawi
@thowsawi 6 жыл бұрын
Thanks a very good explanation for those asking why the not been written before this for make since as the writer explained in line what he is doing and how to think So this is mor about how to develop the code Thanks a lot
@thecombatengineer7069
@thecombatengineer7069 3 жыл бұрын
OR you can just add the interrupt via registers and use 1/4 of the space and time. Less complicated and everything you need to know is in the data sheet. But you worked hard on this and it shows. Today you’re probably kicking yourself
@BPLearningTV
@BPLearningTV 3 жыл бұрын
It's actually not less complicated, especially if you add debouncing. In fact, the library is actually written so that it can piggy-back on interrupts as well. However, it needs rewriting to use function pointers, as C++ objects just kill the memory on those tiny chips. Also thinking about doing this in Go.
@btomas225
@btomas225 3 жыл бұрын
I can see some problems with this scheme and that is the execution time of the listeners themselves and the eventual call of the function as a result of an event. If the events are occurring at a rate that's discernable by eye (blinking led) then the execution time of the library routines will be negligible because the events are occurring relatively slow but if events occur very fast, say in the microseconds or milliseconds then the listeners may have trouble reacting in real time....So they're useful if one keeps that in mind.
@rudolfst
@rudolfst 2 жыл бұрын
Really great library. I'm going to use it tomorrow! Thanks!
@michroz
@michroz 2 жыл бұрын
What I am worrying about is that we basically ignore the very first buttonpress and the whole bunch of the bouncing transitions. We consider the button has been actually pressed only _after_ the bounces are over plus some extra delay to be sure. (So in the hypotetic case when the button contact is poor we could have a significant delay or even miss the button press completely!) However at the very first transition (despite the bouncing that follows) it is _already_ pretty clear the button _has indeed_ been pressed. So we may want to react as soon as possible and only get rid of the _following_ jitter! What I would do is to react immediately on the _first_ transition and then just ignore the following transitions for a certain period of time. Never thought of doing this with a state machine though. Just check for millis() inside the loop.
@semirdzhyan
@semirdzhyan Жыл бұрын
This could come in handy. Thanks.
@thomasweyermann5848
@thomasweyermann5848 4 жыл бұрын
Thank you! This is exactly what I was looking for!!
@leeaustex2670
@leeaustex2670 4 жыл бұрын
Oh, and this looks awesome! I can't wait to try it out!
@lcepeda
@lcepeda 3 жыл бұрын
Hi, Thanks for the great tutorial. I am new to Arduino and as well to C++ code, but after spending about a month watchin tutorials I believe I can learn this fast. Now the reason I comment is not only to say thank you but also want to ask a favor if even possible. I work for a Laser (Optic) company An I have built electronic mechanical stations to check laser stability and save data to an excel file, well I have been thinking about doing the same with Arduino and some codes all I need to do is to check 3 monitors from the laser (voltages in the scale of 0.5VDC to 4VDC) in the 3 monitors I need to set alarms based on the Voltage, e. g (V1 is set a max of 2.2V) if the voltage exceed this number I want to trigger an alarm or else do nothing, when an alarm is triggered I need to be able to identify which event caused the alarm by a code or by turning an led which will be labeled accordingly and so on, same for the other two monitors. all this will also turn a pin off which turns off a relay, the relay will turn the laser of by interrupting a signal, after 1 second will turn a second relay off to turn the housekeeping supply and a third relay will be interrupted the same way to cut main power to the laser. I have pretty much everything documented, so if you or somebody in the group could give me a hand it would be greatly appreciated. Thanks
@dkryptonut
@dkryptonut 4 жыл бұрын
Is there any advantage to using this library over say, using an interrupt? Thanks.
@BPLearningTV
@BPLearningTV 4 жыл бұрын
The primary one is that it merges different types of events (time, pins, and complex events) into a single unified framework that is more intuitive than the standard one. The specific help that you would get compared to an interrupt is automatic debouncing.
@dkryptonut
@dkryptonut 4 жыл бұрын
@@BPLearningTV Great, thanks! I can see how this would be very useful!
@toysareforboys1
@toysareforboys1 4 жыл бұрын
I've been abusing interrupts a lot! I love them! They do exactly what I want when I want. Screw debug. There is no code in my "loop" :)
@KC-vp7wn
@KC-vp7wn 3 жыл бұрын
Very cool! I'm gonna try this on my next project. Thanks for simplifying things!
@mathiaspampus813
@mathiaspampus813 3 жыл бұрын
You mean 'overcomplicating things'... He's obviously doing it wrong in a lot of places, before advertising his library. I just wonder wether he really doesn't know any better, or he does it on purpose, to make the code especially bad...
@agnichatian
@agnichatian 3 жыл бұрын
This is a nice effort. Are you using a different platform these days ?
@ipadize
@ipadize 2 жыл бұрын
i mean, i know that you probably shouldnt use delay but, for "booting" my arduino and display things only once at the start its quite useful.
@AccidentalScience
@AccidentalScience 6 жыл бұрын
May I link your video in the description of a my recent video where I show a event-driven (and RPC) framework originally designed for devices that are slightly different from Arduino? I think your example at the beginning is useful to understand how messy can become programs in sequential execution. By the way, interesting library the one you have made. It seems that your listeners are related to fixed features such as time and input changes, do I have understood correctly?
@nafisahmed6247
@nafisahmed6247 2 жыл бұрын
veterens will eventually not use this, and go to the standard way of writing code. So for professional products a coder will either use freeRtos or the standard baremetal programming.
@kishpawar
@kishpawar 7 жыл бұрын
if( millis() - previous_time >= interval ){ // declare previous time to 0 and interval as you wish in setup previous_time = millis(); //your code here below digitalWrite( 13 , digitalRead( 13 ) ^ 1 ); // To toggle led. } //Use this instead
@errrzarrr
@errrzarrr 6 жыл бұрын
Also, you declared your unsigned int variable (curtime) inside your loop. Do this at very beginning of your code instead.
@94valeRa01
@94valeRa01 4 жыл бұрын
No, it's correct like he wrote it. Try it like ur saying to see why it wont work :) This guy wrote an event library with classes and casts and function pointers.. do you think he'd make that mistake? 😄
@andrewcichetti555
@andrewcichetti555 3 жыл бұрын
@@ParabolicLabs Bingo. "Look, my code is shorter!" and less efficient. This video is all about using as few lines as possible, not efficient (or clear) programming. I'm surprised they didn't put more into libraries to make it even shorter.
@grahamwelshpool3132
@grahamwelshpool3132 6 жыл бұрын
You miss the point the BLINK program is a starter program to help get new users to get using the Arduino . I am nearly 60 years old, my early programming was in machine code. I found the blink program useful to get started with the Uno...
@BPLearningTV
@BPLearningTV 6 жыл бұрын
I actually love blink myself and teach it to my students. The problem is that there is nothing in Arduino that helps you move past blink. People see the simplicity of blink, and they are lured in to thinking that it will all be that simple. However, once they get to the point where you have to have counters and delays and debouncing, then a lot of people just give up. This isn't the "easy-as-blink" system they thought it was. The goal of the library is to make *regulare* Arduino programming more simple. Blink is used as a counterpoint just to show where the limitations of it are, not that people shouldn't use it as a starting program.
@budove58
@budove58 5 жыл бұрын
@@BPLearningTV I agree with what you are saying here. My experience is in Javascript and your video caught my attention as I (as an Arduino newby) was thinking myself that event handlers would be very helpful. I've written some jQuery event handlers myself for some projects and they can be extremely powerful. The basis of what you've done here is great, although I think there is always room for improvement. I would like to see something more object oriented in a future release. Imagine what you could do passing objects to event listeners.
@TraceguyRune
@TraceguyRune 5 жыл бұрын
Agreed. Blink introduces you to: 1. Delays 2. Setting a pin height 3. setting a pin low 4. program flow. 5. program structure.
@EcceBestia
@EcceBestia 3 жыл бұрын
Just stumbled upon this. I'll try it out, eventually 😜. Great work.
@robotikatolye7728
@robotikatolye7728 6 жыл бұрын
you can simply "int tmp = digitalRead(ledpin); somedelay ; digitalWrite(!tmp);
@MusicLife1952
@MusicLife1952 4 жыл бұрын
can you make with a 20x4 lcd?, make a sentence with the button and run the command to turn on the LED, and same command for another LED
@featherbrain7147
@featherbrain7147 5 жыл бұрын
Interesting. Those example programs are for absolute beginners who eventually progress and see that there are better ways. I think that it is good to learn the nuts and bolts first.
@AriesBreath
@AriesBreath 3 жыл бұрын
Hello, I'm new to arduino and I find your library really a life-saver, but I would really like to be able to delete a single listener instead of resetting the entire context (all the listeners), how can I do it?
@CrimFerret
@CrimFerret 4 жыл бұрын
If you want to get even more slick, just do a digitalWrite (5, blinkstate); 'HIGH' and 'LOW' are just constants equating to 1 and 0. You can use 1 and 0 instead and it works just fine.
@StevenMartinGuitar
@StevenMartinGuitar 2 жыл бұрын
Don't even need that, do digitalWrite(5, !digitalRead(5)); Doesn't need the if/else or the state variable then
@fleshTH
@fleshTH 7 жыл бұрын
I like the idea, but the non-event code when completed (minus debounce and not very well optimized) was 3% of storage, but the just the setup for the event code was 5%... without actually doing anything.
@AccidentalScience
@AccidentalScience 6 жыл бұрын
When you are close to zero (3%) it's easy to jump to 2% more, adding antibouncing that would likely take 200 bytes once compiled will bring it to 4%. Even-driven programs have to pay for the burden of the underlying event handling system, but they benefit when the programs become more complex.
@mrdrgonzo
@mrdrgonzo Жыл бұрын
Sorry about the question but I’m completely new to programming, in your eventually demo, you tell it to blink but where in the code is the time which you define the blink timing?
@jaydekaytv
@jaydekaytv Жыл бұрын
Hi, there's a bug in this library. Adding "false" to create a single, no-repeating function call doesn't work. It calls repeatedly (very quickly). Can you please provide some advice on executing a single function call that's delayed? I'm using eventually in a larger project, and have also tested and confirmed this issue by altering the simple blink example included with the library. Thank you.
@bassome3000ify
@bassome3000ify 4 жыл бұрын
This is till to awesome even in 2020, thx BPL for sharing
@WtF-ki9vp
@WtF-ki9vp 4 жыл бұрын
This library has a problem with SHT3X (temperature and humidity sensor) library. It does work sometime but mostly will display 130 C.
@Alfakillen
@Alfakillen 2 жыл бұрын
Nicely done.
@qzorn4440
@qzorn4440 4 жыл бұрын
Geee, i thought the arduino ide would of had the original just getting started theme; to more bells and whistles for advanced programming in C++? nice video and fantastic info...:)
@mystery_1101
@mystery_1101 Жыл бұрын
I love how most people are complaining in the comments. BEFOUR LEARNING THIS, learn the basics of c/c++ and then you'll understand.
@jackdaniel8269
@jackdaniel8269 6 жыл бұрын
Hey, Phew! Are you you trying to dissuade me? Hell, that was a MINDFULLL. But thanks for the knowledge.
@CollinBaillie
@CollinBaillie 3 жыл бұрын
I'll have to check your library. It's definitely conceptually cleaner, but talking about 'all the extra code' is maybe a bit naff if your library basically adds it all back in. I mean, we're working with microcontrollers, code size matters.
@TrueDetectivePikachu
@TrueDetectivePikachu 2 жыл бұрын
I don't know if the thread here is still active... I've been having some issues trying to fire an event right after another event, basically the act of turning on an LED, wait for a moment, then turn it off and turn on another LED of another color. Here's the catch tho, the time where both LEDs are on is different, so it should be two different events right? well, i tried that and what I end up is with two events at the same time. You could say "well use delay()" without realizing that delay will literally freeze the program for a given time and not allow the interruption of the event during the delay. So how can I make two events where one depends on the other to end in order to trigger?
@etmax1
@etmax1 3 жыл бұрын
Thanks, this lack of event programming is why I've never used that Arduino programming system before. Without events it remains a toy. Do you have an example of how to create event type libraries that you would be willing to share?
@NicksStuff
@NicksStuff 7 ай бұрын
Cool but 3 kB to blink an LED, though How does it scale with a more complex program?
@swapnilbandgar8730
@swapnilbandgar8730 3 жыл бұрын
Please help me ::::: I want to start my loop only when my Ultrasound sensor detects the object and if the object is not present then it should directly stop all the operations until the ultrasound sensor detect another (different or same) object
@jimhagan203
@jimhagan203 4 жыл бұрын
HI just watched your video and enjoyed it. I will download the files and try it. Thanks
@jsquaredm
@jsquaredm 2 жыл бұрын
hello BP, you can make your libraries code colored by using a keywords text file and putting it in the libraries folder for arduino
@dawoodips
@dawoodips 3 жыл бұрын
Plz tell me code if I want turn on the buzzer for only 10 seconds after reading then it should off automatically .
@suruzuddin
@suruzuddin 4 жыл бұрын
Event generators are going to eat more clock cycles, continuously, while polling events, that will be bottle neck in performance critical application, in Arduino.
@liboradamec7451
@liboradamec7451 3 жыл бұрын
Is there some method for listening during the running cycle like FOR or WHILE, or it is necessary to use an interrupts on Arduino pins?
@TheEdmaster87
@TheEdmaster87 3 жыл бұрын
Well by using a custom library one can do alot. You still end up sending time to make the library anyway instead of direcly programming. Also using if and else is not the best way to program states IMO. But good to let people know how to avoid delay() at all cost
@americanengineering2063
@americanengineering2063 5 жыл бұрын
at the beginning you talked about the programs needing to be easier to write and more intuitive but you go through a labrynth of writing un necessary junk to accomplish what you did. this could be accomplished with only adding in 5 lines of code to the original blink. set the pinmode. set a pullup. connect the button to any pin and ground. if button low then flip boolean and delay 1 second so if the button is held it wont cycle no faster than 1 per second.
@nichtverstehen2045
@nichtverstehen2045 Жыл бұрын
that is an ancient library that does not use interrupts and timers although it was great for its time. but using it now for modern things makes no any sense. it hijacks loop function and you have no control of what's going on there unless you figure out how to incorporate this library's loop iteration. overall, it's just another way of implementing silly blinking app.
@frankt9156
@frankt9156 Жыл бұрын
So the program can run about a month before it is overflowed ?
@k.chriscaldwell4141
@k.chriscaldwell4141 3 жыл бұрын
For those a bit lost as to what he is doing, learn Python. I learned the basics of Arduino, but it was learning Python that moved me to the next level. I now understand much more about what is involved with Arduino and microprocessor programming because of learning Python. Yes, Arduino programming is C/C++ based, but the easiest way to learn the basics of programming comes via Python. Later, if need be, one can learn more of C/C++.
@nichtverstehen2045
@nichtverstehen2045 Жыл бұрын
learn assembly language if you really want to know what is going on. python hides all the details from you because that's what high-level languages are for - to hide hardware and implementation details.
@gerrekurquidez3044
@gerrekurquidez3044 4 жыл бұрын
I have 2 questions; 1. How do you write a program to create a double click function on the button to have the motor turn a certain amount of degrees, hold it as long as you hold down the button, than rewind back the exact way when you release it? 2. Could and how do you program/solder that circuit into smaller arduino models?
@barryrudolph9542
@barryrudolph9542 7 жыл бұрын
Some constructive criticism. It took 30 minutes to explain something that could have been explained in 5 minutes if you had written your examples prior to making the video and just loading them in side by side windows. Then you could explain why one is not as good as the other and dispense with all the typing in real time.
@BPLearningTV
@BPLearningTV 6 жыл бұрын
Understandable, but typing in real time slows it down for people who are trying to follow. That is, if you are new, and trying to follow a new comment, seeing it typed out can pace your mind to help you follow the concepts better.
@okby8600
@okby8600 6 жыл бұрын
yeah, turned playback speed to x2
@silversurfer1967
@silversurfer1967 5 жыл бұрын
I agree with BP Learning. If you go slow and explain, where one can go wrong, one can understand better
@joedempseysr.3376
@joedempseysr.3376 5 жыл бұрын
Thank you! I was thinking the same thing. I see this noobie error all too often here on KZbin.
@joedempseysr.3376
@joedempseysr.3376 5 жыл бұрын
@@BPLearningTV No!
@byronwatkins2591
@byronwatkins2591 5 жыл бұрын
So, how might one update a display, check for serial port activity, etc. that one normally does in 'loop()'?
@bloodyMind4
@bloodyMind4 4 жыл бұрын
That's beautiful!!! thank you!
@abualis1178
@abualis1178 4 жыл бұрын
A nice video however your program is for intended for different function than blinking an LED, the initial BlinkLed code does the job for its purpose with a couple of lines only, your codes is for a more complex interrupt and event driven function nevertheless many thanks for the session still great and informative.
@SodAlmighty
@SodAlmighty 7 жыл бұрын
You know, given that this event library is intended to reduce code bloat, it sure as hell looks bloaty. Why not use closures? Why not use handles to enable and disable other events? Why tear down the entire edifice when the button is pressed, just to build it back up again afterwards? I've written a few simple event libraries myself, in various languages (C++, Ruby, .NET, Lisp), and yours needs work.
@BPLearningTV
@BPLearningTV 6 жыл бұрын
Closures *can* work, but they were brand new to C++ when I wrote this video. Additionally, closures use extra memory (it creates hidden classes), which you are quite short of in Arduino.
@realsoftgames7174
@realsoftgames7174 5 жыл бұрын
thanks for sharing this ill be looking at implementing it into my project. is there any documentation for this library floating around anywhere i would like to look more into it as i plan on using it as a transmitter/Reciever for an ESK8 Board.
@ElectroMentor
@ElectroMentor 3 жыл бұрын
wonderfully Explained dude all-time best 😍
@Graham1904
@Graham1904 4 жыл бұрын
Looks great but why have you the expression stop Blink in the startBlink function?
@shrikantnikam2426
@shrikantnikam2426 4 жыл бұрын
Is it possible to make millis function in separate tab and use millis single line command like delay? For make code more simpler
@hugofrancisco9823
@hugofrancisco9823 4 жыл бұрын
you could have set a bit high when the input is on than check if output is high/low invert the state and reset bit
@nahidhasan-fh3np
@nahidhasan-fh3np 5 жыл бұрын
Hi i m nahid hasan. Recently i buy a IOT GA6-B mini Gsm module. I face a problem Ardiuno R3 program is Upload but GSM AT Command is Not Response...I don't know Why .....Please Help me to solve this problem....
@kayrizob92
@kayrizob92 4 жыл бұрын
Does this method work to fade an led or run a for loop/ PWM, controlled by a button press?
@adrianrawlings2470
@adrianrawlings2470 5 жыл бұрын
Why isnt this how arduino sketches are introduced to new users? It seems tge traditional way is like saying yiu need to learn Latin before you can learn Englush. Alrhiugh I am sure the techno-trolls will bag me out but it seems to amount to geek snobbery. Looking forward to learning this intuative and straight forward approach. Please keep the videos rolling.
@rubertostutzer
@rubertostutzer 3 жыл бұрын
Congrats! This is very good!
@jrs0007
@jrs0007 4 жыл бұрын
I guess this is for those who already know how to write code
@cadillacescalade5428
@cadillacescalade5428 2 жыл бұрын
Hi. I'm a beginner to arduino an still learning I'm watching videos here on KZbin. But I had a question, if you could help me out on a code/ Sketch I am trying to put together a sketch for a Crossing bell for a Model railroad.
@daleh7062
@daleh7062 3 жыл бұрын
Does anyone know how to program NeoPixel? My daughter is working on a project and this is our first time. Would appreciate if someone knowledgeable could talk with us for a few minutes to help get us started. Many thanks in advance!
@tobiaseaton7049
@tobiaseaton7049 4 жыл бұрын
This program is not completely good, can you show me how to turn off on the LED instantly at the time you click the button? According to this sketch, sometimes I press the button, the LED stop blinking but still on the HIGH state, which is a little annoying. Thank you!
@TraceguyRune
@TraceguyRune 5 жыл бұрын
I am using EvtPinListener with a PULL_UP button. I'm not sure if that is a cause, but the event only actives when I let up on the button. How can I keep the event going as long as I have the button pressed?
@TraceguyRune
@TraceguyRune 5 жыл бұрын
I gave up on the whole event thing. I put everything back into a loop and did my own debounce checks. The current project I'm working on does fine in the loop. Plus, your program was causing my Arduino to crash. It hasn't crashed and is working a lot more efficiently in the plain old loop.
@jjfoerch
@jjfoerch 5 жыл бұрын
Great library! Thanks!
@robm3357
@robm3357 3 жыл бұрын
This was cool Is there anyway to define some variables and then change there value using Ethernet Basically I want to assign a few preset variables and then be able to change them over the internet. Think of a lock code, or codes.... Event driven would be good as there could be locks in use while the variables not in use are changed..... Any thoughts? Thanks Rob
@hairankunhaqaiq8108
@hairankunhaqaiq8108 4 жыл бұрын
can anyone help me in controlling a motor that is for a specific time i want it to turn on and also taking some inputs from sensors to turn it on but specified time period will not affect when it is on due to a sensor output but after sensor is done the specified time period should start whee it ended . Regards
@rgbetanco604
@rgbetanco604 4 жыл бұрын
seems cleaner than the ticker library
@MusicLife1952
@MusicLife1952 4 жыл бұрын
cool,can you make with a 20x4 lcd?, make a sentence with the button and run the command to turn on the LED, and same command for another LED
@Koettnylle
@Koettnylle 3 жыл бұрын
So essentially, timer interrupts?
@taloot123
@taloot123 4 жыл бұрын
high quality class
@oscararguello9009
@oscararguello9009 5 жыл бұрын
it is just fine, great job.
@abnerhagelsieb
@abnerhagelsieb 6 жыл бұрын
How can you adjust the blinking intervals? I mean if I want the LED to remind on for longer how would you adjust that?
@ccv3237
@ccv3237 4 жыл бұрын
Those time numbers are milliseconds ON or OFF (High or Low), so you can easily change those time variables.
Arduino Programming Syntax
9:15
SparkFun Electronics
Рет қаралды 239 М.
拉了好大一坨#斗罗大陆#唐三小舞#小丑
00:11
超凡蜘蛛
Рет қаралды 16 МЛН
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 24 МЛН
АЗАРТНИК 4 |СЕЗОН 1 Серия
40:47
Inter Production
Рет қаралды 1,2 МЛН
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00
Understanding Arduino Interrupts | Hardware, Pin Change & Timer Interrupts
48:17
Handheld BASIC Computer in Badge Format with the Arduino Uno
21:17
element14 presents
Рет қаралды 13 М.
✔ Multitask Arduino with State Machines (& Switch Debouncing)
30:42
Normal Universe - Chris Guichet
Рет қаралды 69 М.
How to do multiple tasks in Arduino | Beginners | millis() function
10:23
Arduino Interrupts Tutorial
9:30
educ8s.tv
Рет қаралды 294 М.
Level Up Your Arduino Code: Registers
21:09
SparkFun Electronics
Рет қаралды 184 М.
Fun with Transistors
24:33
HackMakeMod
Рет қаралды 264 М.
拉了好大一坨#斗罗大陆#唐三小舞#小丑
00:11
超凡蜘蛛
Рет қаралды 16 МЛН