def __init__(self): devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) self.board = PeriBoard(devs[0]) self.continueZeroCounter = 0 self.maxContinueZeroCounter = 30 self.sendAble = True
def main(): #init for i, dev in enumerate(findDevices()): board = PeriBoard(dev) if rouleteGame(board, 1): print 'True' else: print 'False'
def main(): global game_over,font,score,score_image pygame.init() clock = pygame.time.Clock() display = pygame.display.set_mode(WINDOW_SIZE) pygame.display.set_caption('Squash') game_over = False font = pygame.font.SysFont("monospace", 20) score = 0 score_image = None render_score() ball = Ball(speed=(200,50)) players = [] for i,dev in enumerate(findBoards()): color = PLAYER_COLORS[i % len(PLAYER_COLORS)] board = PeriBoard(dev) players.append(Player(board,color=pygame.Color(color),pos=100,width=150)) print "Player#%d (%s): %s" % (i+1, color, board.getDeviceName()) while not game_over: for event in pygame.event.get(): # process events if (event.type == QUIT) or \ (event.type == KEYDOWN and event.key == K_ESCAPE): game_over = True display.fill(BLACK) # clear screen display.blit(score_image, (10,10)) # draw score for p in players: p.move() # move player p.draw(display) # draw playeer ball.move(1./FPS, display, players) # move ball ball.draw(display) # draw ball pygame.display.update() # redraw the screen clock.tick(FPS) # wait to limit FPS requirement
class RFIDReader(object): board = '' def __init__(self): devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) self.board = PeriBoard(devs[0]) self.continueZeroCounter = 0 self.maxContinueZeroCounter = 30 self.sendAble = True def getInput(self): #return id of card, or 9999 if no input try: inRFID = self.board.getRFID()[0] except USBError: return 9999 if self.sendAble: if inRFID == 0: return 9999 else: self.sendAble = False self.continueZeroCounter = 0 return inRFID else: if self.continueZeroCounter < self.maxContinueZeroCounter: self.continueZeroCounter += 1 return 9999 elif self.continueZeroCounter >= self.maxContinueZeroCounter: self.continueZeroCounter = self.maxContinueZeroCounter self.sendAble = True return 9999
from practicum import findDevices from peri import PeriBoard from time import sleep devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) b = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % b.getVendorName() print "*** Device name: %s" % b.getDeviceName() count = 0 while True: # sleep(1) swu = b.getSwitchUp() swd = b.getSwitchDown() swl = b.getSwitchLeft() swr = b.getSwitchRight() swb = b.getSwitchBomb() light = b.getLight() if swu is True: stateUp = "PRESSED" else: stateUp = "RELEASED" if swd is True:
from practicum import findDevices from peri import PeriBoard from time import sleep devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) b = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % b.getVendorName() print "*** Device name: %s" % b.getDeviceName() count = 0 while True: sleep(0.1) rfid = b.getRFID() print rfid
BGCOLOR = (135, 206, 250) PLAYER_WIDTH = 75 PLAYER_HEIGHT = 100 PLAYER_START_POS = SCREEN_WIDTH / 2 RELOAD_TIME = 300 ##################### BOARD SETUP ####################### minLight = [9999, 9999, 9999] maxLight = [0, 0, 0] if EVENT_MODE == 1: devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) board = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % board.getVendorName() print "*** Device name: %s" % board.getDeviceName() running = 1 print "Adjust min-max light value, press the switch when done." while(running): for i in range(0, 3): light = board.getLight(i) running = not board.getSwitch() if light > maxLight[i]: maxLight[i] = light if light < minLight[i]: minLight[i] = light
from practicum import findDevices from peri import PeriBoard from time import sleep devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) b = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % b.getVendorName() print "*** Device name: %s" % b.getDeviceName() count = 0 while True: sleep(0.5) #b.setLedValue(count) #sw = b.getSwitch() light = b.getLight() temp = b.getTemp() humi = b.getHumi() stage = "" if light > 2*1023/3: stage = "high" elif (light > 1023/3) and (light < 2*1023/3) : stage = "median" else: stage = "low" print "LEDs set to %d | Light value: %s | Temperature: %d^C | Humidity: %d" % (
from practicum import findDevices from peri import PeriBoard devs = findDevices() if len(devs) == 0: print "*** No MCU board found." exit(1) board = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % board.getVendorName() print "*** Device name: %s" % board.getDeviceName() minLight = [9999, 9999, 9999] maxLight = [0, 0, 0] while(1): for i in range(0, 3): light = board.getLight(i) if light > maxLight[i]: maxLight[i] = light if light < minLight[i]: minLight[i] = light print (minLight[0], maxLight[0]), (minLight[1], maxLight[1]), (minLight[2], maxLight[2])
from time import sleep from random import randrange ####################### Edit Here ######################### HOST = '127.0.0.1' # The remote host PORT = 8081 # The same port as used by the server ####################### Edit Here ######################### devs = findDevices() # if len dev == 2 if len(devs) == 0: print "*** No MCU board found." exit(1) b = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % b.getVendorName() print "*** Device name: %s" % b.getDeviceName() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) round = 0 oldLight = False newLight = False oldSwitch = False newSwitch = False checkVal = randrange(1000) # Run after server start s.sendall('JoinGame|' + b.getDeviceName() + '|' + str(checkVal) + '|' + b.getVendorName()) while True :
def main(): for i, dev in enumerate(findDevices()): board = PeriBoard(dev) setALLout(board, 0) setALLin(board, 0)
import pygame, sys, random from practicum import findDevices from peri import PeriBoard from numpy import interp # constant of game screen = pygame.display.set_mode((640, 480)) screen_width = screen.get_width() screen_height = screen.get_height() win_number = 0 devs = findDevices() if len(devs) == 0: print "*** No MCU board found." board = None else: board = PeriBoard(devs[0]) print "*** MCU board found" print "*** Device manufacturer: %s" % board.getVendorName() print "*** Device name: %s" % board.getDeviceName() print "Calibrating board." raw_input("Face the board down then press ENTER...") minLight = board.getLight() print minLight raw_input("Face the board up then press ENTER...") maxLight = board.getLight() print maxLight board.lightRange = (minLight, maxLight)