本文整理汇总了Python中pyfirmata.Arduino类的典型用法代码示例。如果您正苦于以下问题:Python Arduino类的具体用法?Python Arduino怎么用?Python Arduino使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arduino类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
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,代码行数:32,代码来源:lights.py
示例2: main
def main():
board = Arduino("/dev/ttyACM0")
board.add_cmd_handler(pyfirmata.pyfirmata.STRING_DATA, on_string_received)
iter = util.Iterator(board)
iter.start()
write_loop(board)
开发者ID:nchavez324,项目名称:es50_final_project,代码行数:9,代码来源:firmata_connect.py
示例3: __init__
def __init__(self, port):
try:
self.board = Arduino(port)
except OSError as e:
raise Exception("Arduino not found on: {0}".format(port))
self._setup()
开发者ID:onepercentclub,项目名称:hoduino,代码行数:7,代码来源:board_interface.py
示例4: ArdUno
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,代码行数:30,代码来源:ArdUno_functions.py
示例5: __init__
def __init__(self, config, SS):
from pyfirmata import Arduino, util, SERVO
self.SS = SS
self.board = Arduino(config['board'])
self.iterator = util.Iterator(self.board)
self.iterator.daemon = True
self.iterator.start()
self.fwheel = self.board.get_pin('d:11:p')
self.fwheel.mode = SERVO
self.rwheel = self.board.get_pin('d:10:p')
self.rwheel.mode = SERVO
self.awheel = self.board.get_pin('d:3:p')
self.awheel.mode = SERVO
self.awheel.write(self.awheel_stop)
self.state = 'start'
self.controlobjects = [
ControlObject(9, self, [self.fire_red]),
ControlObject(8, self, [self.fire_orange]),
ControlObject(12, self, [self.fire_yellow]),
ControlObject(13, self, [self.fire_green])
]
self.colormatch_measurement = M.Measurement.objects(method="closestcolorml")[0]
self.timesince_measurement = M.Measurement.objects(method="timesince_manual")[0]
self.deliveredcolor_measurement = M.Measurement.objects(method="closestcolor_manual")[0]
self.region_inspection = M.Inspection.objects[0]
self.SS = SS
if not "debug" in config:
self.cw = ControlWatcher()
self.cw.control = self
self.cw.daemon = True
self.cw.start()
开发者ID:kscottz,项目名称:SimpleSeer,代码行数:35,代码来源:Controls.py
示例6: ArduinoConnection
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,代码行数:47,代码来源:arduino_connection.py
示例7: __init__
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)
开发者ID:nerdguy,项目名称:httpfirmata,代码行数:8,代码来源:models.py
示例8: __init__
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,代码行数:44,代码来源:hinako.py
示例9: __init__
def __init__(self, port, claw=False):
self.uarm_status = 0
# self.pin2_status = 0
self.coord = {}
self.g_interpol_val_arr = {}
self.angle = {}
self.claw = claw
self.uarm = Arduino(port)
self.assignServos()
self.uarmDetach()
开发者ID:dmopalmer,项目名称:UArmForPython,代码行数:10,代码来源:uarm_python.py
示例10: __init__
def __init__(self, app, parent=None):
super(Form, self).__init__(parent)
# Pyfirmata code
self.potPin = 0
self.servoPin = 9
self.ledPin = 13
self.board = Arduino("/dev/ttyACM0")
iterator = util.Iterator(self.board)
iterator.start()
self.board.analog[self.potPin].enable_reporting()
# self.board.digital[self.servoPin].mode = SERVO
# PyQT Code
servoLabel = QLabel("Servo")
self.servoDial = QDial()
self.servoDial.setMinimum(0)
self.servoDial.setMaximum(180)
self.servoPosition = 0
potLabel = QLabel("Potenciometro")
self.potSlider = QSlider()
self.potSlider.setMinimum(0)
self.potSlider.setMaximum(1000)
ledLabel = QLabel("Led 13")
self.ledButton = QPushButton("Light")
grid = QGridLayout()
grid.addWidget(servoLabel, 0, 0)
grid.addWidget(potLabel, 0, 1)
grid.addWidget(ledLabel, 0, 2)
grid.addWidget(self.servoDial, 1, 0)
grid.addWidget(self.potSlider, 1, 1)
grid.addWidget(self.ledButton, 1, 2)
self.setLayout(grid)
self.connect(self.ledButton, SIGNAL("pressed()"), self.ledOn)
self.connect(self.ledButton, SIGNAL("released()"), self.ledOff)
# self.connect(self.servoDial,
# SIGNAL("valueChanged(int)"), self.moveServo)
self.connect(app, SIGNAL("lastWindowClosed()"), self.cleanup)
self.timer = QTimer()
self.timer.setInterval(500)
self.connect(self.timer, SIGNAL("timeout()"), self.readPot)
self.setWindowTitle("Arduino")
self.timer.start()
开发者ID:marcosscholl,项目名称:essa,代码行数:55,代码来源:test01.py
示例11: ArduinoConnection
class ArduinoConnection(ConnectionBase):
def __init__(self, connection_type, port_name):
super().__init__()
self.connectionStatus = ConnectionStatus.Closed
self.connectionType = connection_type
self.portName = port_name
self._iterator = None
def open_connection(self):
if self.connectionStatus == ConnectionStatus.Open:
print(self.connectionStatus)
return None
try:
if self.board is None:
print("Initializing board object specified connected to port {} ...".format(self.portName))
self.board = Arduino(self.portName)
print("Board object created!")
if self._iterator is None:
print("Initializing iterator object to prevent overflow serial buffer ...")
self._iterator = util.Iterator(self.board)
print("Iterator object created!")
self._iterator.start()
self.connectionStatus = ConnectionStatus.Open
print("{}, {} , {} ".format(self.connectionStatus, self.connectionType, self.portName))
except serial.SerialException as e:
print(e.args[0])
if self.board is not None:
self.board.exit()
raise SystemExit
def close_connection(self):
if self.connectionStatus == ConnectionStatus.Closed:
print("Connection is already closed!")
else:
self.board.exit()
self.board = None
self._iterator = None
self.connectionStatus = ConnectionStatus.Closed
print(self.connectionStatus)
开发者ID:b0ch3n,项目名称:pyarduino,代码行数:40,代码来源:arduino.py
示例12: Board
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,代码行数:37,代码来源:models.py
示例13: main
def main():
parser = ArgumentParser(
description='Bridge connecting Arduino and hat webapp')
parser.add_argument('-s', '--server', default='127.0.0.1:3000',
help='Server the webapp is running on')
parser.add_argument('device',
help='Path to Arduino device, e.g., /dev/tty/ACM0')
args = parser.parse_args()
url = ddp.ServerUrl(args.server)
board = None
hat_controller = None
try:
print 'Connecting to Arduino board...'
board = Arduino(args.device)
print 'Connecting to DDP server...'
hat_controller = HatController(url, board)
hat_controller.connect()
wait_for_user_to_exit()
finally:
if hat_controller is not None:
try:
hat_controller.disconnect()
except:
print (
'An error occurred while disconnecting from the DDP '
'server.'
)
if board is not None:
try:
board.exit()
except:
print 'An error occurred while exiting from the Arduino board.'
开发者ID:foxdog-studios,项目名称:party-hat,代码行数:37,代码来源:hat_controller.py
示例14: main
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,代码行数:37,代码来源:CannyStream-arduino.py
示例15: onActivated
def onActivated(self, ec_id):
print "onActivated Begin"
pinNumber = [3, 5, 6, 7, 11]
self.pin = [None, None, None, None, None]
try:
self.board = Arduino(self._com_port[0])
for i in range(5):
self.board.servo_config(pinNumber[i], angle=90)
# Caution: Don't use board.get_pin('d:*:s') as it calls servo_config method with angle=0, which damages your servo.
self.pin[i] = self.board.digital[pinNumber[i]]
print "onActivated End"
except Exception as e:
print "some errors %s" % str(e)
self.pin[0].write(80)
return RTC.RTC_OK
开发者ID:thorikawa,项目名称:rtc-johnny-five,代码行数:15,代码来源:firmata_servo.py
示例16: init
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,代码行数:15,代码来源:spi_firmata.py
示例17: __init__
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
开发者ID:wadiskth,项目名称:tempSens,代码行数:18,代码来源:arduino_connection.py
示例18: __init__
def __init__(self, port, log_handler):
## Initalize logging
logging.basicConfig(level=logging.DEBUG)
self.logger = logging.getLogger('Arduino_Interface')
self.logger.addHandler(log_handler) # Add Tk log handler
self.logger.debug('__init__')
## Board Initalization
self.board = Arduino(port)
self.board.add_cmd_handler(pyfirmata.START_SYSEX, self.handleIncomingSysEx)
self.board.add_cmd_handler(pyfirmata.STRING_DATA, self.handleIncomingString)
## Data Buffer Initalization
self.incoming_data = []
## Callback holder
self.callback_holder = dict()
开发者ID:david-kooi,项目名称:PythonWorks,代码行数:18,代码来源:Arduino_Interface.py
示例19: __init__
def __init__(self, session):
monkey.patch_socket()
import gevent_zeromq
gevent_zeromq.monkey_patch()
#we do use greenlets, but only patch sock stuff
#other stuff messes up the
config = session.arduino
boardglob = config['board']
boards = glob(boardglob)
if not len(boards):
raise Exception("No Arduino found")
self.board = Arduino(boards[0])
#self.iterator = util.Iterator(self.board)
#self.iterator.daemon = True
#self.iterator.start()
#initialize servo objects
self.servos = {}
if "servos" in config:
for servo in config["servos"]:
self.servos[servo['name']] = Servo(servo['pin'], self.board)
#initialize light objects
self.digitalouts = {}
if "digitalouts" in config:
for do in config["digitalouts"]:
self.digitalouts[do['name']] = DigitalOut(do['pin'], self.board)
if "digitalouts" in config or "servos" in config:
self.subsock = ChannelManager().subscribe("ControlOutput/")
self.buttons = []
if "buttons" in config:
for button in config["buttons"]:
self.buttons.append(Button(button['pin'], button['message'], self.board))
self.potentiometers = []
if "potentiometers" in config:
for pot in config["potentiometers"]:
self.buttons.append(Potentiometer(pot['pin'], pot['name'], self.board))
开发者ID:carriercomm,项目名称:SimpleSeer,代码行数:43,代码来源:Controls.py
示例20: __init__
def __init__(self, api_key, feed, serial_port, delay=5):
"""Setup hardware and remote feeds.
@param api_key This is the key from Cosm.com
@param feed This is the feed ID from Cosm.com
@param serial_port Where to read data from
@param delay Number of seconds to wait between read/sends.
"""
self.api_key = api_key
self.feed = feed
self.serial_port = serial_port
self.delay = delay
self.arduino = Arduino(self.serial_port)
self.iterator = util.Iterator(self.arduino)
self.iterator.start()
self.cosm = CosmSender(self.api_key, self.feed, {}, cacheSize=0)
self.streams = {}
开发者ID:stringfellow,项目名称:alt-power-cosm,代码行数:20,代码来源:reader.py
注:本文中的pyfirmata.Arduino类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论