Shorten Repeating Tasks Statments
Humanoido
Posts: 5,770
repeat
task52
task53
task54
task55
task56
task57
task58
task59
task60
task61
task62
task63
task64
task65
task66
Is there a way to shorten these statements without taking up more resources? Thanks in advance. Humanoido
task52
task53
task54
task55
task56
task57
task58
task59
task60
task61
task62
task63
task64
task65
task66
Is there a way to shorten these statements without taking up more resources? Thanks in advance. Humanoido
Comments
Assuming you have all those tasks the same but doing something slightly different you can declare an array of objects that contain the tasks work and then use a repeat block statement to execute a method in each of the tasks.
Something like this in the top level:
The task object is whatever you want as long as it's "run" method actually returns:
As presented all task run methods do the same thing which is probably not very useful.
You could provide parameters to the run method calls to get them to work on different data or pins or whatever.
Or you could call a "setup" method in each task before you start to configure them.
If your tasks are actually different code you may just have to do it the long winded way.