Hardware Reference
In-Depth Information
Getting the Code to Do More
Well, that was not very exciting, was it? Let's get the code to do a little more. Take a look at
Listing 3-2:
Listing 3-2: Windows2 Test Program
#!/usr/bin/env python
“””
Window2 to open up a window on the desktop, draw something in it
and read the mouse position upon a click
“””
import piface.pfio as pfio # piface library
import os, pygame, sys
pygame.init() # initialise graphics interface
pfio.init() # initialise pfio
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption(“LED controll”)
screen = pygame.display.set_mode([190,160],0,32)
box = False
def main():
drawBox(box)
while True :
checkForEvent()
def drawBox(state):
boxNum = 0
# first draw the box
# - fill colour depends on sequence bit state
if state :
pygame.draw.rect(screen,(255,0,0),
(50, 70, 40,40), 0)
else :
pygame.draw.rect(screen,(180,180,180),
(50, 70, 40,40), 0)
#now draw the outline of the box
pygame.draw.rect(screen,(0,0,180),(50, 70, 40,40), 3)
pygame.display.update() # refresh the screen
pfio.write_output(state)
def mouseGet() : # see where we have clicked
global box
x,y = pygame.mouse.get_pos()
Search WWH ::




Custom Search