Please note that mainloop() costs a lot of performance and is inaccurate. Consider using timer() instead.