当前位置: 首页>>代码示例>>Python>>正文


Python Arduino.get_pin方法代码示例

本文整理汇总了Python中pyfirmata.Arduino.get_pin方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.get_pin方法的具体用法?Python Arduino.get_pin怎么用?Python Arduino.get_pin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyfirmata.Arduino的用法示例。


在下文中一共展示了Arduino.get_pin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
class LightsController:
    def __init__(self):
        self.board = Arduino("/dev/ttyACM0")
        self.lightPin = self.board.get_pin("d:3:p")

    def Off(self):
        self.lightPin.write(0)
        sleep(1)

    def On(self):
        self.lightPin.write(1)
        sleep(1)

    def Fade(self):
        for pwm in arange(0.02, 0.1, 0.004):
            self.lightPin.write(pwm)
            sleep(0.075)
        for pwm in arange(0.1, 0.8, 0.01):
            self.lightPin.write(pwm)
            sleep(0.075)
        for pwm in arange(0.8, 0.1, -0.01):
            self.lightPin.write(pwm)
            sleep(0.075)
        for pwm in arange(0.1, 0.02, -0.004):
            self.lightPin.write(pwm)
            sleep(0.075)

    def Blink(self):
        self.lightPin.write(1)
        sleep(1)
        self.lightPin.write(0)
        sleep(1)
开发者ID:blieber,项目名称:LightAutomation,代码行数:34,代码来源:lights.py

示例2: Arduino

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
from pyfirmata import Arduino, util
import time

refVoltage = 4.50
R1 = 3270.3
R2 = 1013.5
vdivide = (R1+R2)/R2
vscale = refVoltage * vdivide

board = Arduino('/dev/ttyACM0')
analogPin = 4

it = util.Iterator(board)
it.start()
voltPin = board.get_pin('a:'+str(analogPin)+':i')
voltPin.enable_reporting()

avg10 = [0 for i in range(10)]

time.sleep(2)

while(1):
	voltval = voltPin.read()*vscale
	avg10.insert(0, voltval)
	avg10.pop()
	avg = 0.0
	for n in avg10:
		avg += n
	print avg / len(avg10)
	time.sleep(.5)
	
开发者ID:saites,项目名称:guggug,代码行数:32,代码来源:voltmeter.py

示例3: ArdUno

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
class ArdUno():
    def __init__(self):
        self.port = 'COM21'
        self.board = Arduino(self.port)
        self.anticrash()
        self.readenable()
        self.board.digital[8].write(1)
        
    def anticrash(self):
        """ Iterator evita que se crashee el puerto (no permite que se sobrecargue de trafico) """
        it = util.Iterator(self.board)       
        it.start()                   #corremos el iterator
    def readenable(self):
        self.board.analog[0].enable_reporting()
                    
    def getpin(self,numchannel):
        ch=str(numchannel)
        pin='a:' + ch + ':i'
        R=self.board.get_pin(pin)
        return(R)
        
    def chdef(self,namechannel,numchannel):
        ch=str(numchannel)
        R='A' + ch + ' = h.getpin(' + ch + ')'
        return(R)
    
    def voltread(self,namechannel,numchannel):
        ch=str(numchannel)
        A=namechannel+ ch +'.read()'
        return(str(A))    
开发者ID:LaFriOC,项目名称:Arduino,代码行数:32,代码来源:ArdUno_functions.py

示例4: ArduinoConnection

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
class ArduinoConnection(Thread):

    def __init__(self):
        Thread.__init__(self)
        
        self.SAMPLING_INTERVAL = 0.100
        self.MEAN_INTERVAL = 5
        self.MEAN_SAMPLES_NUMBER = round(self.MEAN_INTERVAL/self.SAMPLING_INTERVAL)

        PORT = '/dev/ttyACM0'
        self.board = Arduino(PORT)
        it = util.Iterator(self.board)
        it.start()

        self.analog_pin_value_arr = [self.board.get_pin('a:0:i'), self.board.get_pin('a:1:i'), self.board.get_pin('a:2:i'), self.board.get_pin('a:3:i'), self.board.get_pin('a:4:i'), self.board.get_pin('a:5:i')]
        for i in range(len(self.analog_pin_value_arr)):
            self.analog_pin_value_arr[i].enable_reporting()

        self.mean_analog_valuea_arr = [0.0] * 6
        self.mean_analog_valuea_assigned_arr = [0.0] * 6

    def run(self):        
        #s= ''
        sample_number = 0
        
        while True:
            while (sample_number < self.MEAN_SAMPLES_NUMBER):
                #    time.sleep(DELAY)
                self.board.pass_time(self.SAMPLING_INTERVAL)
                for i in range(len(self.mean_analog_valuea_arr)):
                    self.mean_analog_valuea_arr[i] = self.mean_analog_valuea_arr [i] + self.analog_pin_value_arr[i].read()
                sample_number = sample_number + 1

            for i in range(len(self.mean_analog_valuea_arr)):
                self.mean_analog_valuea_arr[i] = self.mean_analog_valuea_arr[i] / self.MEAN_SAMPLES_NUMBER
                #s = s + str(self.mean_analog_valuea_arr[i]) + ' '

            self.mean_analog_valuea_assigned_arr = self.mean_analog_valuea_arr
                
            #print s
            
            #s = ''            
            sample_number = 0
            self.mean_analog_valuea_arr = [0.0] * 6

    def getMeanAnalogArduinoValueArray(self):
        return self.mean_analog_valuea_assigned_arr
开发者ID:wadiskth,项目名称:tempSens,代码行数:49,代码来源:arduino_connection.py

示例5: __init__

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
class Hinako:

    def __init__(self, port, b_pin_id, w_pin_id, h_pin_id):
        self.board = Arduino(port)
        
        '''
        d: digital output
        n: number PWM pin
        s: servo control
        '''
        self.b_pin = self.board.get_pin(b_pin_id)
        self.w_pin = self.board.get_pin(w_pin_id)
        self.h_pin = self.board.get_pin(h_pin_id)

        self.b = 0
        self.w = 0
        self.h = 0

    def _move_servo(self, pin, begin_val, end_val, ds=0.1):
        step = 1 if begin_val < end_val else -1

        print '%d -> %d' % (begin_val, end_val)
        print step

        for i in range(begin_val, end_val, step):
            print i
            pin.write(i)
            time.sleep(ds)

    def set_bust(self, size_cm, ds=0.1):
        print "bust: %d cm" % size_cm
        val = int(round(map_value(size_cm, 70, 100, 65, 0)))
        self._move_servo(self.b_pin, self.w, val, ds=ds)
        self.w = val
        
    def set_waist(self, val):
        '''
        dc motor
        self.w_pin
        '''

    def set_hip(self, val):
        self._move_servo(self.h_pin, self.h, val)
        self.h = val
开发者ID:otknoy,项目名称:hinako_bwh,代码行数:46,代码来源:hinako.py

示例6: main

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
def main():
  board = Arduino('/dev/ttyUSB0')

  #starting values

  multiplier = 400.0

  cam = Camera()
  js = JpegStreamer()

  analog_4 = board.get_pin('a:1:i')
  analog_5 = board.get_pin('a:2:i')
  button_13 = board.get_pin('d:13:i')

  it = util.Iterator(board) 
  it.start()

  while (1):
    #print str(analog_5.read()) + "\t\t" + str(analog_4.read())
    t1 = analog_5.read()
    t2 = analog_4.read()
    b13 = button_13.read()

    if not t1: 
      t1 = 50 
    else:
      t1 *= multiplier 

    if not t2: 
      t2 = 100 
    else:
      t2 *= multiplier

    print "t1 " + str(t1) + ", t2 " + str(t2) + ", b13 " + str(b13)
    cam.getImage().flipHorizontal().edges(int(t1), int(t2)).invert().smooth().save(js.framebuffer)

    time.sleep(0.01)
开发者ID:Aravindlivewire,项目名称:SimpleCV,代码行数:39,代码来源:CannyStream-arduino.py

示例7: init

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
def init():
	global board
	board = Arduino('/dev/ttyACM0')
	global lazer1
	lazer1 = board.get_pin('d:2:o')
	global lazer2
	lazer2 = board.get_pin('d:3:o')
	global lazer3
	lazer3 = board.get_pin('d:4:o')
	global pump1
	pump1 = board.get_pin('d:11:o')
	global pump2
	pump2 = board.get_pin('d:12:o')
	global pwm_led
	pwm_led = board.get_pin('d:6:p')
开发者ID:btarnold,项目名称:SPIScan,代码行数:17,代码来源:spi_firmata.py

示例8: __init__

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
class ArduinoWrapper:
    __arduino = None
    
    def __init__(self, com=None):
        self.connect(com)

    def connect(self, com=None):
        if com != None:
            self.__arduino = Arduino(com) 
        else:
            self.__arduino = Arduino(DEFAULT_COMPORT) 

    def update_pin(self, num, status):
        if status:
            print "update pin: %s -> ON" %str(num)
            return self.__arduino.digital[num].write(1)
        else:
            print "update pin: %s -> OFF" %str(num)
            return self.__arduino.digital[num].write(0)

    def get_pin(self, status):
            return self.__arduino.get_pin(status)
开发者ID:ca5,项目名称:ohd2,代码行数:24,代码来源:__init__.py

示例9: Board

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
class Board(SerializableModel):
    pk = None
    port = None
    pins = None
    name = None
    written_pins = set()

    json_export = ('pk', 'port', 'pins')

    def __init__(self, pk, port, *args, **kwargs):
        self.pk = pk
        self.port = port
        self._board = Arduino(self.port)
        self.pins = dict(((i, Pin(pk, i)) for i in range(14)))

        [setattr(self, k, v) for k, v in kwargs.items()]
        super(Board, self).__init__(*args, **kwargs)

    def __del__(self):
        try:
            self.disconnect()
        except:
            print(traceback.format_exc())

    def disconnect(self):
        for pin in self.written_pins:
            pin.write(0)
        return self._board.exit()

    def firmata_pin(self, identifier):
        return self._board.get_pin(identifier)

    def release_pin(self, identifier):
        bits = identifier.split(':')
        a_d = bits[0] == 'a' and 'analog' or 'digital'
        pin_nr = int(bits[1])
        self._board.taken[a_d][pin_nr] = False
开发者ID:nerdguy,项目名称:httpfirmata,代码行数:39,代码来源:models.py

示例10: Arduino

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
#!/usr/bin/python
from pyfirmata import Arduino, util

# para buscar el puerto ls /dev/tty.*
import time




if __name__ == '__main__':

	try : 
		board = Arduino('/dev/tty.usbserial-A400eMcd')
		pin10 = board.get_pin('d:10:p')
		pin11 = board.get_pin('d:11:p')

		def rampaMotor1 (rampa_) : 
			rampaLen = len(rampa_)
			pwm = 0
			delay = 0
			for x in xrange(0,rampaLen):

				#encendido de luz 1
				if x == 0 : 
					board.digital[6].write(1)
				#apagado de luz 1 con delay
					
				elif x == (rampaLen - 1) :
					time.sleep(rampa_[rampaLen-1] + 0.2)
					board.digital[6].write(0)
开发者ID:JoseU,项目名称:Exercises-Python,代码行数:32,代码来源:06digital1.py

示例11: bridgeclient

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
#!/usr/bin/python

#import sys
import socket

#sys.path.insert(0, '/usr/lib/python2.7/bridge/')
 
#from bridgeclient import BridgeClient as bridgeclient
from pyfirmata import Arduino, util
from time import sleep
 
#value = bridgeclient()
board = Arduino('/dev/ttyATH0', baudrate=115200)
pin9 = board.get_pin('d:9:s')
pin10 = board.get_pin('d:10:s')
 
UDP_IP = "192.168.240.1"
UDP_PORT = 5005
 
sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

pin9.write(40)
sleep(0.5)
pin9.write(140)
sleep(0.5)
pin9.write(90)
sleep(0.5)

#print 'server is running...'
开发者ID:dhanson0510,项目名称:android-arduino-remote,代码行数:33,代码来源:bridgeUdpServer.py

示例12: handshake

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
    (sid, hbtimeout, ctimeout) = handshake(HOSTNAME, PORT) #handshaking according to socket.io spec.
except Exception as e:
    print e
    sys.exit(1)
ws = websocket.create_connection("ws://%s:%d/socket.io/1/websocket/%s" % (HOSTNAME, PORT, sid))

# handshake this player with the server
playerID = uuid.uuid4();
ws.send('5:1::{"name":"handshake", "args":"player|' + str(playerID) + '"}')

board = Arduino("COM6")

it = util.Iterator(board)
it.start()

button1Pin = board.get_pin('d:2:i')
button1Pin.enable_reporting()

button2Pin = board.get_pin('d:3:i')
button2Pin.enable_reporting()

ledPin = board.get_pin('d:13:o')

while 1:
   b1Val = button1Pin.read()
   b2Val = button2Pin.read()

   if b1Val == True:
      print("button 1 click")
      ws.send('5:1::{"name":"buttonClick", "args":"' + str(playerID) + '|button1"}')
开发者ID:spiridon-alexandru,项目名称:ArduinoConsole,代码行数:32,代码来源:consoleControllerPlayer1.py

示例13: Arduino

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
On linux it is typically:
/dev/ttyUSBO

but the Arduino IDE should tell you where you should mount the arduino from.

"""

print __doc__

from SimpleCV import *
import sys, curses, time
from pyfirmata import Arduino, util


board = Arduino('/dev/ttyUSB0') #the location of the arduino
analog_pin_1 = board.get_pin('a:1:i') #use pin 1 of the arduino as input
analog_pin_2 = board.get_pin('a:2:i') #use pin 2 of the arduino as input
button_13 = board.get_pin('d:13:i') #use pin 13 of the arduino for button input

it = util.Iterator(board) # initalize the pin monitor for the arduino
it.start() # start the pin monitor loop

multiplier = 400.0 # a value to adjust the edge threshold by
cam = Camera() #initalize the camera

while True:
  t1 = analog_pin_1.read() # read the value from pin 1
  t2 = analog_pin_2.read() # read the value from pin 2
  b13 = button_13.read() # read if the button has been pressed.

  if not t1: #Set a default if no value read
开发者ID:ALitTLeQ,项目名称:SimpleCV,代码行数:33,代码来源:CannyStream-arduino.py

示例14: int

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
pscom = devconfig.get('Parameters', 'pscom')
arduinocom = devconfig.get('Parameters', 'arduinocom')
ports = devconfig.getint('Parameters', 'ports')
tubevol = devconfig.getfloat('Parameters', 'tubevol')
length1 = devconfig.getfloat('Parameters', 'length1')
length2 = devconfig.getfloat('Parameters', 'length2')
length3 = devconfig.getfloat('Parameters', 'length3')
piv = devconfig.getint('Parameters', 'piv')

len1 = int(tubevol*length1) 
len2 = int(tubevol*length2) 
len3 = int(tubevol*length3)

ps = serial.Serial(port=pscom, baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) # VICI port selector
board = Arduino(arduinocom) # Arduino Uno
n2 = board.get_pin('d:2:o') # Solenoid valve normally closed, connected to digital pin 2
vent = board.get_pin('d:3:o') # Solenoid valve normally open, connected to digital pin 3
reagent = board.get_pin('d:4:o') # Solenoid valve normally closed, connected to digital pin 4
waste = board.get_pin('d:5:o') # Solenoid valve normally closed, connected to digital pin 5
prime = board.get_pin('d:6:o') # Solenoid valve normally closed, connected to digital pin 6
pump = board.get_pin('d:7:o') # Solenoid micro pump with an internal volume of 20 microliter and rated for a maximum pumping rate of 2.4 ml/min or 40 microliter/sec, connected to digital pin 7

print(" ")
print("--------------------------------------------------------------------------------------------------")
print("                                           PepSy                                                  ")
print("--------------------------------------------------------------------------------------------------")
print(" ")
print(datetime.datetime.now().strftime('%m-%d-%Y %I:%M:%S %p'))
print(" ")

seqfile = input("Enter the sequence configuration file name ")
开发者ID:harigali,项目名称:PepSy,代码行数:33,代码来源:PepSy.py

示例15: Arduino

# 需要导入模块: from pyfirmata import Arduino [as 别名]
# 或者: from pyfirmata.Arduino import get_pin [as 别名]
import time
from pyfirmata import Arduino, util

board = Arduino('/dev/tty.usbmodem411')
led = board.get_pin('d:13:o')

while True:
    led.write(1)
    time.sleep(.1)
    led.write(0)
    time.sleep(.1)
    led.write(1)
    time.sleep(1)
    led.write(0)
    time.sleep(1)
开发者ID:vinyll,项目名称:arduino-playground,代码行数:17,代码来源:led-pulse.py


注:本文中的pyfirmata.Arduino.get_pin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。