def Left(self):

        pfio.digital_write(1,1)

        time.sleep(2)

        pfio.digital_write(1,0)
예제 #2
0
파일: ohpiface.py 프로젝트: 1pilo/openhab
    def handle(self):
        data = self.request[0]
        socket = self.request[1]

        # read the UDP packet into our own object
        packet = UdpPacket().from_network(data)

        # only support digital read/writes
        if packet.command == DIGITAL_WRITE_CMD:
            if verbose:
                print "Digital write request for pin %d -> %d" % (packet.pin, packet.value)
            pfio.digital_write(packet.pin, packet.value)
            response = UdpPacket(DIGITAL_WRITE_ACK, packet.pin)
            socket.sendto(response.for_network(), self.client_address)

        elif packet.command == DIGITAL_READ_CMD:
            if verbose:
                print "Digital read request for pin %d" % packet.pin
            response = UdpPacket(DIGITAL_READ_ACK, packet.pin, pfio.digital_read(packet.pin))
            socket.sendto(response.for_network(), self.client_address)

        elif packet.command == WATCHDOG_CMD:
            if verbose:
                print "Watchdog request"
            response = UdpPacket(WATCHDOG_ACK, packet.pin)
            socket.sendto(response.for_network(), self.client_address)

        else:
            if verbose:
                print "Unknown packet command (%d)" % packet.command
            response = UdpPacket(ERROR_ACK, packet.pin)
            socket.sendto(response.for_network(), self.client_address)
예제 #3
0
파일: bell.py 프로젝트: si2w/pidoorbell
def output(n):
	print "output begin"
	pfio.digital_write(n,1)
	sleep(1)
	pfio.digital_write(n,0)
	sleep(1)
	print "output end"
예제 #4
0
    def Left(self):

        pfio.digital_write(1, 1)

        time.sleep(2)

        pfio.digital_write(1, 0)
예제 #5
0
    def Right(self):

        pfio.digital_write(0, 1)

        time.sleep(2)

        pfio.digital_write(0, 0)
예제 #6
0
    def handle(self):
        data = self.request[0]
        socket = self.request[1]

        # read the UDP packet into our own object
        packet = UdpPacket().from_network(data)

        # only support digital read/writes
        if packet.command == DIGITAL_WRITE_CMD:
            if verbose:
                print "Digital write request for pin %d -> %d" % (packet.pin,
                                                                  packet.value)
            pfio.digital_write(packet.pin, packet.value)
            response = UdpPacket(DIGITAL_WRITE_ACK, packet.pin)
            socket.sendto(response.for_network(), self.client_address)

        elif packet.command == DIGITAL_READ_CMD:
            if verbose:
                print "Digital read request for pin %d" % packet.pin
            response = UdpPacket(DIGITAL_READ_ACK, packet.pin,
                                 pfio.digital_read(packet.pin))
            socket.sendto(response.for_network(), self.client_address)

        elif packet.command == WATCHDOG_CMD:
            if verbose:
                print "Watchdog request"
            response = UdpPacket(WATCHDOG_ACK, packet.pin)
            socket.sendto(response.for_network(), self.client_address)

        else:
            if verbose:
                print "Unknown packet command (%d)" % packet.command
            response = UdpPacket(ERROR_ACK, packet.pin)
            socket.sendto(response.for_network(), self.client_address)
    def Right(self):

        pfio.digital_write(0,1)

        time.sleep(2)

        pfio.digital_write(0,0)
	def on_message(self, message):
		global last_data
		# print '> %s' % message
		pin = int(message)
		state = int(last_data['out'][pin])
		# invert (toggle)
		state = not bool(state)
		pfio.digital_write(pin, state)
예제 #9
0
	def __init__(self, side, enable_pin, forwards_pin, backwards_pin):
		self.side = side
		self.enable_pin = enable_pin
		self.forwards_pin = forwards_pin
		self.backwards_pin = backwards_pin
		self._speed = 0.5
		self.f = 5.0
		
		pfio.digital_write(self.enable_pin, True)
예제 #10
0
 def convert1(self):
     if pfio.read_output():
         pfio.digital_write(1, 0)
         print('LED 1 OFF')
         sleep(0.5)
     else:
         pfio.digital_write(1, 1)
         print('LED 1 ON')
         sleep(0.5)
예제 #11
0
 def do_GET(self):
         try:
                 self.send_response(200)
                 parsed=parse_qs(urlparse(self.path).query)
                 pfio.digital_write(int(parsed['i'].pop()), int(parsed['s'].pop()))
                 rep="C'est fait"
                 self.send_header('Content-Type','text/html')
         except Exception, e:
                 self.send_response(500)
                 self.send_header('Content-Type','text/html')
                 rep="ERROR : "+str(e)
예제 #12
0
	def run(self):
		while not self.stopped():
			if not self.paused():
				total_time = 1/self.f
				on_time = total_time * self.dc
				off_time = total_time - on_time
				pin = self.pin
				pfio.digital_write(pin,True)
				sleep(on_time)
				pfio.digital_write(pin,False)
				sleep(off_time)
예제 #13
0
 def on_message(self,  obj, msg):
     
     rm = self.outputRegex.match( msg.topic )
     
     if rm != None:
         pin = int(rm.group(1))
         #print msg.topic + " - " + msg.payload
         
         if msg.payload == '0':
             pfio.digital_write(pin, 0)
             #print "setting pin %d to %d"%(int(rm.group(1)), 1)
         else:
             pfio.digital_write(pin, 1)
예제 #14
0
def process (cycles, on, unit_mult_on, off, unit_mult_off):
        """ 
            This function contains the actual timing loops and calls to the PiFace firmware.
            It will let the user know how many cycles have been completed by sending an update to the console.
            This function also monitors the contents of "control.txt". Please refer to the doc string in main 
            for details on the operation using "control.txt".
            If a pause of the cycle is invoked locally or via Twitter.com, a counter-clockwise rotating 
            character icon is output to the console.
        """

        from time import sleep
        import piface.pfio as pfio
        pfio.init( )
        controlString = ''
        if cycles > 0:
            count = 1
            for count in range (1, cycles + 1):
                pfio.digital_write(0,1)     # Turn relay 0 / LED 0 ON
                sleep(on * unit_mult_on)     
                                           
                pfio.digital_write(0,0)     # Turn relay 0 / LED 0 OFF
                                            
                sleep(off * unit_mult_off)
                print ('Cycles completed: '+ str(count))
                controlString = str(readFile('control.txt'))
                if controlString == 'STOP':
                    exit (0)
		if controlString == 'PAUSE':
                    print ('Waiting...')
                while controlString == 'PAUSE':
	            sigwait()
                    controlString = str(readFile('control.txt'))

            return
        else:
            count = 0
            while (True):           
                pfio.digital_write(0,1)     # Turn relay 0 / LED 0 ON
                sleep(on * unit_mult_on)           
                                            
                pfio.digital_write(0,0)     # Turn relay 0 / LED 0 OFF
                                            
                sleep(off * unit_mult_off)
                count = count + 1
                print ('Cycles completed: '+ str(count))
                controlString = str(readFile('control.txt'))
                if controlString == 'STOP':
                    exit (0)
		if controlString == 'PAUSE':
                    print ('Waiting...')
                while controlString == 'PAUSE':
                    sigwait()	
                    controlString = str(readFile('control.txt'))
                   
        return
    def Forward(self):

        pfio.digital_write(1,1)

        pfio.digital_write(0,1)

        time.sleep(2)

        pfio.digital_write(1,0)

        pfio.digital_write(0,0)
예제 #16
0
    def Forward(self):

        pfio.digital_write(1, 1)

        pfio.digital_write(0, 1)

        time.sleep(2)

        pfio.digital_write(1, 0)

        pfio.digital_write(0, 0)
def decimalToBinaryConverter(numberToConver):    

    pfio.init()
    binaryListOfNumberToConvert=list(bin(numberToConver))
    binaryListOfBinaryNumber = []
     
    for i in range(len(binaryListOfNumberToConvert)-1, 0, -1):
        if binaryListOfNumberToConvert[i] == 'b':
            break
       
        binaryListOfBinaryNumber.append(binaryListOfNumberToConvert[i])
       
    for i in range(len(binaryListOfBinaryNumber),8):
        binaryListOfBinaryNumber.append(0)
    
    for i in range(7,-1,-1):
        if binaryListOfBinaryNumber[i] == "1":
            pfio.digital_write(i,1)
        else:
            pfio.digital_write(i,0)        	
예제 #18
0
	def stop(self):
		try:	
			self.d.stop()
			self.d = None
		except AttributeError:
			pass
	
		pfio.digital_write(self.enable_pin, False)
		pfio.digital_write(self.forwards_pin, False)
		pfio.digital_write(self.backwards_pin, False)
def ledBlinker(morseCode):
        if len(morseCode) > 0:
                state = False
                for character in morseCode:
                        if character == ";" or character == " ":
                                time.sleep(timer[character])
                        else:
                                pfio.digital_write(0,state)
                                time.sleep(timer[character])
                                print (character)
                                state = not state
                                pfio.digital_write(0,state)
                                time.sleep(timer[character])
                                state = not state
                                pfio.digital_write(0,state)
                                time.sleep(ditDah_space)

                pfio.digital_write(0,False)
                #time.sleep(phrase_space) - Use on future release...

        else:
                ledBlinker(translator(""))
예제 #20
0
def ledBlinker(morseCode):
    if len(morseCode) > 0:
        state = False
        for character in morseCode:
            if character == ";" or character == " ":
                time.sleep(timer[character])
            else:
                pfio.digital_write(0, state)
                time.sleep(timer[character])
                print(character)
                state = not state
                pfio.digital_write(0, state)
                time.sleep(timer[character])
                state = not state
                pfio.digital_write(0, state)
                time.sleep(ditDah_space)

        pfio.digital_write(0, False)
        #time.sleep(phrase_space) - Use on future release...

    else:
        ledBlinker(translator(""))
예제 #21
0
#!/usr/bin/python

# This script flashes output 2 LED's
from time import sleep
import piface.pfio as pfio
pfio.init() # Initialise PiFace #Comment out if used as nested PiFace Script

while(True): # Variable to ensure the script runs indefinatly
  pfio.digital_write (2,1) # LED On
  sleep (0.5) # Wait Time
  pfio.digital_write (2,0) # LED off
  sleep (0.5) # Wait time
예제 #22
0
#!/usr/bin/python

# This script flashes output 2 LED's
from time import sleep
import piface.pfio as pfio

pfio.init()  # Initialise PiFace #Comment out if used as nested PiFace Script

while (True):  # Variable to ensure the script runs indefinatly
    pfio.digital_write(2, 1)  # LED On
    sleep(0.5)  # Wait Time
    pfio.digital_write(2, 0)  # LED off
    sleep(0.5)  # Wait time
예제 #23
0
 def convert4(self):
     print('LED 4 ON')
     pfio.digital_write(4, 1)  #turn on
예제 #24
0
"""The simplest Python script in the world to cycle the piface onboard LEDs"""

import piface.pfio as pfio
from time import sleep
from espeak import espeak


pfio.init()


try:

    espeak.synth(
        "Hello Maddox, this is your robot car brain speaking. I just wanted to say goodnight and I hope my wheels arrive soon. Bye bye from your robot brain"
    )
    while True:
        espeak.synth("Turning the lights on")
        for i in range(1, 9):
            pfio.digital_write(i, True)
            sleep(0.2)

        sleep(1)
        espeak.synth("Turning the lights off")
        for i in range(1, 9):
            pfio.digital_write(i, False)
            sleep(0.2)
        sleep(1)

except KeyboardInterrupt:
    print "Bye..."
예제 #25
0
def close_evsco_valve():
    pfio.init()
    pfio.digital_write(0, 1)
    time.sleep(4)
    pfio.digital_write(0, 0)
예제 #26
0
import random			# for generating the next random button flash

import piface.pfio as pfio			# piface library		


pfio.init()			# initialise pfio (sets up the spi transfers)


def next_colour():
	""" choses a random number between 1 and 5 to represent the coloured leds and their corresponding buttons"""
	return random.randint(1,5)



current = next_colour() 			# create first random colour to be lit
pfio.digital_write(current+2,1)			# turn colour on
set_time = 2000					# time allowed to hit each light (starts off large and reduced after each hit)
time_left = set_time				# countdown timer for hitting the light
hit = 0						# the input value
score = 0					# keep track of the player's score
misses = 0					# keep track of how many the player misses

colours = ["Red","Green","Blue","Yellow","White"]	# colour list for printing to screen
previous_pressed = 255


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


while True:
예제 #27
0
from time import sleep
import piface.pfio as pfio
pfio.init()
pfio.digital_write(3, 1)  # turn on
pfio.digital_write(4, 1)  # turn on
pfio.digital_write(5, 1)  # turn on
sleep(1)
pfio.digital_write(3, 0)  # turn off
#pfio.digital_write(4,0) # turn on
pfio.digital_write(5, 0)  # turn on
sleep(2)
pfio.digital_write(3, 1)  # turn on
pfio.digital_write(4, 0)  # turn on
pfio.digital_write(5, 1)  # turn on
sleep(1)
pfio.digital_write(3, 0)  # turn off
#pfio.digital_write(4,0) # turn on
pfio.digital_write(5, 0)  # turn on
예제 #28
0
red1 = 4
green2 = 5
yellow2 = 6
red2 = 7

green1Time = 5
yellowTime = 2
red1Time = 4
redGreenTime = 1

loop = True

pfio.init()

while (loop):
    pfio.digital_write(green1, 1)
    pfio.digital_write(red2, 1)
    sleep(green1Time)
    pfio.digital_write(green1, 0)
    pfio.digital_write(yellow1, 1)
    sleep(yellowTime)
    pfio.digital_write(yellow1, 0)
    pfio.digital_write(red1, 1)
    sleep(redGreenTime)
    pfio.digital_write(red2, 0)
    pfio.digital_write(green2, 1)
    sleep(red1Time)
    pfio.digital_write(green2, 0)
    pfio.digital_write(yellow2, 1)
    sleep(yellowTime)
    pfio.digital_write(yellow2, 0)
예제 #29
0
파일: tank.py 프로젝트: cs413/Tank
def left(val):
	if val == 3:
		pfio.digital_write(4,0)
		pfio.digital_write(3,1)
	elif val == 4:
		pfio.digital_write(3,0)
		pfio.digital_write(4,1)
	elif val == 0:
		pfio.digital_write(3,0)
		pfio.digital_write(4,0)
	return True
def write_output(i,stan):
	pfio.digital_write(i,stan)
예제 #31
0
 def convert3(self):
     print('LED 3 ON')
     pfio.digital_write(3, 1)  #turn on
예제 #32
0
 def write_output(port, stan):
     pfio.digital_write(port, stan)
예제 #33
0
'''
def read_input(i):
	global stan
	stan = pfio.digital_read(i)
	return stan
'''

def main(argv):
	port = int(argv[1])
		if port > 9:
			print 'No correct value PORT: %d' %port
	stan = int(argv[2])
		if stan > 2:
			print 'No correct value STAN %d' %stan
	pfio.digital_write(port,stan)

def print_usage():
	print '''
	You need two arguments: PORT and stan
	'''	
'''
zakres = range(1,9)
print zakres
for i in zakres:
	stan = read_input(i)
	print "Port nr: %d stan portu: %d " %(i, stan)
	i = i+1
'''
if __name__ == '__main__':
    if len(sys.argv) < 2:
예제 #34
0
 def convert7(self):
     print('LED 7 ON')
     pfio.digital_write(7, 1)  #turn on
예제 #35
0
from time import sleep
import piface.pfio as pfio
pfio.init()
pfio.digital_write(2, 1)  # turn on
예제 #36
0
def exitscript():
    pfio.digital_write(1,0)
    print "Exiting. Thanks for playing!"
    exit()
예제 #37
0
 def convert5(self):
     print('LED 5 ON')
     pfio.digital_write(5, 1)  #turn on
예제 #38
0
# This scrip runs the motor out and then back in again by closing relay output 0
import piface.pfio as pfio # Import PiFace
from time import sleep
pfio.init() # initialise PiFace # Comment out if using as nested script

for x in range (0, 5): # loop x number of times
 pfio.digital_write (0,1) # motor out
 print "button pressed - motor out"
 sleep (1) # hold time
 pfio.digital_write (0,0) # release button
#print "released"
#sleep (3) # wait time
#print "running"
#pfio.digital_write (0,1) # motor stop
#print "button pressed - motor stopped"
#sleep (1) # hold time
#pfio.digital_write (0,0) # release button
#print "move in complete waiting"

#sleep (10) # in dead waiting
#print "waiting"

#pfio.digital_write (0,1) # motor in
#print "button pressed - motor in"
#sleep (1) # hold time
#pfio.digital_write (0,0) # release button
#print "released"
#sleep (4) # wait time
#print "running"
#pfio.digital_write (0,1) # motor stop
#print "button pressed - motor stopped"
예제 #39
0
	def write_output(port,stan):
		pfio.digital_write(port,stan)
예제 #40
0
def write_output(i,stan):
	pfio.digital_write(i,stan)
예제 #41
0
 def convert6(self):
     print('LED 6 ON')
     pfio.digital_write(6, 1)  #turn on
예제 #42
0
def open_evsco_valve():
    pfio.init()
    pfio.digital_write(1, 1)
    time.sleep(4)
    pfio.digital_write(1, 0)
예제 #43
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('-r',
                      '--room',
                      help='check access to this room',
                      dest='roomname',
                      default='room1',
                      action='store')
    parser.add_option('-f',
                      '--forever',
                      help='run forever',
                      dest='runf',
                      default=False,
                      action='store_true')
    (opts, args) = parser.parse_args()
    pfio.init()
    pin = 0
    if (opts.runf == False):
        room = opts.roomname
        ID = RFIDread()
        key = validateUser(str(ID), str(room))
    else:
        while (True):
            roomcount = 0
            ID = RFIDread()
            if validateUser(str(ID), 'room1'):
                roomcount = roomcount + 1
                print "access granted to room1"
                pfio.digital_write(0, 1)
                time.sleep(3)
                pfio.digital_write(0, 0)
            if validateUser(str(ID), 'room2'):
                roomcount = roomcount + 1
                print "access granted to room2"
                pfio.digital_write(1, 1)
                time.sleep(3)
                pfio.digital_write(1, 0)
            if validateUser(str(ID), 'room3'):
                roomcount = roomcount + 1
                print "access granted to room3"
                pfio.digital_write(2, 1)
                time.sleep(3)
                pfio.digital_write(2, 0)
            if roomcount == 3:
                print "Sorry! No access"

    if room == 'room1':
        pin = 0
    elif room == 'room2':
        pin = 1
    elif room == 'room3':
        pin = 2

    if key:
        print "!! Access Granted !!"
        pfio.digital_write(pin, 1)
        time.sleep(3)
        pfio.digital_write(pin, 0)
    else:
        print "Sorry! No access"
예제 #44
0
def on(pin_id):
  global pfio
  pfio.digital_write(int(pin_id), 1)
  state = pfio.digital_read(int(pin_id))
  #print 'Turning pin ' + pin_id + ' ON, state = ' + str(state)
  return "on" if state == 1 else "error"
예제 #45
0
# This scrip runs the motor out and then back in again by closing relay output 0
import piface.pfio as pfio  # Import PiFace
from time import sleep
pfio.init()  # initialise PiFace # Comment out if using as nested script

for x in range(0, 5):  # loop x number of times
    pfio.digital_write(0, 1)  # motor out
    print "button pressed - motor out"
    sleep(1)  # hold time
    pfio.digital_write(0, 0)  # release button
#print "released"
#sleep (3) # wait time
#print "running"
#pfio.digital_write (0,1) # motor stop
#print "button pressed - motor stopped"
#sleep (1) # hold time
#pfio.digital_write (0,0) # release button
#print "move in complete waiting"

#sleep (10) # in dead waiting
#print "waiting"

#pfio.digital_write (0,1) # motor in
#print "button pressed - motor in"
#sleep (1) # hold time
#pfio.digital_write (0,0) # release button
#print "released"
#sleep (4) # wait time
#print "running"
#pfio.digital_write (0,1) # motor stop
#print "button pressed - motor stopped"
예제 #46
0
game = 1  # keep track of game active (1 for active, 0 for game over)
score = 0  # keep track of player's score
screen_output = False  # choice to write colours and cues to the screen

sleep(1)  # let them get their bearings

while game:  # while game in play

    game_round = score + 1

    if screen_output:  # print the round number
        print "\nRound %s!" % game_round

    for i in array:  # for each colour in current sequence (flash the sequence)

        pfio.digital_write(i + 2, 1)  # turn the colour on

        if screen_output:  # print the colour to the screen
            print colours[i - 1]

        sleep(0.5)  # wait to keep the colour showing
        pfio.digital_write(i + 2, 0)  # turn the colour off
        sleep(0.2)  # small break between colours

    sleep(0.4)
    pfio.write_output(
        0xFF)  # signify it is their turn by turning all the LEDs on then off
    sleep(0.3)
    pfio.write_output(0x0)

    if screen_output:
예제 #47
0
print(q1)
print ""

# User inputs answer

ans = raw_input()

if ((ans) == (a1)):
    print "Well done!"
    score = (score) + 1
    led = (score) - 1
    time.sleep(1)
    print "Your score is %i" % (int(score))
    pfio.init()
    pfio.digital_write(led, 1)
    time.sleep(1)
    print ""
else:
    print(f1)
    time.sleep(1)
    score = 0
    pfio.init()
    print ""

# Question 2

print(q2)
print ""

ans = raw_input()
예제 #48
0
def off(pin_id):
  global pfio
  pfio.digital_write(int(pin_id), 0)
  state = pfio.digital_read(int(pin_id))
  #print 'Turning pin ' + pin_id + ' OFF, state = ' + str(state)
  return "off" if state == 0 else "error"
예제 #49
0
LeftBack = 11
RightBack = 5
RightForward = 6

light = False

pan = 1228
tilt = 1278

board.digital[Ppan].mode = SERVO
board.digital[Ptilt].mode = SERVO

board.digital[Ptilt].write(tilt)
board.digital[Ppan].write(pan)

pfio.digital_write(0,1)

@app.route("/")
def hello():
  return "You probably want <a href=/static/rover.html> to control the rover. </a>"

########################## end setup ################

@app.route("/light_on")
def light_on():
  pfio.digital_write(0,1)
  return "light on"

@app.route("/light_off")
def light_off():
  pfio.digital_write(0,0)
예제 #50
0
 #
# Python script to turn off all LEDs
# @Pierre
#
import piface.pfio as pfio
pfio.init()
pfio.digital_write(0,0)
pfio.digital_write(1,0)
pfio.digital_write(2,0)
pfio.digital_write(3,0)
pfio.digital_write(4,0)
pfio.digital_write(5,0)
pfio.digital_write(6,0)
pfio.digital_write(7,0)
pfio.digital_write(8,0)
예제 #51
0
def light_on():
  pfio.digital_write(0,1)
  return "light on"
예제 #52
0
def light_off():
  pfio.digital_write(0,0)
  return "light off"
예제 #53
0
def relayon():
    pfio.digital_write(1,1)
    print "Turning on relay!"
    while True:
        if pfio.digital_read(0) == 0:
            return
예제 #54
0
#
# Python script to wait until certain button is pressed
# returns button pressed and turns on a light to indicate it (for testing) 
# @Pierre
# 
import piface.pfio as pfio

pfio.init()

button = pfio.read_input()
while button == 0:
    button = pfio.read_input()
pin_number = pfio.get_pin_number(button)
pfio.digital_write(0,1)
print pin_number
예제 #55
0
def relayoff():
    pfio.digital_write(1,0)
    print "Turning off relay!"
    while True:
        if pfio.digital_read(1) == 0:
            return
예제 #56
0
파일: simon.py 프로젝트: AndyA/piface
score = 0				# keep track of player's score
screen_output = False			# choice to write colours and cues to the screen


sleep(1) # let them get their bearings

while game:						# while game in play
	
	game_round = score+1				
	
	if screen_output:				# print the round number
		print "\nRound %s!" %game_round
		
	for i in array:					# for each colour in current sequence (flash the sequence)

		pfio.digital_write(i+2,1)		# turn the colour on

		
		if screen_output:			# print the colour to the screen
			print colours[i-1]
			
		sleep(0.5)				# wait to keep the colour showing 
		pfio.digital_write(i+2,0)		# turn the colour off
		sleep(0.2)				# small break between colours
		

	sleep(0.4)
	pfio.write_output(0xFF)				# signify it is their turn by turning all the LEDs on then off
	sleep(0.3)
	pfio.write_output(0x0)
	
예제 #57
0
 def convert2(self):
     print('LED 2 ON')
     pfio.digital_write(2, 1)  #turn on