Reputation: 37
I've got a CASIO fx-CG50 with python running extended version of micropython 1.9.4
Decided to make a game but I really need a sleep function, I cannot use any imports as everything is pretty barebones. Any help would be greatly appreciated.
I've tried downloading utilities but they're just extra applications, nothing seems to really exist for the casio.
Cheers!
Upvotes: 1
Views: 726
Reputation: 561
I am trying to do the same exact things and I was trying to benchmark a wait function by animating a square accross the scree. Here is what I have come up width:
from casioplot import *
def wait(milli):
time = milli*50
for i in range(time):
pass
def drawSquare(x,y,l):
for i in range(l):
for j in range(l):
set_pixel(x+j,y+i,(0,0,0))
draw_string(0, 0, "start.", (0, 0, 0,), "small")
show_screen()
waitMillis = 1000
screenWidth = 384
screenHeight = 192
xPos = 0
yPos = 0
squareSide = 24
while xPos + squareSide < screenWidth:
clear_screen()
drawSquare(xPos,yPos,squareSide)
show_screen()
wait(waitMillis)
xPos = xPos + 5
draw_string(int(screenWidth/2), 0, "done", (0, 0, 0,), "small")
show_screen()
So when just using a manual stopwatch app, I noticed that the wait function has a 1 second turnaround time for every 50k iterations. So I set a ratio to the value in order to have a comfortable millisecond parameter. Unfortunately, performance degrade drastically probably do to the drawing utilities and the constant clear and setting of pixels. The performance degradation is exponential and it is hard to capture and control. The square moves well up to half of the screen after which it moves very sluggishly so. I am not sure if we can fix this problem easily...
Upvotes: 0
Reputation: 290
If you cannot import time (or utime) in your code, you could always implement a simple function that loops for a certain number of steps:
def wait(step):
for i in range(step):
pass
wait(999999)
In that case, the actual time spent in the function will depend on the computational power of your device.
Upvotes: 1