示例#1
0
def checkbuttons():
        if pfio.digital_read(0) == 1:
            relayon()
        elif pfio.digital_read(1) == 1:
            relayoff()
        elif pfio.digital_read(2) == 1:
            exitscript()
def ButtonPressed(x):
    pfio.init()
    pressed = pfio.digital_read(x)
    while(pressed!=1):
        pressed = pfio.digital_read(x)
    if(pressed==1):
        return True 
def pedestrianCrossing():
        #waits for input from piface
        while True:
                if(piface.digital_read(portsIn[0])):
                        send("1")
                        print "North-South"
                        sleep(0.5)

                elif(piface.digital_read(portsIn[1])):
                        send("2")
                        print "East-West"
                        sleep(0.5)
示例#4
0
def monitor_pin(pin, value, sock, port):
    latest = pfio.digital_read(pin)
    if latest != value:
        if (verbose):
            print "Pin %d changed to %d" % (pin, latest)
        send(pin, latest, sock, port)
    return latest
示例#5
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)
示例#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)
示例#7
0
文件: ohpiface.py 项目: 1pilo/openhab
def monitor_pin(pin, value, sock, port):
    latest = pfio.digital_read(pin)
    if latest != value:
        if (verbose):
            print "Pin %d changed to %d" % (pin, latest)
        send(pin, latest, sock, port)
    return latest
def scanSwitch():
    import piface.pfio as pfio
    pfio.init() 
    loopctl = True
    button1 = 0
    button2 = 0
    button3 = 0
    button4 = 0
    input6 = 0                             # input6 and input7 are 5V logic level control signals from Arduino.
    input7 = 0
    goControl()                       
    while loopctl is True:

        for i in range (1, 15000):             # These loops indexed by "i" are delay loops to reduce keybounce.
	    delay = 0
        button1 = int(pfio.digital_read(0))    # Read the outer most button
        if button1 == 1:
            print('Stop button pressed')
            stopControl()
            for i in range (1, 15000):
		delay = 0

        button2 = int(pfio.digital_read(1))     # Read the second middle button 
        if button2 == 1:
            waitControl()
            print('Pause button pressed')
            for i in range (1, 1500):
                delay = 0   
 
        button3 = int(pfio.digital_read(2))     # Read the first middle button
        if button3 == 1:
            waitControl()
            print('Pause button pressed')
            for i in range (1, 15000):
		delay = 0

        button4 = int(pfio.digital_read(3))    # Read the inner most button
        if button4 == 1:
            goControl()
            print('Go button pressed')
            for i in range (1, 15000):
		delay = 0
		
        input6 = int(pfio.digital_read(6))    # Read the digital input pin 6, PAUSE signal from Arduino.
        input7 = int(pfio.digital_read(7))    # Read the digital input pin 7, GO signal from Arduino.
        if input6 == 1 and input7 == 0:       # PAUSE when true
           for i in range (1, 5000):
               delay = 0
           if input6 == 1 and input7 == 0:
               waitControl()
               print('WAIT signal from Arduino')   # Suppress multiple triggers

        if input6 ==0 and input7 == 1:        # GO when true
           for i in range (1, 5000):
               delay = 0
           if input6 == 0 and input7 == 1:
               goControl()
               print('GO signal from Arduino')   # Suppress multiple triggers
示例#9
0
import piface.pfio as pfio
pfio.init()
pfio.digital_read(1)
示例#10
0
	# envelope header.
	s = smtplib.SMTP('192.168.1.90')
	s.sendmail(msg['From'], msg['To'], msg.as_string())
	s.quit()
	return True



pfio.init()
AlertaLed = pfio.LED(7)
intStart=time.time()
intRead = -1
enviaemail('Inicio Programa %s' % time.strftime('%X %x %Z'),'Foi iniciado o programa de leitura')

while True:
	teste = pfio.digital_read(0)
	SwitchExit = pfio.digital_read(2)
	if (SwitchExit == 1)
		break
	#print (teste)
	if(intRead <> teste):
		print 'Mudança de leitura de %d para %d as %s' % (intRead,teste,time.strftime('%X %x %Z'))
		intRead = teste
		if(intRead == 1):
			AlertaLed.turn_on()
			intInicio = time.time()
			strCorpo='Linha X parou as %s' % (time.strftime('%X %x %Z'))
			strAssunto='Atença inicio de Paragem da Linha X' 
		elif(intRead == 0):
			AlertaLed.turn_off()
			elapsed = (time.time() - intInicio)
示例#11
0
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)
    pfio.digital_write(red2, 1)
    sleep(redGreenTime)
    pfio.digital_write(red1, 0)

    if pfio.digital_read(0):
        loop = False
        pfio.digital_write(red2, 0)

print("bye!")
#turn on IR LED emitters
p.digital_write(INNER_BEAM,1)
p.digital_write(OUTER_BEAM,1)
#p.digital_write(STATUS_LED,1)

#open a file for appnding , do not buffer
logFile= open('birdlog.txt',  'a', 0)

#indicate the point the program started in the log
logFile.write("###starting up at:" + getFormattedTime() + "\n")

#main  loop of the code
while (True):
    #read the current state of the beam
    innerBeamStateIsBroken = (p.digital_read(INNER_BEAM) == 0)
    outerBeamStateIsBroken = (p.digital_read(OUTER_BEAM) == 0)
    time.sleep(.01)

    ##handle inner Beam
    # if the beam has become broken, that is if the beam was not broken before but is now
    # then record that the bem was broken and log to file
    if (not innerBeamStateWasBroken and innerBeamStateIsBroken):
        innerBeamStateWasBroken = True
        logEvent(0,0)
        print "inner beam has been broken"
        print "------------------------------"

    #this detects when the beam has become un-broken again.
    # That us when the beam was broken ad it is not broken any longer
    # When this occurs, record the new state and log it to file
def read_input(i):
	global stan
	stan = pfio.digital_read(i)
	return stan
示例#14
0
				elif event.key == K_UP:
					rotate_piece()
				elif event.key == K_DOWN:
					move_down()
				elif event.key == K_SPACE:
					drop_down()
					new_shape()
				elif event.key == K_s:
					shadow = not shadow

				elif event.key == K_h:
					next_shape_help = not next_shape_help
	else:
		if clock % 5 == 1:
			if pfio.digital_read(7):
				shadow = not shadow
		if clock % 3 == 1:

			if pfio.digital_read(5):
				drop_down()
			elif pfio.digital_read(3):
				rotate_piece()
		else:
			if pfio.digital_read(1):
				move_left()
			elif pfio.digital_read(2):
				move_right()


			if pfio.digital_read(4):
示例#15
0
def relayon():
    pfio.digital_write(1,1)
    print "Turning on relay!"
    while True:
        if pfio.digital_read(0) == 0:
            return
示例#16
0
def control(LED, switch):
  while True:
    if pfio.digital_read(switch):
      pfio.digital_write(LED, HIGH)
    else:
      pfio.digital_write(LED, LOW)
示例#17
0
import piface.pfio as pfio
from time import sleep

pfio.init()
switch_state = []
info = ["inactive", "active"]

for i in range(8):
    switch_state.append(pfio.digital_read(i+1))
    pfio.digital_write(i+1, switch_state[i])
    if switch_state[i] == 1:
        print "Input {0} is {1}".format(i+1, info[switch_state[i]])

try:
    while True:
        for i in range(8):
            if pfio.digital_read(i+1) != switch_state[i]:
                switch_state[i] = pfio.digital_read(i+1)
                pfio.digital_write(i+1, switch_state[i])
                print "Input {0} is {1}".format(i+1, info[switch_state[i]])
				
            else:
                pass
        sleep(.5)
except:
    pfio.init()
				 
				
示例#18
0
import piface.pfio as pfio
pfio.init()
teste = pfio.digital_read(2)
print (teste)
led1 = pfio.LED(1)
led1.turn_on()

示例#19
0
import piface.pfio as pfio
import time

pfio.init()
teste = pfio.digital_read(2)
print(teste)
start = time.time()

led1 = pfio.LED(7)
led1.turn_on()
time.sleep(1)
led1.turn_off()

elapsed = (time.time() - start)
print elapsed
示例#20
0
def read(n):
  '''Read switch n. If it is closed, print "ON".'''
  while True:
    if pfio.digital_read(n):
      print("ON")
示例#21
0
	## We used to send to a web service, leving this here for reference later - if we want to do away with mysql
	script_path = "http://10.0.2.2:8001/alarm/update/%s/%s/" % (str(sensor), str(status))
	try:
		rt=urllib2.urlopen(script_path)
	except urllib2.HTTPError:
		print "HTTP Error"
		return False
#	cur.close()

pfio.init()
prev_patio=None
prev_entry=None
prev_motion=None

while(1):                
	patio=pfio.digital_read(4)
	data=[patio]
	if patio != prev_patio:
		if data[0]==0:
			notify('patio','open')
		if data[0]==1:
			notify('patio','closed')
		prev_patio = patio
		
	entry=pfio.digital_read(5)
	data=[entry]
	if entry != prev_entry:
		if data[0]==0:
			notify('entry','open')
		if data[0]==1:
			notify('entry','closed')
示例#22
0
def relayoff():
    pfio.digital_write(1,0)
    print "Turning off relay!"
    while True:
        if pfio.digital_read(1) == 0:
            return
示例#23
0
def status(pin_id):
  global pfio
  return "on" if pfio.digital_read(int(pin_id)) == 1 else "off"
示例#24
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"
示例#25
0
def button_pressed():  # Note:PiFace Buttons(index) are switchable.
    p("button press check called ++++++++++++++")
    for button_index in range(0, 8):
        if pf.digital_read(button_index):
            return button_index
    return -1
示例#26
0
	def read_input(port):
		#global stan
		stan = pfio.digital_read(port)
		return stan
示例#27
0
文件: bell.py 项目: si2w/pidoorbell
signal.signal(signal.SIGFPE, close)

try:
	# refresh calendar entries in another thread
	rc()
	
	# init pfio board
	pfio.init()

	i = 0

	while(True):
		now = datetime.datetime.now()

		# doorbell pushed ?
		if pfio.digital_read(0) == 1 :
			day_of_week = datetime.datetime.today().weekday()
			hour = now.hour

			if day_of_week >= 5: # Monday is 0 and Sunday is 6
				print "weekend"
				if((hour >= 7 and hour <= 13) or (hour >= 15 and hour <= 20) or calendar_overwritten >= 1):
					output(0)
				else:
					output(1)
					email_alert()
			else:
				print "week"
				if((hour >= 7 and hour <= 20) or calendar_overwritten >= 1):
                                	output(0)
                        	else:
示例#28
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"
示例#29
0
 def read_input(port):
     #global stan
     stan = pfio.digital_read(port)
     return stan
def read_input(i):
	global stan
	stan = pfio.digital_read(i)
	return stan
示例#31
0
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)
	pfio.digital_write(red2,1)
	sleep(redGreenTime)
	pfio.digital_write(red1,0)
	
	if pfio.digital_read(0):
		loop = False
		pfio.digital_write(red2,0)

print("bye!")