示例#1
0
def flash(t):
  # True puts 3.3 Volts on the pin connected to the LED, the LED goes on
  GPIO.output(LED, True)
  time.sleep(t)
  
  # False puts 0 Volts on the pin connected to the LED, the LED goes off
  GPIO.output(LED, False)
  time.sleep(t)
  print('false')
示例#2
0
def setup():
    GPIO.setmode(GPIO.BCM)
    for l in LED_GPIO:
        GPIO.setup(l, GPIO.OUT)
        GPIO.output(l, False)

    for b in BUTTON_GPIO:
        GPIO.setup(b, GPIO.IN)
示例#3
0
def setup():
  GPIO.setmode(GPIO.BCM)
  for l in LED_GPIO:
    GPIO.setup(l, GPIO.OUT)
    GPIO.output(l, False)

  for b in BUTTON_GPIO:
    GPIO.setup(b, GPIO.IN)
示例#4
0
def loop():
  while True:
    time.sleep(TIME)
    b = GPIO.input(BUTTON)
    if not b:
      print("pressed")
    else:
      print("released")
示例#5
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)
示例#6
0
def init(delay=0.0015):
    global running, StepCount, StepDir, stepsToDo, StepPosition, StepPins
    global StepCounter, Seq, WaitTime
    # Use physical pin numbers
    GPIO.setmode(GPIO.BCM)

    # Define GPIO signals to use
    #  StepPins = [35,36,32,33]   # RoboHat
    StepPins = [4, 17, 27, 18]  # ZeroPoint

    # Set all pins as output
    for pin in StepPins:
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, False)

    # Define pin sequence
    Seq = [[1, 0, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0], [0, 1, 0, 1]]

    StepCount = len(Seq)
    StepDir = 1  # 1 == clockwise, -1 = anticlockwise
    StepsToDo = 0  #number of steps to move
    StepPosition = 0  # current steps anti-clockwise from the zero position

    # Initialise variables
    StepCounter = 0
    WaitTime = delay
    running = True
    # Move pointer to zero position
    StepDir = -1
    stepsToDo = 700
    step()
示例#7
0
def init(delay = 0.0015):
  global running, StepCount, StepDir, stepsToDo, StepPosition, StepPins
  global StepCounter, Seq, WaitTime
  # Use physical pin numbers
  GPIO.setmode(GPIO.BCM)
 
  # Define GPIO signals to use
#  StepPins = [35,36,32,33]   # RoboHat
  StepPins = [4, 17, 27, 18]  # ZeroPoint
 
  # Set all pins as output
  for pin in StepPins:
    GPIO.setup(pin,GPIO.OUT)
    GPIO.output(pin, False)

  # Define pin sequence
  Seq = [[1,0,0,1],
       [1,0,1,0],
       [0,1,1,0],
       [0,1,0,1]]
       
  StepCount = len(Seq)
  StepDir = 1 # 1 == clockwise, -1 = anticlockwise
  StepsToDo = 0 #number of steps to move
  StepPosition = 0 # current steps anti-clockwise from the zero position

  # Initialise variables
  StepCounter = 0
  WaitTime = delay
  running = True
  # Move pointer to zero position
  StepDir = -1
  stepsToDo = 700
  step()
示例#8
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)
示例#9
0
def step():
  global running, StepCounter, stepsToDo
  while running and stepsToDo>0:
    for pin in range(0,4):
      xpin = StepPins[pin]# Get GPIO
      if Seq[StepCounter][pin]!= 0:
        GPIO.output(xpin, True)
      else:
        GPIO.output(xpin, False)   
    StepCounter += StepDir
    if (StepCounter>=StepCount):
      StepCounter = 0
    if (StepCounter<0):
      StepCounter = StepCount + StepDir
    stepsToDo -= 1
    #print stepsToDo
    time.sleep(WaitTime)
  # clear the output pins
  for pin in StepPins:
    GPIO.output(pin, False)
  running = False
示例#10
0
def step():
    global running, StepCounter, stepsToDo
    while running and stepsToDo > 0:
        for pin in range(0, 4):
            xpin = StepPins[pin]  # Get GPIO
            if Seq[StepCounter][pin] != 0:
                GPIO.output(xpin, True)
            else:
                GPIO.output(xpin, False)
        StepCounter += StepDir
        if (StepCounter >= StepCount):
            StepCounter = 0
        if (StepCounter < 0):
            StepCounter = StepCount + StepDir
        stepsToDo -= 1
        #print stepsToDo
        time.sleep(WaitTime)
    # clear the output pins
    for pin in StepPins:
        GPIO.output(pin, False)
    running = False
示例#11
0
文件: led.py 项目: RyanteckLTD/RTk
#TrafficHAT KS Demo
from time import sleep
t = 0.2
import anyio.GPIO as GPIO

RED = 22
YEL = 23
GRN = 24
BUZZ = 5
BUTT = 25

GPIO.setmode(GPIO.BCM)
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(YEL, GPIO.OUT)
GPIO.setup(GRN, GPIO.OUT)
GPIO.setup(BUZZ,GPIO.OUT)
GPIO.setup(BUTT,GPIO.IN)

try:
	while True:
		GPIO.output(RED, True)
		sleep(t)
		GPIO.output(YEL, True)
		sleep(t)
		GPIO.output(GRN, True)
		sleep(2)
		GPIO.output(RED, False)
		sleep(t)
		GPIO.output(YEL, False)
		sleep(t)
		GPIO.output(GRN, False)
示例#12
0
def flash(t):
    GPIO.output(LED, True)
    time.sleep(t)
    GPIO.output(LED, False)
    time.sleep(t)
示例#13
0
#Pibrella Demo
from time import sleep
t = 0.2
import anyio.GPIO as GPIO

RED = 27
YEL = 17
GRN = 4
BUZZ = 18
OUT1 = 22
OUT2 = 23
OUT3 = 24
OUT4 = 25

GPIO.setmode(GPIO.BCM)
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(YEL, GPIO.OUT)
GPIO.setup(GRN, GPIO.OUT)
GPIO.setup(OUT1, GPIO.OUT)
GPIO.setup(OUT2, GPIO.OUT)
GPIO.setup(OUT3, GPIO.OUT)
GPIO.setup(OUT4, GPIO.OUT)

try:
    while True:
        GPIO.output(RED, True)
        sleep(t)
        GPIO.output(YEL, True)
        sleep(t)
        GPIO.output(GRN, True)
        sleep(t)
示例#14
0
from anyio import GPIO
from time import sleep

#Setup
GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

i = 0
try:
    while (i < 10):
        print("Forward")
        GPIO.output(17, 1)
        sleep(1)
        GPIO.output(17, 0)
        print("Backward")
        GPIO.output(18, 1)
        sleep(1)
        GPIO.output(18, 0)
        i = i + 1
finally:
    GPIO.cleanup()
示例#15
0
# Raspberry Pi
#import RPI.GPIO as GPIO
#BUTTON = 4

# Arduino
import anyio.GPIO as GPIO
BUTTON = 24

def setup():
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(BUTTON, GPIO.IN)
  
def loop():
  while True:
    time.sleep(TIME)
    b = GPIO.input(BUTTON)
    if not b:
      print("pressed")
    else:
      print("released")

try:
  setup()
  loop()
finally:
  GPIO.cleanup()

# END

示例#16
0
def flash(t):
  GPIO.output(LED, True)
  time.sleep(t)
  GPIO.output(LED, False)
  time.sleep(t)
示例#17
0
# Test flashing an LED

import time
t = 0.2


# RTk.GPIO
import anyio.GPIO as GPIO

RED = 22
YEL = 23
GRN = 24
BUZZ = 5
BTN = 25

GPIO.setmode(GPIO.BCM)
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(YEL, GPIO.OUT)
GPIO.setup(GRN, GPIO.OUT)


try:
  while True:
	GPIO.output(RED, True)
	time.sleep(t)
	GPIO.output(YEL, True)
	time.sleep(t)
	GPIO.output(GRN, True)
	time.sleep(2)
	GPIO.output(RED, False)
	time.sleep(t)
示例#18
0
import anyio.GPIO as GPIO  #Import GPIO library
import time  #Import time library

GPIO.setmode(GPIO.BCM)  #Set GPIO pin numbering

TRIG = 23  #Associate pin 23 to TRIG
ECHO = 24  #Associate pin 24 to ECHO

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
示例#19
0
def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = data
  # mode = True  for character
  #        False for command

  GPIO.output(LCD_RS, mode) # RS

  # High bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x10==0x10:
    GPIO.output(LCD_D4, True)
  if bits&0x20==0x20:
    GPIO.output(LCD_D5, True)
  if bits&0x40==0x40:
    GPIO.output(LCD_D6, True)
  if bits&0x80==0x80:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()

  # Low bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x01==0x01:
    GPIO.output(LCD_D4, True)
  if bits&0x02==0x02:
    GPIO.output(LCD_D5, True)
  if bits&0x04==0x04:
    GPIO.output(LCD_D6, True)
  if bits&0x08==0x08:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()
示例#20
0
def main():
  # Main program block
  
  #GPIO.setwarnings(False)
  GPIO.setmode(GPIO.BCM)       # Use BCM GPIO numbers
  GPIO.setup(LCD_E, GPIO.OUT)  # E
  GPIO.setup(LCD_RS, GPIO.OUT) # RS
  GPIO.setup(LCD_D4, GPIO.OUT) # DB4
  GPIO.setup(LCD_D5, GPIO.OUT) # DB5
  GPIO.setup(LCD_D6, GPIO.OUT) # DB6
  GPIO.setup(LCD_D7, GPIO.OUT) # DB7


  # Initialise display
  lcd_init()

  while True:

    # Send some test
    lcd_string("RTk.GPIO",LCD_LINE_1)
    lcd_string("16x2 LCD Test",LCD_LINE_2)

    time.sleep(3) # 3 second delay

    # Send some text
    lcd_string("1234567890123456",LCD_LINE_1)
    lcd_string("abcdefghijklmnop",LCD_LINE_2)



    time.sleep(3) # 3 second delay

    # Send some text
    lcd_string("Code by",LCD_LINE_1)
    lcd_string("RPiSPY",LCD_LINE_2)

    time.sleep(3)

    # Send some text
    lcd_string("Wow, Very LCD",LCD_LINE_1)
    lcd_string("Such Magic",LCD_LINE_2)

    time.sleep(3)

   lcd_string("All done on a", LCD_LINE_1)
   lcd_string("Desktop Computer", LCD_LINE_2)
   time.sleep(3)
示例#21
0
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import countdown_mac as countdown

#import RPi.GPIO as GPIO  # Raspberry Pi
import anyio.GPIO as GPIO # Arduino

BUTTON = 4
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)
示例#22
0
# BIG BANG - COUNTDOWN

# Import modules
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
#import RPi.GPIO as GPIO
import anyio.GPIO as GPIO

# GPIO pins on breadboard
BANG    = 15

# Setup
mc = minecraft.Minecraft.create()
GPIO.setmode(GPIO.BCM) # use broadcom GPIO numbers
GPIO.setup(BANG, GPIO.OUT)

pos = mc.player.getTilePos()
mc.setBlock(pos.x+1, pos.y, pos.z, block.GOLD_BLOCK.id)
mc.postToChat("hit that gold block!")

# Main loop
while True:
    time.sleep(0.1)

    # Input Sensing
    bang = False
    events = mc.events.pollBlockHits()
    for e in events:
        pos = e.pos
        b = mc.getBlock(pos.x, pos.y, pos.z)
示例#23
0
#import RPi.GPIO as GPIO
import anyio.GPIO as GPIO
#LED_PINS = [10,22,25,8,7,9,11,15] #Pi
LED_PINS = [7,6,14,16,10,8,9,15]

GPIO.setmode(GPIO.BCM)

ON = False # False = common-anode

for g in LED_PINS:
    GPIO.setup(g, GPIO.OUT)

pattern = [True, True, True, True, True, True, True, False] #ABCDEFG (no decimal point)

for g in range(8):
    if pattern[g]:
        GPIO.output(LED_PINS[g], ON)
    else:
        GPIO.output(LED_PINS[g], not ON)

raw_input("finished?")

GPIO.cleanup()
示例#24
0
#Program that tests each pin of the RTk.GPIO port
#Import the RTk.GPIO Board
import anyio.GPIO as RTKGPIO
#And now the RPi header
import RPi.GPIO as RPIGPIO
import sys
from time import sleep

#Set the modes
RPIGPIO.setmode(RPIGPIO.BCM)
RTKGPIO.setmode(RTKGPIO.BCM)

#
#Define GPIO pins
gpios = [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
#2,3,26 and 27 removed for now
errorPins = []

print("Setting up GPIO Outs on the RTK Board")
#Setup the RPi
for gpio in gpios:
	print(gpio)
	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")
示例#25
0
#TrafficHAT KS Demo
from time import sleep
t = 0.1
import anyio.GPIO as GPIO

gpios = [
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    21, 22, 23, 24, 25, 26, 27
]

GPIO.setmode(GPIO.BCM)
while True:
    for cGPIO in gpios:
        print("Testing GPIO", cGPIO)
        GPIO.setup(cGPIO, GPIO.OUT)
        raw_input("Press enter to continue")
        GPIO.output(cGPIO, 1)
    sleep(1)
    for cGPIO in gpios:
        #sleep(t)
        raw_input("Press enter to continue")
        GPIO.output(cGPIO, 0)
        #sleep(t)
    sleep(1)
示例#26
0
from anyio import GPIO
from time import sleep

#Setup
GPIO.setmode(GPIO.BCM)

GPIO.setup(17,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)

i = 0
try:
	while (i<10):
		print("Forward")
		GPIO.output(17,1)
		sleep(1)
		GPIO.output(17,0)
		print("Backward")
		GPIO.output(18,1)
		sleep(1)
		GPIO.output(18,0)
		i=i+1
finally:
  GPIO.cleanup()
示例#27
0
# testLED.py - 06/06/2014 D.J.Whale
#
# Test flashing an LED

import time
TIME = 0.5

# Raspberry PI
#import RPi.GPIO as GPIO
#LED = 15

# Arduino
import anyio.GPIO as GPIO
LED = 15

GPIO.setmode(GPIO.BCM)
GPIO.setup(LED, GPIO.OUT)

def flash(t):
  GPIO.output(LED, True)
  time.sleep(t)
  GPIO.output(LED, False)
  time.sleep(t)

try:
  while True:
    flash(TIME)
finally:
  GPIO.cleanup()
  
# END
示例#28
0
def cleanup():
    running = False
    time.sleep(1)
    GPIO.cleanup()
示例#29
0
# clears blocks surrounding player for specified radius with button

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()
    self.delayMicroseconds(1)		# commands need > 37us to settle


  def message(self, text):
    """ Send string to LCD. Newline wraps to second line"""

    for char in text:
      if char == '\n':
        self.write4bits(0xC0) # next line
      else:
        self.write4bits(ord(char),True)


if __name__ == '__main__':
  
  gpio.output(2, True)
  
  lcd = CharLCD()

  lcd.clear()
  lcd.message(("\\"*16) + "\n" + ("\\"*16))
  
  sleep(5)
  
  lcd.clear()
  lcd.message("       :)       \n       :)       ")
  
  sleep(3)
  
  lcd.clear()
  lcd.message(("\\"*16) + "\n" + ("\\"*16))
示例#31
0
def setup():
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(BUTTON, GPIO.IN)
示例#32
0
# BIG BANG - COUNTDOWN

# Import modules
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
#import RPi.GPIO as GPIO
import anyio.GPIO as GPIO

# GPIO pins on breadboard
BANG = 15

# Setup
mc = minecraft.Minecraft.create()
GPIO.setmode(GPIO.BCM)  # use broadcom GPIO numbers
GPIO.setup(BANG, GPIO.OUT)

pos = mc.player.getTilePos()
mc.setBlock(pos.x + 1, pos.y, pos.z, block.GOLD_BLOCK.id)
mc.postToChat("hit that gold block!")

# Main loop
while True:
    time.sleep(0.1)

    # Input Sensing
    bang = False
    events = mc.events.pollBlockHits()
    for e in events:
        pos = e.pos
        b = mc.getBlock(pos.x, pos.y, pos.z)
示例#33
0
#Program that tests each pin of the RTk.GPIO port
#Import the RTk.GPIO Board
import anyio.GPIO as RTKGPIO
#And now the RPi header
import RPi.GPIO as RPIGPIO
import sys
from time import sleep

#Set the modes
RPIGPIO.setmode(RPIGPIO.BCM)
RTKGPIO.setmode(RTKGPIO.BCM)

#
#Define GPIO pins
gpios = [
    4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
    24, 25
]
#2,3,26 and 27 removed for now
errorPins = []

print("Setting up GPIO Outs on the RTK Board")
#Setup the RPi
for gpio in gpios:
    print(gpio)
    RTKGPIO.setup(gpio, RTKGPIO.IN)
    #sleep(0.1)

print("Setting up GPIO Ins on the RPi Board")
for gpio in gpios:
    print(gpio)
示例#34
0
#! /usr/bin/python
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import anyio.GPIO as GPIO

blockId = block.CARPET_PINK.id
blockData = block.CARPET_PINK.data
LED_PIN = 9
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)

def drawCarpet(locx, locy, locz, size, blockId, blockData):
	mc.setBlocks(locx + 1, locy, locz + 1, locx + size, locy, locz + size, blockId, blockData)


if __name__ == "__main__":
	mc = minecraft.Minecraft.create()
	orig = mc.player.getTilePos()
	drawCarpet( orig.x, orig.y, orig.z, 3, blockId, blockData)

	try:
		while True:
			time.sleep(2)
			pos = mc.player.getTilePos()
			if pos.x > orig.x and pos.x < orig.x + 3 + 1 and pos.z > orig.z and pos.z < orig.z + 3 + 1:
				print("x="+str(pos.x) + " y="+str(pos.y) + " z="+str(pos.z))
				mc.postToChat("Welcome to the pink carpet!")
				GPIO.output(LED_PIN, True)
			else:
				GPIO.output(LED_PIN, False)
示例#35
0
# testSeg7.py - Test a 7-segment display

import anyio.seg7 as display
import time

# Use this for Raspberry Pi
#import RPi.GPIO as GPIO
#LED_PINS = [10,22,25,8,7,9,11,15]

# Use this for Arduino
import anyio.GPIO as GPIO

LED_PINS = [7, 6, 14, 16, 10, 8, 9, 15]

GPIO.setmode(GPIO.BCM)

ON = False  # common-anode. Set to True for a common cathode display

display.setup(GPIO, LED_PINS, ON)

try:
    while True:
        for d in range(10):
            display.write(str(d))
            time.sleep(0.5)
finally:
    GPIO.cleanup()

# END
示例#36
0
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import anyio.seg7 as display
#import RPi.GPIO as GPIO #pi
import anyio.GPIO as GPIO #arduino

BUTTON = 4
LED_PINS = [10,22,25,8,7,9,11,15] #pi
LED_PINS = [7,6,14,16,10,8,9,15] #arduino

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

ON = False
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)
示例#37
0
# http://eu.wiley.com/WileyCDA/WileyTitle/productCd-111894691X.html
#
# This program tests that you can flash an LED connected to your computer.
# This works on Raspberry Pi, PC and Mac.

# Import necessary modules
import time
#import RPi.GPIO as GPIO     # use this for Raspberry Pi
import anyio.GPIO as GPIO  # use this for Arduino on PC/Mac

# This is the GPIO number that the LED is attached to
# It's not the same as the pin number on the connector though!
LED = 2

# Use Broadcom pin numbering (GPIO numbers, not connector pin numbers)
GPIO.setmode(GPIO.BCM)

# Configure the LED GPIO to be an output, so that you can
# change the voltage on it and thus turn the LED on and off
GPIO.setup(LED, GPIO.OUT)

# Define a function that flashes the LED once
# The 't' variable holds the time to flash for
def flash(t):
  # True puts 3.3 Volts on the pin connected to the LED, the LED goes on
  GPIO.output(LED, True)
  time.sleep(t)
  
  # False puts 0 Volts on the pin connected to the LED, the LED goes off
  GPIO.output(LED, False)
  time.sleep(t)
示例#38
0
import anyio.seg7 as display
#import RPi.GPIO as GPIO        pi

import anyio.GPIO as GPIO
import time

LED_PINS = [7,6,14,16,10,8,9,15]  # arduino
#LED_PINS = [10,22,25,8,7,9,11,15] # pi

GPIO.setmode(GPIO.BCM)

ON = False

display.setup(GPIO, LED_PINS, ON)

try:
    while True:
        for d in range(10):
            display.write(str(d))
            time.sleep(0.25)
        # robin's addition: display letters in letters list
        letters = ['A', 'b', 'C', 'd', 'E']
        for l in letters:
            display.write(l)
            time.sleep(.8)
finally:
    GPIO.cleanup()

示例#39
0
import anyio.GPIO as GPIO                    #Import GPIO library
import time                                #Import time library
GPIO.setmode(GPIO.BCM)                     #Set GPIO pin numbering 

TRIG = 23                                  #Associate pin 23 to TRIG
ECHO = 24                                  #Associate pin 24 to ECHO

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
示例#40
0
#Pibrella Demo
from time import sleep
t = 0.2
import anyio.GPIO as GPIO

RED = 27
YEL = 17
GRN = 4
BUZZ =18
OUT1 =22
OUT2 =23
OUT3 =24
OUT4 =25

GPIO.setmode(GPIO.BCM)
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(YEL, GPIO.OUT)
GPIO.setup(GRN, GPIO.OUT)
GPIO.setup(OUT1,GPIO.OUT)
GPIO.setup(OUT2,GPIO.OUT)
GPIO.setup(OUT3,GPIO.OUT)
GPIO.setup(OUT4,GPIO.OUT)


try:
	while True:
		GPIO.output(RED, True)
		sleep(t)
		GPIO.output(YEL, True)
		sleep(t)
		GPIO.output(GRN, True)
示例#41
0
#Program that tests each pin of the RTk.GPIO port
#Import the RTk.GPIO Board
import anyio.GPIO as RTKGPIO
#And now the RPi header
import RPi.GPIO as RPIGPIO
import sys
from time import sleep

#Set the modes
RPIGPIO.setmode(RPIGPIO.BCM)
RTKGPIO.setmode(RTKGPIO.BCM)

#
#Define GPIO pins
gpios = [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
#2,3,26 and 27 removed for now
errorPins = []

print("Setting up GPIO Outs on the RTK Board")
#Setup the RPi
for gpio in gpios:
	print(gpio)
	RTKGPIO.setup(gpio, RTKGPIO.OUT)
	#sleep(0.1)

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

print("Now Testing")
示例#42
0
def cleanup():
  running = False
  time.sleep(1)
  GPIO.cleanup()
示例#43
0
import mcpi.minecraft as minecraft
import mcpi.block as block
import mcpi.minecraftstuff as minecraftstuff
import time
import random
import thread
import anyio.seg7 as display
import anyio.GPIO as GPIO

BUTTON = 4
LED_PINS = [7,6,14,16,10,8,9,15]

GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON, GPIO.IN)
ON = False # common-anode, set to True for common cathode
display.setup(GPIO, LED_PINS, ON)

#arena constants
ARENAX = 20
ARENAZ = 30
ARENAY = 5
RIVERWIDTH = 6

def createArena(pos):
    mc = minecraft.Minecraft.create()
    pos.x
    mc.setBlocks(pos.x - 1, pos.y, pos.z - 1,
                 pos.x + ARENAX + 1, pos.y - 3,
                 pos.z + ARENAZ + 1, block.GRASS.id)
    mc.setBlocks(pos.x - 1, pos.y + 1, pos.z - 1,
                 pos.x + ARENAX + 1, pos.y + ARENAY, pos.z + ARENAZ + 1,
示例#44
0
#TrafficHAT KS Demo
from time import sleep
t = 0.1
import anyio.GPIO as GPIO

gpios = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]

GPIO.setmode(GPIO.BCM)
while True:
	for cGPIO in gpios:
		print("Testing GPIO", cGPIO);
		GPIO.setup(cGPIO,GPIO.OUT)
		raw_input("Press enter to continue")
		GPIO.output(cGPIO,1)
	sleep(1)
	for cGPIO in gpios:
		#sleep(t)
		raw_input("Press enter to continue")
		GPIO.output(cGPIO,0)
		#sleep(t)
	sleep(1)