01: Event-Driven Programming

    Procedural Code

    Consider the example in the Digital Output tutorial with the blinking LED. The code for this example was written in a procedural way:

    1. Set the output pin to the current state of the LED
    2. Flip the current state of the LED
    3. Wait for 1 second
    4. Goto step 1

    This code is very straightforward for simple models.

    Thought Experiment

    How would you write a program to blink two LEDs at different rates, e.g. with periods 1000ms and 1100ms?

    • What if you had three LEDs with periods of 1000ms, 1100ms, and 1110ms?  Would your algorithm still work
    • What if you had an unknown number of LEDs, each with an unknown period? Would your algorithm still work?

    Event-Driven Code

    External Example

    For another example of how to accomplish blinking without using the delay function, see the Blink Without Delay example on Arduino.cc.

    Tag page (Edit tags)
    • No tags
    Pages that link here
    Page statistics
    5672 view(s), 36 edit(s) and 1531 character(s)


    You must login to post a comment.

    Attach file