Hardware Reference
In-Depth Information
Listing 15-5 continued
segRect = pygame.Surface.get_rect(segment)
screen.blit(segment, segRect)
segRect.topleft = segSize,0
screen.blit(pygame.transform.flip(segment, True, ;
False), segRect)
segRect.topleft = 0,segSize
screen.blit(pygame.transform.flip(segment, False, ;
True), segRect)
segRect.topleft = segSize,segSize
screen.blit(pygame.transform.flip(segment, True, ;
True), segRect)
pygame.display.update()
#end of main loop
# Function definitions
# read two encoder with alternating 00 11 detent
def readEncoders() : #exit when one has moved
global current_reading, lastPort
moved = False
inc = 6
while not moved :
checkForQuit()
port = pfio.read_input()
portP = (port & 0xc0) >> 6
lastPortP = (lastPort & 0xc0) >> 6
for axis in range(0,2) :
if lastPortP != portP and (lastPortP == 0 or ;
lastPortP == 0x3) :
if (lastPortP == 0 and portP == 0x2) or ;
(lastPortP == 0x3 and portP == 0x1):
current_reading[axis] -= inc
if current_reading[axis] < 0:
# restrain to segment
current_reading[axis] += inc
moved = True
if (lastPortP == 0x3 and portP == 0x2) or ;
(lastPortP == 0 and portP == 0x1):
current_reading[axis] += inc
if current_reading[axis] > segSize:
# restrain to segment
current_reading[axis] -= inc
Search WWH ::




Custom Search