예제 #1
0
def loop():
  old_first  = False
  old_left   = False
  old_right  = False
  old_last   = False
  index = 0
  
  while True:
    # POLL BUTTONS
    # remember they are inverted
    first  = not GPIO.input(BUTTON_FIRST)
    left   = not GPIO.input(BUTTON_LEFT)
    right  = not GPIO.input(BUTTON_RIGHT)
    last   = not GPIO.input(BUTTON_LAST)
    
    # REPORT ANY CHANGED BUTTONS
    if first != old_first:
      print("FIRST=" + str(first))
      old_first = first
    if left != old_left:
      print("LEFT=" + str(left))
      old_left = left
    if right != old_right:
      print("RIGHT=" + str(right))
      old_right = right
    if last != old_last:
      print("LAST=" + str(last))
      old_last = last
      
      
    # PROCESS HELD BUTTONS IN PRIORITY ORDER
    if first:
      index = 0
      
    elif last:
      index = len(LED_GPIO)-1
      
    elif left:
      if index > 0:
        index -= 1
      
    elif right:
      if index < len(LED_GPIO)-1:
        index += 1

        
    # FLASH PRESENTLY SELECTED LED
    GPIO.output(LED_GPIO[index], True)
    time.sleep(FLASH_TIME/2)
    GPIO.output(LED_GPIO[index], False)
    time.sleep(FLASH_TIME/2)
예제 #2
0
def loop():
    old_first = False
    old_left = False
    old_right = False
    old_last = False
    index = 0

    while True:
        # POLL BUTTONS
        # remember they are inverted
        first = not GPIO.input(BUTTON_FIRST)
        left = not GPIO.input(BUTTON_LEFT)
        right = not GPIO.input(BUTTON_RIGHT)
        last = not GPIO.input(BUTTON_LAST)

        # REPORT ANY CHANGED BUTTONS
        if first != old_first:
            print("FIRST=" + str(first))
            old_first = first
        if left != old_left:
            print("LEFT=" + str(left))
            old_left = left
        if right != old_right:
            print("RIGHT=" + str(right))
            old_right = right
        if last != old_last:
            print("LAST=" + str(last))
            old_last = last

        # PROCESS HELD BUTTONS IN PRIORITY ORDER
        if first:
            index = 0

        elif last:
            index = len(LED_GPIO) - 1

        elif left:
            if index > 0:
                index -= 1

        elif right:
            if index < len(LED_GPIO) - 1:
                index += 1

        # FLASH PRESENTLY SELECTED LED
        GPIO.output(LED_GPIO[index], True)
        time.sleep(FLASH_TIME / 2)
        GPIO.output(LED_GPIO[index], False)
        time.sleep(FLASH_TIME / 2)
예제 #3
0
def loop():
  while True:
    time.sleep(TIME)
    b = GPIO.input(BUTTON)
    if not b:
      print("pressed")
    else:
      print("released")
예제 #4
0
WALLZ = RIVERZ + RIVERWIDTH + 3
thread.start_new_thread(theWall, (arenaPos, WALLZ))

HOLESZ = WALLZ + 5
thread.start_new_thread(theHoles, (arenaPos, HOLESZ))

LEVELS = 3
DIAMONDS = [3,5,9]
TIMEOUTS = [8,30,30]

level = 0
points = 0

mc.postToChat("Press the button to start")
while GPIO.input(BUTTON):
    time.sleep(0.1)

#game loop
while not gameOver:
    
    createDiamonds(arenaPos, DIAMONDS[level])
    diamondsLeft = DIAMONDS[level]
    display.write(str(diamondsLeft))

    start = time.time()
    levelComplete = False

    #level loop
    while not gameOver and not levelComplete:
        pos = mc.player.getTilePos()
예제 #5
0
print "Distance measurement in progress"

GPIO.setup(TRIG,GPIO.OUT)                  #Set pin as GPIO out
GPIO.setup(ECHO,GPIO.IN)                   #Set pin as GPIO in

while True:

  GPIO.output(TRIG, False)                 #Set TRIG as LOW
  print "Waitng For Sensor To Settle"
  time.sleep(2)                            #Delay of 2 seconds

  GPIO.output(TRIG, True)                  #Set TRIG as HIGH
  time.sleep(0.00001)                      #Delay of 0.00001 seconds
  GPIO.output(TRIG, False)                 #Set TRIG as LOW

  while GPIO.input(ECHO)==0:               #Check whether the ECHO is LOW
    pulse_start = time.time()              #Saves the last known time of LOW pulse

  while GPIO.input(ECHO)==1:               #Check whether the ECHO is HIGH
    pulse_end = time.time()                #Saves the last known time of HIGH pulse 

  pulse_duration = pulse_end - pulse_start #Get pulse duration to a variable

  distance = pulse_duration * 17150        #Multiply pulse duration by 17150 to get distance
  distance = round(distance, 2)            #Round to two decimal points

  if distance > 2 and distance < 400:      #Check whether the distance is within range
    print "Distance:",distance - 0.5,"cm"  #Print distance with 0.5 cm calibration
  else:
    print "Out Of Range"                   #display out of range
예제 #6
0
    RTKGPIO.setup(gpio, RTKGPIO.IN)
    #sleep(0.1)

print("Setting up GPIO Ins on the RPi Board")
for gpio in gpios:
    print(gpio)
    RPIGPIO.setup(gpio, RPIGPIO.OUT)

print("Now Testing")
for gpio in gpios:
    print("Testing GPIO%s", str(gpio))
    print("Turning off")
    RPIGPIO.output(gpio, 0)
    sleep(0.1)
    print("Reading input")
    input1 = RTKGPIO.input(gpio)

    print("Turning on")
    RPIGPIO.output(gpio, True)
    sleep(0.1)
    print("Reading input")
    input2 = RTKGPIO.input(gpio)
    if (input1 == 0 and input2 == 1):
        print("GPIO Pin Passed")
    else:
        errorPins.append(gpio)
        print("GPIO Pin Failed")
        print(input1)
        print(input2)
    #sleep(0.1) #Sleep buffers required
예제 #7
0
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
# import RPi.GPIO as GPIO
import anyio.GPIO as GPIO

clearButton = 5

GPIO.setmode(GPIO.BCM)
GPIO.setup(clearButton, GPIO.IN)

ON = False

mc = minecraft.Minecraft.create()

# clears blocks around player.  Great for mining or getting through walls.
def clearNear(x, y, z):
    radius = 20
    mc.setBlocks(x-radius, y-radius, z-radius, x+radius, y+radius+1, z+radius, block.AIR.id)

try:
    while True:
        time.sleep(0.1)
        if GPIO.input(clearButton) == False:
            pos = mc.player.getTilePos()
            clearNear(pos.x, pos.y, pos.z)

finally:
    GPIO.cleanup()
예제 #8
0
display.setup(GPIO, LED_PINS, ON)

mc = minecraft.Minecraft.create()

def bomb(x, y, z):
    size = 10
    mc.setBlock(x+1, y, z+1, block.TNT.id)
    for t in range(6):
        display.write(str(5-t)) # clever countdown
        time.sleep(1)

    # tp player if inside blast radius
    pos = mc.player.getTilePos()
    if pos.x > x-size and pos.x<x+size and pos.y>(y-size/2) and pos.y<y+size and pos.z>z-size and pos.z<z+size:
        # tp player above bomb site
        mc.player.setPos(x,y+size,z)

    mc.postToChat("BANG!")
    mc.setBlocks(x-size, y-(size/2), z-size, x+size, y+size, z+size, block.AIR.id)

try:
    while True:
        time.sleep(0.1)
        if GPIO.input(BUTTON) == False:
            pos = mc.player.getTilePos()
            bomb(pos.x, pos.y, pos.z)

finally:
    GPIO.cleanup()

예제 #9
0
print "Distance measurement in progress"

GPIO.setup(TRIG, GPIO.OUT)  #Set pin as GPIO out
GPIO.setup(ECHO, GPIO.IN)  #Set pin as GPIO in

while True:

    GPIO.output(TRIG, False)  #Set TRIG as LOW
    print "Waitng For Sensor To Settle"
    time.sleep(2)  #Delay of 2 seconds

    GPIO.output(TRIG, True)  #Set TRIG as HIGH
    time.sleep(0.00001)  #Delay of 0.00001 seconds
    GPIO.output(TRIG, False)  #Set TRIG as LOW

    while GPIO.input(ECHO) == 0:  #Check whether the ECHO is LOW
        pulse_start = time.time()  #Saves the last known time of LOW pulse

    while GPIO.input(ECHO) == 1:  #Check whether the ECHO is HIGH
        pulse_end = time.time()  #Saves the last known time of HIGH pulse

    pulse_duration = pulse_end - pulse_start  #Get pulse duration to a variable

    distance = pulse_duration * 17150  #Multiply pulse duration by 17150 to get distance
    distance = round(distance, 2)  #Round to two decimal points

    if distance > 2 and distance < 400:  #Check whether the distance is within range
        print "Distance:", distance - 0.5, "cm"  #Print distance with 0.5 cm calibration
    else:
        print "Out Of Range"  #display out of range
예제 #10
0
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON, GPIO.IN)

mc = minecraft.Minecraft.create()
mc.postToChat("PRESS THE BUTTON!")

def bomb(x, y, z):
	mc.setBlock(x+1, y, z+1, block.TNT.id)

	for a in range(5, 0, -1):
		mc.postToChat(str(a))
		time.sleep(1)
	####countdown.count()

	mc.postToChat("BANG!")
	mc.setBlocks(x-10, y-5, z-10, x+10, y+10, z+10, block.AIR.id)
	####mc.player.setTilePos(x, y+40, z)
	####countdown.bang()

try: 
	while True:
		time.sleep(0.1)
		if GPIO.input(BUTTON) == False:
			pos = mc.player.getTilePos()
			bomb(pos.x, pos.y, pos.z)

finally: 
	GPIO.cleanup()


예제 #11
0
	RTKGPIO.setup(gpio, RTKGPIO.IN)
	#sleep(0.1)

print("Setting up GPIO Ins on the RPi Board")
for gpio in gpios:
	print(gpio)
	RPIGPIO.setup(gpio, RPIGPIO.OUT)

print("Now Testing")
for gpio in gpios:
	print("Testing GPIO%s",str(gpio))
	print("Turning off")
	RPIGPIO.output(gpio,0)
	sleep(0.1)
	print("Reading input")
	input1 = RTKGPIO.input(gpio)

	print("Turning on")
	RPIGPIO.output(gpio,True)
	sleep(0.1)
	print("Reading input")
	input2 = RTKGPIO.input(gpio)	
	if(input1 == 0 and input2 ==1):
		print("GPIO Pin Passed")
	else:
		errorPins.append(gpio)
		print("GPIO Pin Failed")
		print(input1)
		print(input2)
	#sleep(0.1) #Sleep buffers required