First, I'd like to say I don't need multitasking for my current project. But, after looking at a couple threads on the topic in the tutorials section, I appreciate the elegance and am feeling compelled to use that method in my implementation.
Second, I've been an amateur programmer off and on for 33 years. I have little formal training, but I do try to do things "right" within reason. Generally, that means trying to mimic the pros and avoid bad programming habits as I become aware of them. I fail miserably in the end, but the emphasis in on "try". This is my motivation for this question, to write the code for my current project right... whatever that means.
So, by "multitasking" I'm referring to the method where a timer is set to CTC mode and a tick_flag is set at each overflow. I'm sure there are different approaches, but I assume the more commonly used all basically operate via that method? I'm torn between using that approach and what I will call a clock counter method that was my originally intended approach. I have a sense of "I don't like it." It's inelegant. But, I cannot pinpoint exactly why I don't like it. Are there poor practices in using the clock counter approach? If not, I'm inclined to use it but I'd like your input. I'll explain the project briefly, then explain the clock counter code as I haven't written it yet.
Device: ATtiny 85
Output: 3 leds
Inputs: 1 tactile button and 1 PIR sensor
The circuit will be a battery powered remote recording device for pedestrian traffic. By remote, I mean portable. It can be moved and placed anywhere. The circuit may be left in the field for up to a week. Assume sufficient power to run the device for a week. When the circuit is first energized, it starts the clock... like millis() in Arduino (only it's a variable) and runs continuously, incremented via the CTC timer. This clock is the backbone of the code. When the sensor is triggered, the AVR will record the last 20 "hits" in a long array after being converted to minutes. The button will act as a multifunction button by being able to distinguish between a long and a short key press. It's purpose will be to activate the output leds to communicate the time in milliseconds from bootup of each hit. I plan to use multiple "timers" (or tasks if multitasking method is used) for various things that should be obvious but a few are listed below. 3 leds = 8 combinations. I was planning to simply display sequentially, each digit of each value recorded in the long array with a couple flashes between the values for delimiting. Since 3 leds won't handle 10 combinations, I was planning to do a flashing binary 6 and flashing binary 7 to represent 8 and 9 decimal (or similar method).
timing button press
timing the flashing of the leds (on and off)
filtering artifact PIR sensor output (must be active for 100ms to count as a hit)
Each of the timers would require their own long variable. It would be set to the current clock time at some point. For example, the button was just pressed (timer_button = clock_ms +100). In the main loop, compare the timer_button value to clock_ms ( timer_button < clock_ms , then do something ). Remember clock_ms is the number of milliseconds the circuit has been powered up. The main loop would have an if() for each timer to direct program flow. That's pretty much it. I hope it made sense. It seems convoluted to me, but so did the multitasking method the first couple times I saw it.
What I'd like to know is, is there anything inherently wrong with the clock counter method? Does it scream amateur? I hope to learn more about the right way to program by learning why this method would be a poor choice. Is it significantly worse than the multitasking method? Are there better non-multitasking methods that I should consider?
Before suggesting I step up to an atmega, this project is an exercise in designing small. It isn't intended for production. I have some 328's on hand. I also have some shift registers that would make the output better but I am intrigued by minimalist practices and thus I ask you to respond with respect to the parameters of the hardware I've laid out.