當前位置: 首頁>>代碼示例>>Python>>正文


Python Program.set方法代碼示例

本文整理匯總了Python中program.Program.set方法的典型用法代碼示例。如果您正苦於以下問題:Python Program.set方法的具體用法?Python Program.set怎麽用?Python Program.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在program.Program的用法示例。


在下文中一共展示了Program.set方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GushPiBot

# 需要導入模塊: from program import Program [as 別名]
# 或者: from program.Program import set [as 別名]
class GushPiBot(object):
    """
    This class controls the menu and programming and operates the main event loop
    """
    def __init__(self):
        self.components = []
        self.active = True
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)

    def startup(self):
        self.create_display()
        self.create_menu()
        self.create_wheels()
        self.create_program()
        if BUTTONS_AVAILABLE:
            self.create_buttons()
        if WEBCAM_AVAILABLE:
            self.create_webcam()
        if WII_AVAILABLE:
            self.create_wiimote()
        if ECHO_AVAILABLE:
            self.create_echo()
        if SPEECH_AVAILABLE:
            self.create_speech()
        if AUDIO_AVAILABLE:
            self.create_audio()
        if WEBSERVER_AVAILABLE:
            self.create_webserver()
        self.create_keyboard()
        self.update_menu()
        self.display.display_at(1, 0, "Init complete")

    def add_component(self, text, component):
        self.components.append(component)
        self.display.display_at(1, 0, "Created " + text)

    def create_display(self):
        if LCD_AVAILABLE:
            self.display = LCDDisplay()
        else:
            self.display = ConsoleDisplay()
        self.display.display("GushPiBot...")
        self.display_ip()
        self.add_component("Display", self.display)

    def create_wheels(self):
        self.wheels = Wheels()
        self.add_component("Wheels", self.wheels)

    def create_program(self):
        self.command = 0
        self.program = Program(self.display)
        self.program.add_command("^", "Forward", self.wheels.forwards, self.wheels.stop)
        self.program.add_command("v", "Backward", self.wheels.backwards, self.wheels.stop)
        self.program.add_command("<", "Left", self.wheels.left, self.wheels.stop)
        self.program.add_command(">", "Right", self.wheels.right, self.wheels.stop)
        self.program.add_command("{", "Slow Left", self.wheels.slow_left, self.wheels.stop)
        self.program.add_command("}", "Slow Right", self.wheels.slow_right, self.wheels.stop)
        self.add_component("Program", self.program)

    def create_buttons(self):
        self.buttons = Buttons()
        self.buttons.handlers["MENU"].add(self.menu.next)
        self.buttons.handlers["SELECT"].add(self.menu.select)
        self.add_component("Buttons", self.buttons)

    def create_webcam(self):
        self.webcam = Webcam()
        self.program.add_command("#", "Photo", self.webcam.take_photo)
        self.add_component("Webcam", self.webcam)

    def create_wiimote(self):
        self.wiimote = Wiimote(self.display)
        self.wiimote.handlers["UP"].add(self.wheels.forwards)
        self.wiimote.handlers["DOWN"].add(self.wheels.backwards)
        self.wiimote.handlers["LEFT"].add(self.wheels.left)
        self.wiimote.handlers["RIGHT"].add(self.wheels.right)
        self.wiimote.handlers["A"].add(self.wheels.stop)
        try:
            self.wiimote.handlers["B"].add(self.webcam.take_photo)
        except AttributeError:
           pass
        self.wiimote.handlers["HOME"].add(self.menu.select)
        self.wiimote.handlers["MINUS"].add(self.menu.prev)
        self.wiimote.handlers["PLUS"].add(self.menu.next)
        self.wiimote.stop_handler = self.wheels.stop
        self.add_component("Wiimote", self.wiimote)

    def create_speech(self):
        self.speech = Speech()
        self.speech.speak("Hello. I am Gush Pi Bot.")
        self.wheels.speech_handler.add(self.speech.speak)
        self.add_component("Speech", self.speech)

    def create_audio(self):
        self.audio = Audio()
        self.add_component("Audio", self.audio)

    def create_echo(self):
#.........這裏部分代碼省略.........
開發者ID:gushie,項目名稱:gushpibot,代碼行數:103,代碼來源:gushpibot.py


注:本文中的program.Program.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。