本文整理汇总了Python中Arduino.Arduino类的典型用法代码示例。如果您正苦于以下问题:Python Arduino类的具体用法?Python Arduino怎么用?Python Arduino使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arduino类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self,valveP=6,valveS1=2,valveS2=3,valveS3=4,valveS4=5,pump1D=8,pump1S=9,pump2D=12,pump2S=11):#the defaults are the pins that I assume will be connected to the valves
try:
Arduino.__init__(self) #connect to arduino REMOVE THE PORT!!
except ValueError:
logging.warning('Error! Arduino was not found')
return
self.valveP=valveP
self.valveS1=valveS1
self.valveS2=valveS2
self.valveS3=valveS3
self.valveS4=valveS4#
self.valveList=[self.valveP,self.valveS1,self.valveS2,self.valveS3,self.valveS4]
self.pump1D=pump1D#
self.pump1S=pump1S
self.pump2D=pump2D
self.pump2S=pump2S
self.pinMode(self.valveP,'Output')#
self.digitalWrite(self.valveP,'HIGH')
self.pinMode(self.valveS1,'Output')
self.digitalWrite(self.valveS1,'HIGH')
self.pinMode(self.valveS2,'Output')
self.digitalWrite(self.valveS2,'HIGH')
self.pinMode(self.valveS3,'Output')
self.digitalWrite(self.valveS3,'HIGH')
self.pinMode(self.valveS4,'Output')
self.digitalWrite(self.valveS4,'HIGH')
self.pinMode(self.pump1D,'Output')#
self.pinMode(self.pump1S,'Output')
self.pinMode(self.pump2D,'Output')
self.pinMode(self.pump2S,'Output')
示例2: ButtonTry
def ButtonTry():
currPin = 0
board = Arduino(9600, "")
board.pinMode(8, "INPUT")
i = 0
Counter = 7
while True:
inp = board.analogRead(0)
i = i + 1
print "[" + str(i) + "]\t" + str(inp)
if inp > 0:
Counter = Counter - 1
if Counter <= 1:
message = client.messages.create(body="'Hey there! Looks like your medication needs to be restocked! We have taken care of that for you! Ready to be picked up whenever you are ready :)",
to="+19737234645",
from_="+12677133663")
#print message.sid
#Counter = 7
elif Counter < (7 / 2):
message = client.messages.create(body="'Hey there! Looks like your doing okay there friend! Make sure your taking your medication on time!",
to="+19737234645",
from_="+12677133663")
else:
print "YOU ARE GOOD TO GO"
#print board.digitalRead(led_pin) # confirm HIGH (1)
time.sleep(0.2)
示例3: Blink
def Blink(led_pin, baud, port=""):
board = Arduino(baud, port=port)
board.pinMode(led_pin, "OUTPUT")
while True:
board.digitalWrite(led_pin, "HIGH")
#print board.digitalRead(led_pin) # confirm HIGH (1)
time.sleep(1)
示例4: __init__
def __init__(self, *args, **kwargs):
Thread.__init__(self)
Arduino.__init__(self, *args, **kwargs)
self.lock = Lock()
self._kill = False
self.start()
示例5: Lighting
def Lighting():
currPin = 0
board = Arduino(9600, "")
board.pinMode(0, "OUTPUT")
i = 0
while True:
#board.analogWrite(0,65)
i = i + 1
print "[" + str(i) + "]\t"
#print board.digitalRead(led_pin) # confirm HIGH (1)
time.sleep(0.1)
示例6: adjustBrightness
def adjustBrightness(pot_pin, led_pin, baud, port=""):
"""
Adjusts brightness of an LED using a
potentiometer.
"""
board = Arduino(baud, port=port)
while True:
time.sleep(0.01)
val = board.analogRead(pot_pin) / 4
print val
board.analogWrite(led_pin, val)
示例7: Button
def Button():
currPin = 0
board = Arduino(9600, "")
board.pinMode(8, "INPUT")
i = 0
while True:
inp = board.analogRead(0)
i = i + 1
print "[" + str(i) + "]\t" + str(inp)
#print board.digitalRead(led_pin) # confirm HIGH (1)
time.sleep(0.1)
示例8: test_find
def test_find(self):
""" Tests auto-connection/board detection. """
raw_input(
'Plug in Arduino board w/LED at pin 13, reset, then press enter')
from Arduino import Arduino
board = None
try:
# This will trigger automatic port resolution.
board = Arduino(9600)
finally:
if board:
board.close()
示例9: PingSonar
def PingSonar(pw_pin, baud, port=""):
"""
Gets distance measurement from Ping)))
ultrasonic rangefinder connected to pw_pin
"""
board = Arduino(baud, port=port)
pingPin = pw_pin
while True:
duration = board.pulseIn(pingPin, "HIGH")
inches = duration / 72. / 2.
# cent = duration / 29. / 2.
print inches, "inches"
time.sleep(0.1)
示例10: Stepper
def Stepper(baud, port, steps, pin1, pin2, pin3=0, pin4=0, speed=120):
"""
Steps
"""
board = Arduino(baud, port=port)
board.pinMode(13, "OUTPUT")
board.Stepper.attach(steps,pin1, pin2, pin3, pin4)
board.Stepper.speed(pin1, speed)
while True:
board.Stepper.step(pin1, steps)
time.sleep(1)
board.Stepper.step(pin1, -steps)
time.sleep(1)
示例11: softBlink
def softBlink(led_pin, baud, port=""):
"""
Fades an LED off and on, using
Arduino's analogWrite (PWM) function
"""
board = Arduino(baud, port=port)
i = 0
while True:
i += 1
k = i % 510
if k % 5 == 0:
if k > 255:
k = 510 - k
board.analogWrite(led_pin, k)
示例12: Blink
def Blink(led_pin,baud, port = ""):
"""
Blinks an LED in 1 sec intervals
"""
board = Arduino(baud, port=port)
while True:
board.digitalWrite(led_pin,"LOW")
print board.digitalRead(led_pin) #confirm LOW (0)
time.sleep(1)
board.digitalWrite(led_pin,"HIGH")
print board.digitalRead(led_pin) #confirm HIGH (1)
time.sleep(1)
示例13: test_open
def test_open(self):
""" Tests connecting to an explicit port. """
port = None
while not port:
port = raw_input(
'Plug in Arduino board w/LED at pin 13, reset.\n'\
'Enter the port where the Arduino is connected, then press enter:')
if not port:
print 'You must enter a port.'
from Arduino import Arduino
board = None
try:
board = Arduino(9600, port=port)
finally:
if board:
board.close()
示例14: CommonHardwareArduino
class CommonHardwareArduino(object):
"""
Class for interfacing with arduino device over usb
"""
def __init__(self, baud_rate='9600', device_port="/dev/ttyACM0"):
self.arduino_device = Arduino(baud_rate, port=device_port)
# 'LOW'
def com_arduino_usb_serial_digitalwrite(self, pin_number, pin_high_low='HIGH'):
self.arduino_device.digitalWrite(pin_number, pin_high_low)
def com_arduino_usb_serial_writestring(self, serial_string):
self.arduino_device.SoftwareSerial.write(serial_string)
def com_arduino_usb_serial_receivestring(self):
pass
示例15: ButtonPill
def ButtonPill():
board = Arduino(9600, "")
i = 0
Counter = 10
CounterCopy = Counter
while True:
inp = board.analogRead(0)
i = i + 1
print "[" + str(i) + "]\t" + str(inp)
if inp > 0:
Counter = Counter - 1
if Counter <= 2:
message = client.messages.create(
body="Hey there!\n" +
"Looks like your medication needs to be restocked!\n" +
"We have taken care of that for you! Ready to be picked up whenever you are ready :)",
to="+19737234645",
from_="+12677133663")
message = client.messages.create(
body="Hey there!\n" +
"Looks like Ankita''s medication needs to be restocked!\n" +
"We have taken informed her as well!",
to="+14702633590",
from_="+12677133663")
elif Counter < (CounterCopy/2):
message = client.messages.create(
body="Hey there!\n" +
"Looks like your doing well there friend!\n" +
"Make sure your taking your medication on time!",
to="+19737234645",
from_="+12677133663")
time.sleep(0.3)