示例#1
0
文件: simon.py 项目: AndyA/piface
		while event != 0:					# wait till no buttons pressed
			event = pfio.read_input()	# so a single button press is not read as 2
			sleep(0.001)					# delay
				
		while event == 0:					# wait for any input 
			event = pfio.read_input()
		
		sleep(0.001)						# delay
		pin_number = pfio.get_pin_number(event)			# calculate the input pin
		
		if screen_output:
			print colours[pin_number -1]			# print the colour in sequence to the screen
		
		pfio.digital_write(pin_number+2,1)			# light up the buttons pressed
		
		if event != pfio.get_pin_bit_mask(i):	
			game = 0					# if any wrong buttons were pressed end the game
			break

		else:							# otherwise the correct button was pressed
			previous = event
			event = pfio.read_input()
			
			while previous == event:				# while the button is held down, wait
				previous = event
				event = pfio.read_input()
				
			pfio.digital_write(i+2,0)				# turn the button's LED off
			
			
	sleep(0.4)
示例#2
0
previous_pressed = 255


print "Time left is: %s" %time_left		# notify the player how long they have to hit each flash


while True:

	in_bit_pattern = pfio.read_input() # see if any buttons have been hit
	
	if in_bit_pattern != previous_pressed:		# check this is a new button press
		previous_pressed = in_bit_pattern	# record button press for next time's check

		if in_bit_pattern > 0:

			if in_bit_pattern == pfio.get_pin_bit_mask(current):	# check that only the correct button was hit
			
				pfio.digital_write(current+2, 0)		# turn off hit light
				previous = current
				current = next_colour()				# get next colour
			
				while current == previous:			# ensure differnt colour each time
					current = next_colour()			# get next colour
				
				if ((score + misses) %30) ==29:
					if set_time > 125:
						set_time /= 2			# reduce the time allowed to hit the light
						print "Time left is: %s" %set_time
			
				time_left = set_time				# set the countdown time
			
示例#3
0
            )  # so a single button press is not read as 2
            sleep(0.001)  # delay

        while event == 0:  # wait for any input
            event = pfio.read_input()

        sleep(0.001)  # delay
        pin_number = pfio.get_pin_number(event)  # calculate the input pin

        if screen_output:
            print colours[pin_number -
                          1]  # print the colour in sequence to the screen

        pfio.digital_write(pin_number + 2, 1)  # light up the buttons pressed

        if event != pfio.get_pin_bit_mask(i):
            game = 0  # if any wrong buttons were pressed end the game
            break

        else:  # otherwise the correct button was pressed
            previous = event
            event = pfio.read_input()

            while previous == event:  # while the button is held down, wait
                previous = event
                event = pfio.read_input()

            pfio.digital_write(i + 2, 0)  # turn the button's LED off

    sleep(0.4)
    pfio.write_output(0xFF)  # signify their turn is over
示例#4
0
previous_pressed = 255


print "Time left is: %s" % time_left  # notify the player how long they have to hit each flash


while True:

    in_bit_pattern = pfio.read_input()  # see if any buttons have been hit

    if in_bit_pattern != previous_pressed:  # check this is a new button press
        previous_pressed = in_bit_pattern  # record button press for next time's check

        if in_bit_pattern > 0:

            if in_bit_pattern == pfio.get_pin_bit_mask(current):  # check that only the correct button was hit

                pfio.digital_write(current + 2, 0)  # turn off hit light
                previous = current
                current = next_colour()  # get next colour

                while current == previous:  # ensure differnt colour each time
                    current = next_colour()  # get next colour

                if ((score + misses) % 30) == 29:
                    if set_time > 125:
                        set_time /= 2  # reduce the time allowed to hit the light
                        print "Time left is: %s" % set_time

                time_left = set_time  # set the countdown time