SoftTimer library

Dear Arduino Friends,

I proudly introduce you my latest work, the SoftTimer Arduino library.

This is not just an other multitasking/time-sharing implementation, but also a new way of programing Arduino. In this case you do not implement the "loop()" function, instead you can focus on the tasks need to be done by the software.
Please visit the project page at: Google Code Archive - Long-term storage for Google Code Project Hosting.

Furthermore SoftTimer comes with a lot of useful tools like software PWM, blinking helper, debouncer, melody player, etc. These function always made trouble by blocking the program. But not any more with SoftTimer.

I'm really excited what you think about my idea.
Please feel free to download the library, and share your opinion with me! Thanks!

Best regards,
Balazs

Nice lib, really useful,
did not dive in the details yet how it is implemented.

some questions came up:

  • how do you handle interrupts in this model?

  • if a task is running and another 'alarms' is it started or delayed?

  • how to handle user input? (serial?

  • what can i do with the *Me pointer?

Dear Balazs

I am new to arduino. I am trying to make an electronic football scoreboard. It is meant to be operated using an LCD screen and five buttons as digital inputs. I have managed to code the LCD side of things but I am having some difficulty coding the timer. Your library seems be the perfect answer to the problems I am having with the timer part of the code.

Attached is flow diagram showing what the LCD screen shows and what the seven segments are suppose to do.

I am basically trying to use four variables:
start_time
match_length
end_time
injury_time

An additional variable called match_stage is used to determine if the match is in first half or first half injury or second half or second half injury or penalties.
I want to drive the timer variables using the following logic:

if match_stage is first half then
start_time = 0
end_time = match_length / 2
set injury_time to user entered value
if injury_time value is greater than 1 then
start_time = injury_time
end_time = 0

At the end of injury count down or if injury_time = 0
match_stage = second half

if match_stage is second half then
start_time = match_length / 2
end_time = match_length
set injury_time to user entered value
if injury_time value is greater than 1 then
start_time = injury_time
end_time = 0

Could you please give me some direction as to how can I use your library to achieve this.

LCD Menu flow diagram w Seven Segment Output.pdf (563 KB)

tyousaf:
Dear Balazs

I am new to arduino. I am trying to make an electronic football scoreboard. It is meant to be operated using an LCD screen and five buttons as digital inputs. I have managed to code the LCD side of things but I am having some difficulty coding the timer. Your library seems be the perfect answer to the problems I am having with the timer part of the code.

Attached is flow diagram showing what the LCD screen shows and what the seven segments are suppose to do.

I am basically trying to use four variables:
start_time
match_length
end_time
injury_time

An additional variable called match_stage is used to determine if the match is in first half or first half injury or second half or second half injury or penalties.
I want to drive the timer variables using the following logic:

if match_stage is first half then
start_time = 0
end_time = match_length / 2
set injury_time to user entered value
if injury_time value is greater than 1 then
start_time = injury_time
end_time = 0

At the end of injury count down or if injury_time = 0
match_stage = second half

if match_stage is second half then
start_time = match_length / 2
end_time = match_length
set injury_time to user entered value
if injury_time value is greater than 1 then
start_time = injury_time
end_time = 0

Could you please give me some direction as to how can I use your library to achieve this.

He gives a couple of good examples with his code and it is fairly easy to understand how to put it together.

Essentially this is designed to take you away from having to sprinkle delay(); statements everywhere and hence have the Arduino "idle" and do nothing.

it takes a little to wrap your head around at first as things no longer happen in a linear fashion - so if you are used to writing output to an LCD screen and it just scrolling down as more text is added then you need to be careful.

What i initially did when converting my code was to take each of the functions that i had previously written and called from the Loop() and instead called each of them with a timer.

So if i wanted to take a temperature measurement every 30 seconds then put a call to that in a timer. Where is gets tricky is if something else is going to operate on the output of that function (say something that would average the temperature readings when they are taken) - in that case you need to put a little more thought into how those two functions would work together

Craig

Some questions came up:

1- how do you handle interrupts in this model?
2- if a task is running and another 'Alarms', is it started or delayed?
3- how to handle Serial?
4- what is the Task *Me pointer?

My guesses:

1- I assume you setup the interrupt in setup(), and define an interrupt routine?
2- I guess it's delayed.
3- Serial can be called within the Task routine?
4- ?

I really liked your Library! What happened? Can you answer our questions?

Sorry I didn't have received notifications about your questions. But as I still develop my library, you may still interrested in the answers.

1- how do you handle interrupts in this model?
2- if a task is running and another 'Alarms', is it started or delayed?
3- how to handle Serial?

Interrupts are just happens. I do not modify any interrupt configuration in the Arduino. No hardware is involved in my solution, everything is implemented in the software.
Generally say, when a hardware interrupt occurred, the processor "stops" at that point and the interrupt handler is called. After the handler finished, the program is resumed. This is why we must exit the interrupt handler as soon as possible, and mark the potentially modifiable variables with "volatile".

SoftTimer does not operate with software interrupts. We have tasks. Tasks are invoked after each other, at the time they are scheduled to run.

4- what is the Task *Me pointer?

This is a technical thing. It turns out that it is very hard to program nice object oriented code in Arduino, because we are not recommended to dynamically create objects. This is why I like to add the pointer pointing to the actual object "me" in the callback signature.

Hi Balázs, could you help me out please?

Your library runs fine on Arduino IDE 1.6.5 (under windows 10), but both on 1.6.13 and 1.8.0, when I try to compile the SoftTimer1Task example, I get the "CallBack1 was not declared in this scope message".

istadniy:
Hi Balázs, could you help me out please?

Your library runs fine on Arduino IDE 1.6.5 (under windows 10), but both on 1.6.13 and 1.8.0, when I try to compile the SoftTimer1Task example, I get the "CallBack1 was not declared in this scope message".

Here's the solution:

Thank you