PRACTICUM: HOW TO BLINK TWO LEDS

ZIP files updated 19 jan 2016

the title of this practicum is a bit of an in-joke, aimed at those of you that have tried to use the Arduino's BLINK example as a starting point for your own program. the short answer is: you can't, it won't work; it can't work. and the problem isn't in the code, and the solution isn't in the Arduino language reference.

the problem with most programming instruction is that no one tells you that you need a strategy to think about what you want the (arduino) machine to do, the broken-down human-logical, metaphorical steps that you must break your task into, that can actually be accomplished with code.

here is a simple assertion with profound implications for novice programmers: you can never, ever, write an effective program using the delay() function that is so common in Arduino examples. delay() is harmful. there is a better way.

the key to thinking about coding for Arduino (or any "real time" event programming) is to explicitly work with time. in the human world time may be complex and subjective, but in a computer it's a nice simple ever-increasing number, a "number line" just as in 3rd grade arithmetic. for the timing of tasks within a computer (such as the ON and OFF actions of a blinking LED) the closest analogy i can think of is a clock on a wall; you glance at it, note the time, add desired elapsed time to that value, and then you await that time to occur.