Shop OBEX P1 Docs P2 Docs Learn Events
Shorten Repeating Tasks Statments — Parallax Forums

Shorten Repeating Tasks Statments

HumanoidoHumanoido Posts: 5,770
edited 2010-09-02 03:34 in Propeller 1
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

Comments

  • Heater.Heater. Posts: 21,230
    edited 2010-09-02 03:34
    I'm sure we have discussed this before.

    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:
    OBJ
       task[10] : "task"          'An array of task objects
    
    PUB start | t
        repeat                    'Loop forever
            repeat t from 0 to 9  'Loop through all task objects
                task[t].run       'Execute the run method of each task
    

    The task object is whatever you want as long as it's "run" method actually returns:
    pub run
        'Do task work here
        return
    

    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.
Sign In or Register to comment.