# cPy - 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.time())):
    now = time.time()							
    if now - statics['t'] >= 1:
        print('@', end='')
        statics['t'] = now


# print '*' @ 0.5 Sec
def task2(statics=dict(t=time.time())):
    now = time.time()								# resolution on mPy is 1 Sec
    if now - statics['t'] >= 0.5:
        print('*', end='')
        statics['t'] = now


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


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

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