本文整理汇总了Python中arduino.Arduino类的典型用法代码示例。如果您正苦于以下问题:Python Arduino类的具体用法?Python Arduino怎么用?Python Arduino使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arduino类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WhatsHappening
class WhatsHappening(object):
_screenPos = 0
_mail = Mail()
_owm = pyowm.OWM('4c046ad50263519b269d79a1e9453a53')
def __init__(self, port):
self._arduino = Arduino(port)
def update(self):
#ip = socket.gethostbyname(socket.gethostname())
if self._screenPos == 0:
observation = self._owm.weather_at_place('halifax,ns')
w = observation.get_weather()
temp = w.get_temperature(unit='celsius')['temp']
status = w.get_status()
hum = w.get_humidity()
line_one = '%s %dC %d%%' % (status, temp, hum)
line_two = '%s' % time.strftime("%a %b %d")
self._screenPos += 1
else:
line_one = 'Email:%d' % self._mail.unread_messages()
line_two = 'RAM:%d%% CPU:%d%%' % (psutil.virtual_memory().percent, psutil.cpu_percent())
self._screenPos = 0
self._arduino.clear()
self._arduino.write('%s\r\n%s' % (line_one, line_two))
示例2: Neopixel
class Neopixel():
def __init__(self):
self.board = Arduino()
self.board.connect()
def reset(self):
return self.board.sendCommand(Commands.RESET_NEO_PIXELS,0,0)
def writePixel(self,pixel,r,g,b):
return self.board.sendCommand(Commands.WRITE_NEO_PIXEL,0,pixel,r,g,b)
示例3: Encoder
class Encoder():
def __init__(self):
self.board = Arduino()
self.board.connect()
def getRevsright(self):
rightrevs = self.board.sendCommand(Commands.READ_RIGHT_ENCODER,0,-1)
return rightrevs
def getRevsleft(self):
leftrevs = self.board.sendCommand(Commands.READ_LEFT_ENCODER,0,-1)
return leftrevs
示例4: Ultrasound
class Ultrasound():
def __init__(self):
self.board = Arduino()
self.board.connect()
def getDistance(self):
distance = int(self.board.sendCommand(Commands.READ_ULTRASOUND,TRIGGER_PIN,0))
# large distances are reported as 0, so change to max distance
if distance == 0:
distance = 100
# limit to 100
elif distance > 100:
distance = 100
return distance
示例5: __init__
def __init__(self):
wx.Frame.__init__(self, None, title=self.title, size=(650,570))
if platform.system() == 'Windows':
arduino_port = 'COM4'
else:
arduino_port = '/dev/ttyACM0'
# Try Arduino
try:
self.arduino = Arduino(arduino_port, 115200)
except:
msg = wx.MessageDialog(self, 'Unable to connect to arduino. Check port or connection.', 'Error', wx.OK | wx.ICON_ERROR)
msg.ShowModal() == wx.ID_YES
msg.Destroy()
self.create_main_panel()
self.recording = False
self.output_file = ''
time.sleep(1)
# Timer
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
self.rate = 500
self.timer.Start(self.rate)
示例6: OnChangeSerialPort
def OnChangeSerialPort(self, event): # wxGlade: MainWindow.<event_handler>
self.windowPrintLn('')
self.windowPrintLn("Searching for available serial ports...")
#scan for available ports. return a list of tuples (num, name)
available = []
for i in range(256):
try:
s = serial.Serial(i)
available.append( (i, s.portstr))
s.close() # explicit close because of delayed GC in java
except serial.SerialException:
pass
self.windowPrintLn("Found the following avilable ports:")
for nu, na in available: self.windowPrintLn(na)
dlg = wx.SingleChoiceDialog(self, "Select the correct serial port", 'Serial Port Selection',
[na for nu, na in available], wx.CHOICEDLG_STYLE)
if dlg.ShowModal() == wx.ID_OK:
self.serialPort = dlg.GetStringSelection()
self.windowPrintLn('Selected ' + self.serialPort)
self.windowPrintLn("Attempting to connect to arduino over " + self.serialPort + ".....")
try:
self.arduino = Arduino(self.serialPort)
self.arduino.output(self.arduinoPinMap)
self.arduino.turnOff()
self.windowPrintLn(str(self.arduino))
except serial.serialutil.SerialException:
self.windowPrintLn("Failed to connect to port " + self.serialPort + "!")
self.arduino = None
except TimeoutException:
self.windowPrintLn("5 second timeout: Failed to communicate with arduino over " + self.serialPort)
self.windowPrintLn("Reset arduino and try again, or try different port.")
self.arduino = None
示例7: initialize
def initialize(self, uni):
"""docstring for __init__"""
self.arduino = Arduino()
self.arduino.start()
self.client = MongoClient('localhost', 27017)
self.uni = uni
self.mongo_gestures = self.client.affordance.gestures
self.mongo_envelopes = self.client.affordance.envelopes
self.mongo_users = self.client.affordance.users
self.mongo_tracking = self.client.affordance.tracking
self.mongo_studies = self.client.affordance.studies
self.list_obj = []
self.current_study_participant = None
self.data_fetcher = DataFetcher(self.client.affordance)
self.zap_speed = 1500
self.zap_strength = {"ems1": self.arduino.channels['ems1']['min_max'][0], "ems2": self.arduino.channels['ems2']['min_max'][0]}
self.zap_gestures = {"squeeze": False, "shake": False, "repel": False, "tap": False, "rotate": False, "ems1": False, "ems2": False, "ems3": False, "ems4": False}
#self.data_fetcher = DataFetcher(self.mongo_tracking, False) # Recorded data!
self.hand = Hand(self.data_fetcher, self.client.affordance, self.arduino)
self.uni.hand = self.hand
#screw_driver = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["screwdriver_trackable"], "screwdriver", "Screwdriver")
#screw_brick = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["screw_brick_trackable"], "screw_brick", "Screw brick")
#teapot = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["teapot_trackable"], "teapot", "Teapot")
#spray_can = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["spray_can_trackable"], "spray_can", "Spray Can")
#lamp = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["hot_cup_trackable"], "hot_cup", "hot_cup")
#paint_brush = AffordanceObjects(self.data_fetcher, self.uni, self.arduino, ["paint_trackable"], "paint_brush", "Paint brush")
self.hand.start()
self.data_fetcher.register_trackers()
示例8: action
def action(self, request,pk):
global DEVICES,PATHS,SEMAPHORES
actuator = self.get_object()
arduino = Arduino(actuator.device.path)
if actuator.ejecute:
P(SEM)
ejecute = False
ActuatorArduino.objects.filter(id = actuator.id).update(ejecute = False)
arduino.digitalWriteDown(actuator.pin)
V(SEM)
else:
P(SEM)
ejecute = True
ActuatorArduino.objects.filter(id = actuator.id).update(ejecute = True)
arduino.digitalWriteUp(actuator.pin)
V(SEM)
return Response([{"actuator_name":actuator.name,"ejecute":ejecute}])
示例9: verify
def verify():
global PATHS, DEVICES, SEM,SEM2,ALL
tiempo = 0
while 1:
data = {}
devices = Device.objects.all()
for device in devices:
if device.path not in PATHS:
PATHS.append(device.path)
arduino = Arduino(device.path)
DEVICES.append(arduino)
else:
for dev in DEVICES:
if dev.getLocation() == device.path:
arduino = dev
break
test = True
while test:
#print "while"
#print
try:
data[device.path] = ast.literal_eval(arduino.readAll())
test = False
except:
pass
controllersComplete = ControllerComplete.objects.all()
for controller in controllersComplete:
value = ""
try:
value = data[controller.sensor.device.path][controller.sensor.pin]
except Exception,e:
print e
try:
flag = eval(str(value)+controller.condition+controller.value)
if controller.actuator.ejecute and not flag:
P(SEM)
arduino = Arduino(controller.actuator.device.path)
ActuatorArduino.objects.filter(id = controller.actuator.id).update(ejecute = False)
arduino.digitalWriteDown(controller.actuator.pin)
V(SEM)
elif flag and not controller.actuator.ejecute:
P(SEM)
arduino = Arduino(controller.actuator.device.path)
ActuatorArduino.objects.filter(id = controller.actuator.id).update(ejecute = True)
arduino.digitalWriteUp(controller.actuator.pin)
V(SEM)
except Exception, e:
print e
示例10: pollj
def pollj():
ret = []
pin = 1
try:
b = Arduino('/dev/ttyACM0')
b.output([])
except:
print 'couldnt create b'
for i in range(10):
val = None
try:
val = b.analogRead(pin)
except:
print 'couldnt analogread ' + str(i)
ret.append(val)
print val
time.sleep(0.5)
return " | ".join(ret)
示例11: __init__
def __init__(self):
self.parser = Parser()
self.arduino = Arduino(ArduinoController.BAUD_RATE)
self.arduino.register_listener(self)
self.msg_handlers = {
'log_format': self.parser.register_log_format,
'sensor_readings': self.notify_listeners
}
self.log_received_listeners = []
示例12: __init__
def __init__(self, webserver_queue=None, looprate=0.2):
self.arduino = Arduino()
self.navigation = Navigation(self.arduino)
self.state = State.COLLECT_spin_and_search_cone
# Define constants
self.looprate = looprate
# Variables updated from webserver
self.webserver_queue = webserver_queue
self.mode = "auto"
self.manual_direction = "stop"
# Variables used by states
self.start_time = None
self.ready_to_deliver = False
示例13: __init__
def __init__(self):
if pi is True:
self.board = Arduino()
self.board.connect()
self.move = Motors()
GPIO.setup(GREEN_LED_GPIO,GPIO.OUT)
GPIO.setup(RED_LED_GPIO,GPIO.OUT)
GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# load the sample hash
with open(rfid_hash) as fh:
self.rfid_hash = json.load(fh)
示例14: __init__
def __init__(self, fname, nrepeat=10, ard_port="/dev/ttyACM0", pump_port="/dev/ttyUSB0"):
self.__observers = [] # define an observer
self.step = -1 # before execution
self.conf_label = "R" + "CUCI" * nrepeat
print(self.conf_label)
self.n_session = 1 + nrepeat * 4
self.sessions = len(self.conf_label) # the number of steps
self.__construct__()
self.time_flag = pd.Series(np.zeros(self.n_session), index=list(self.conf_label))
ard_reset(ard_port)
self.ard = Arduino(ard_port)
self.ard.output([pin_LED, pin_Servo])
self.ard.setLow(pin_LED) # Initial
self.fname = fname
self.pump_init(pump_port)
示例15: __init__
def __init__(self, waypointFile=None):
"""Constructor for the boat object"""
self.arduino = Arduino()
self.gps = Gps()
self.xbee = Xbee()
self._waypointN = 0
self._waypointE = 0
self._waypointNumber = 0
self._waypointDist = 0
self._waypointHeading = 0
self._targetHeading = 0
self._targetDistance = 0
self.s = 0
self.c = 0
self.r = 250