# mPy - demonstrating simple cooperative multitasking
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 010  2025-10-06  initial release

import	time

# ============================== demo ===============================

# print '@' @ 1 Sec
def task1(statics=dict(t=time.ticks_ms())):
    now = time.ticks_ms()
    if time.ticks_diff(now, statics['t']) >= 1000:
        print('@', end='')
        statics['t'] = now


# print '*' @ 0.5 Sec
def task2(statics=dict(t=time.ticks_ms())):
    now = time.ticks_ms()
    if time.ticks_diff(now, statics['t']) >= 500:
        print('*', end='')
        statics['t'] = now


# print '.' @ 0.25 Sec
def task3(statics=dict(t=time.ticks_ms())):
    now = time.ticks_ms()
    if time.ticks_diff(now, statics['t']) >= 250:
        print('.', end='')
        statics['t'] = now

# ========================= main ============================

# main loop executing task1, task2 and task3
def main1():
    try:
        while True:
            task1()
            task2()
            task3()
    except:
        print('\napplication terminated')


# main loop executing task1, task2 and task3
def main2():
    tasks = [task1, task2, task3]
    try:
        while True:
            for task in tasks:
                task()
    except:
        print('\napplication terminated')
        
        
main1()

# ============================== end ===============================
