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


Python Arduino.turnOff方法代码示例

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


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

示例1: str

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import turnOff [as 别名]

try:
    for p in serial.tools.list_ports.comports():
        if re.search('Arduino',str(p[1])):
            portString = str(p[0])
except:
    print "Could not open port!"
    sys.exit()

b = Arduino(portString)
pin = (1, 2, 3, 4, 5, 6, 7, 8)

#declare output pins as a list/tuple
b.output([pin])
b.turnOff()

try:
    while True:
        i=0
        while (i<8):
            b.setHigh(pin[i])
            time.sleep(.1)
            b.setLow(pin[i])
            time.sleep(.01)
            i+=1

except KeyboardInterrupt:
    while (i<8):
        b.setLow(pin[i])
        i+=1
开发者ID:cap10subtext,项目名称:PingCanal,代码行数:32,代码来源:sample_blink.py

示例2: MainWindow

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import turnOff [as 别名]

#.........这里部分代码省略.........
        sizer_SwitchBar.Add(sizer_Switch_7_Slot, 1, wx.LEFT|wx.RIGHT|wx.EXPAND, 12)
        sizer_Switch_8_Slot.Add(self.choice_Switch_8, 0, wx.EXPAND, 0)
        sizer_Switch_8_Slot.Add(self.label_1_copy_6, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
        sizer_SwitchBar.Add(sizer_Switch_8_Slot, 1, wx.LEFT|wx.RIGHT|wx.EXPAND, 12)
        sizer_Main.Add(sizer_SwitchBar, 1, wx.ALL|wx.EXPAND, 3)
        sizer_Main.Add(self.static_line_1, 0, wx.TOP|wx.BOTTOM|wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL, 5)
        sizer_Main.Add(self.text_ctrl_Status, 2, wx.LEFT|wx.RIGHT|wx.EXPAND, 20)
        sizer_ButtonBar.Add(self.button_ReadConfig, 0, wx.LEFT|wx.RIGHT, 10)
        sizer_ButtonBar.Add(self.button_ApplyConfig, 0, wx.LEFT|wx.RIGHT, 10)
        sizer_Main.Add(sizer_ButtonBar, 1, wx.LEFT|wx.RIGHT|wx.TOP|wx.ALIGN_CENTER_HORIZONTAL, 10)
        sizer_Main.Add((20, 10), 0, wx.EXPAND, 0)
        self.SetSizer(sizer_Main)
        sizer_Main.Fit(self)
        sizer_Main.SetSizeHints(self)
        self.Layout()
        # end wxGlade

    def windowPrintLn(self, text):
        """Print a string to the terminal within the main window and a newline character"""
        self.text_ctrl_Status.WriteText(text + "\n")
            
    def OnAbout(self, event): # wxGlade: MainWindow.<event_handler>
        #self.windowPrintLn('Event handler "OnAbout" not implemented!')
        event.Skip()

    def OnExit(self, event): # wxGlade: MainWindow.<event_handler>
        if self.arduino is not None:
            self.arduino.close()
        dlg = wx.MessageDialog(self, 
            "Do you really want to close this application?",
            "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
        result = dlg.ShowModal()
        dlg.Destroy()
        if result == wx.ID_OK:
            self.Destroy()
    
    def OnContent(self, event): # wxGlade: MainWindow.<event_handler>
        #self.windowPrintLn("Event handler `OnContent' not implemented!")
        event.Skip()

    def OnReadConfig(self, event): # wxGlade: MainWindow.<event_handler>
        self.windowPrintLn('')
        if self.arduino is None:
            self.windowPrintLn("Must connect to the arduino first! (File->Change Serial Port)")
            return
        for pin, value in zip(self.arduinoPinMap, self.switchList):
            if self.arduino.getState(pin) is False:
                self.windowPrintLn("Pin " + str(pin) + " is LOW")
                value.SetSelection(0)
            else:
                self.windowPrintLn("Pin " + str(pin) + " is HIGH")
                value.SetSelection(1)
            
    
    def OnApplyConfig(self, event): # wxGlade: MainWindow.<event_handler>
        self.windowPrintLn('')
        if self.arduino is None:
            self.windowPrintLn("Must connect to the arduino first! (File->Change Serial Port)")
            return
        for pin, value in zip(self.arduinoPinMap, self.switchList):
            if value.GetSelection() is 0:
                self.windowPrintLn(''.join(['Set pin ', str(pin), ' to LOW']))
                self.arduino.setLow(pin)
            else:
                self.windowPrintLn(''.join(['Set pin ', str(pin), ' to HIGH']))
                self.arduino.setHigh(pin)

    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
开发者ID:webbhorn,项目名称:Arduino-Switch-Controller,代码行数:104,代码来源:MainWindow.py


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