Author:

42 thoughts on “Arduino Event-Based Programming”

  • A good effort, but good God, your on-the-spot coding is a mess. You're better off having the sketch tested before you film.

  • Hello! I think your work is brilliant and I appreciate it. I've been trying to understand your library(Eventually.cpp, Eventually.h).
    And I find something strange…if i say….^_^

    The member function "void EvtContext::addListener(EvtListener *lstn){~~} is strange for me.
    for(int i = 0; i < listenerCount; i++) { // Try to add in empty slot

    if(listeners[listenerCount] == 0) {

    listeners[listenerCount] = lstn;

    return;

    }

    }

    Is the code correct?

  • James Hardiman says:

    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!

  • George Akaniro says:

    I don't understand the logic please. After you added Wasbuttonpushed. I don't understand how the button works, if it stays high after push or goes low after your hand releases. Plz explain

  • TraceguyRune says:

    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 says:

    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.

  • Adrian Rawlings says:

    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.

  • Hi I'm late to the party, I don't understand your first if statement "if(isblinking)" there is no comparison so how does this even compile? And since it did compile, what did the code actually do

  • 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.

  • Byron Watkins says:

    So, how might one update a display, check for serial port activity, etc. that one normally does in 'loop()'?

  • Geoffrey McDermott says:

    Most of the negative comments on this library seem to be from know-it-alls who probably have never had to do amy REAL programming.

  • American Engineering says:

    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.

  • you are over complicating delay() you do know that delay is already a function which probably has been written similar way?

  • Yunus Kurniawan says:

    Programming gui in computer is much more simpler than arduino 😅.
    Just button1_click, button1_pressed, button1_released

  • Also, you declared your unsigned int variable (curtime) inside your loop. Do this at very beginning of your code instead.

  • I dunno … this seems pretty simple to me … and definitely READABLE!

    int debounceMark = 0;
    boolean runBlink = true;

    boolean buttonPressed() {
    boolean pressed = false;
    while (digitalRead(4) == LOW) {
    if ( (millis() – debounceMark) > 50) {
    pressed = true;
    }
    }
    debounceMark = millis();
    return pressed;
    }

    void myDelay (int dely) {
    int start = millis();
    while ((millis() – start) < dely) {
    if(buttonPressed()) { runBlink = !runBlink; }
    }
    }

    void setup() {
    pinMode(4, INPUT_PULLUP); //pin 4 to ground means button pressed
    pinMode(7, OUTPUT); //LED PIN
    }

    void loop() {
    while (runBlink) {
    digitalWrite(7, HIGH);
    myDelay(200);
    digitalWrite(7, LOW);
    myDelay(150);
    }
    myDelay(100);
    }

  • As clear as mud!!
    I was with you until you started messing around with that library. You should have explained what's going on in that library before you introduced it to you main code. What you doing is using interrupts. I notice you code size get much larger

  • Graham Welshpool says:

    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…

  • You're wrong about the delay, C goes from top to bottom when reading code. Your loop function started with your if statement so it'll be ran before Delay and even then delay simple tells the program to just wait, almost like a syetem pause but without user input.

  • I game for days says:

    You don't half to set up the button in code but couldn't you just wire the button in a certain way for that to work

  • Accidental Science says:

    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?

  • https://flprog.ru/en/
    With this program, you can program the controller without knowing the text programming languages,
    but it looks like a drawing of the electronic or electric circuits.

  • Browarus Pierogus says:

    So instead of threads the timer is used. I wonder how the delay() formulas look like under different boards. Normally CPU should not execute any instructions and perform like a sleep() in multithreading apps.

  • Purple Phase says:

    Great job on the video! I appreciated that you typed real-time, versus presenting all the text one page at a time. I'm actually starting to "get" this stuff! Also, really appreciate you passing along your library stuff on github.

  • 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.

  • I'm new to C++ and arduino I was wondering if anyone could help me integrate this library's time listener events to be triggered by a time from a DS3231 instead of the millis function.

  • abner hagelsieb says:

    How can you adjust the blinking intervals? I mean if I want the LED to remind on for longer how would you adjust that?

  • Ultimate Villager says:

    https://learn.adafruit.com/users/adafruit_support_bill This says it all – the absolute best resource for learning how to multi-task with ARDUINO in simple steps with very clear instructions.

  • TAREQ AL HAWSAWI says:

    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

Leave a Reply

Your email address will not be published. Required fields are marked *