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


Python Arduino.write方法代码示例

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


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

示例1: WhatsHappening

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import write [as 别名]
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))
开发者ID:obihann,项目名称:whats-happening,代码行数:30,代码来源:WhatsHappening.py

示例2: Capture

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import write [as 别名]
class Capture():
    '''Set cam, shot and save shot.'''
    def __init__(self, cf):
        self.cf = cf
        if not self.cf["inverse"]:
            self.w = self.cf["width"]
            self.h = self.cf["height"]
        else:
            self.w = self.cf["height"]
            self.h = self.cf["width"]

        # Init device
        self.capture = cv2.VideoCapture(int(self.cf["cam"]))
        self.set_capture()
        self.arduino = None
        self.arduino_init()
        # Init windows: TODO scale en auto ?
        self.rawWin = Window("Raw", self.w, self.h, 0.6, None, cf, None)
        self.grayWin = Window("Gray", self.w, self.h, 0.5, COLOR, self.cf,
                                                        self.cf["webcam"])
        self.barWin = Window("Trackbar", 500, 1, 1, GEOM, self.cf, "scan")
        self.shotWin = Window("Shot in progress", self.w, self.h, 0.5, None,
                                                            self.cf, None)

    def set_capture(self):
        self.capture.set(3, self.cf["width"])
        self.capture.set(4, self.cf["height"])
        apply_all_cam_settings(self.cf)

    def arduino_init(self):
        self.arduino = Arduino(self.cf["ard_dev"])
        # Left Laser on so we can see that it's ok
        self.arduino.write('G')

    def set_cam_position(self):
        while True:
            ret, frame = self.capture.read()
            if ret:
                # Rotate and flip
                if self.cf["inverse"]:
                    rot = cv2.flip(cv2.transpose(frame), 1)
                else:
                    rot = frame
                # Display raw
                rot = self.rawWin.add_lines(rot, self.cf)
                self.rawWin.display(rot, self.cf)

                # Display grayscale image
                gray = cv2.cvtColor(rot, cv2.COLOR_BGR2GRAY)
                self.grayWin.display(gray, self.cf)

                # Display trackbar
                sw_old = self.barWin.win_set["laser"]
                self.barWin.display(gray, self.cf)
                sw_new = self.barWin.win_set["laser"]

                # Update laser
                laser_L_or_R(self.arduino, sw_old, sw_new)

                # wait for esc key to exit
                key = np.int16(cv2.waitKey(33))
                if key == 27:
                    break
            else:
                print("Webcam is busy")
        cv2.destroyAllWindows()

    def shot(self):
        top = time()
        nb_shot = 0
        t_shot = time()
        set_laser("left", self.arduino)
        while True:
            way = "left"
            ret, frame = self.capture.read()
            if ret:
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                # Rotate 90°
                rotated = cv2.transpose(frame)
                # Display while shoting
                self.shotWin.display(rotated, self.cf)
                # Shot only if cam is stable, it's a very long time
                if time() - top > 5:
                    if way == "left":
                        # Shot every second until shot number
                        if nb_shot < self.cf["nb_img"]:
                            nb_shot, t_shot = take_shot(self.cf["tempo"],
                            t_shot, rotated, nb_shot, way, self.arduino,
                            self.cf["img_dir"])
                        else:
                            if self.cf["double"]:
                                way = "right"
                            else:
                                break
                    if way == "right":
                        set_laser(way, self.arduino)
                        # Shot every second until shot number
                        if nb_shot < self.cf["nb_img"] * 2:
                            nb_shot, t_shot = take_shot(self.cf["tempo"],
                            t_shot, rotated, nb_shot, way, self.arduino,
#.........这里部分代码省略.........
开发者ID:sergeLabo,项目名称:Skandal2.7,代码行数:103,代码来源:capture.py

示例3: init_arduino

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import write [as 别名]
def init_arduino(cf):
    arduino = Arduino(cf)
    # Left Laser on
    arduino.write('G')
    return arduino
开发者ID:Ldiz,项目名称:3Dscan,代码行数:7,代码来源:capture.py


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