User manual

SendByte(code,True)
code = GetNextCharacter(code)
time.sleep(delay)
def CharTest(numCycles):
for count in range(numCycles):
rand = random.randint(0,255)
firstChar = GetNextCharacter(rand)
FillScreen(firstChar,0.03)
CharTest(5) #Five screens of characters
3) TIMING IS EVERYTHING
If you are like me, you’ll watch some slow character screens for a while, then remove all
delays to see how zippy it is. You ought to be able to send 60 characters to the display
without any noticable lag, right? In fact, you ought to be able to send 600 characters
without any lag. I was a bit surprised to discover otherwise. Try the following code:
def NumberTest(delay=1):
#show an almost-full screen (60 chars) of each digit 0-9
for count in range(10):
FillChar(ord('0')+count)
time.sleep(delay)
def TimeTest(numCycles=3):
#measures the time required to display 600 characters, sent
#60 characters at a time. The pause between screen displays
#is removed from the reported time.
pause = 0.50
for count in range(numCycles):
startTime = time.time()
NumberTest(pause)
elapsedTime = time.time()-startTime
elapsedTime -= pause*10
print " elapsed time (sec): %.3f" % elapsedTime
TimeTest()
You will need to import the time module for this one. NumberTest will send sixty ‘0’
characters to the screen, then sixty ‘1’ characters, all the way to 9. It will briefly pause
between each set to that you can verify that the numbers displayed correctly. TimeTest
runs this sequence three times, and measures the time for each test to run.
The key to measuring time is the time.time() function. We call it twice: once before and
once after the call to NumberTest. The difference between the two values is the amount of
time that NumberTest took to execute. I run it three times to see the variability: our python
code shares CPU time with other processes, and may take more or less time depending on
what else is running.
The elapsed times will show on your screen. How many seconds does it take? On my
system, a call to NumberTest averages about 4.50 seconds. That’s pretty fast for a human,
but slower than slow for our raspberry pi. Let’s see what we can do to speed it up.