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


Python GPIO.setup方法代码示例

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


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

示例1: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def __init__(self, id, params):
		super(Buzzer, self).__init__(id, params)
		try:
			self.duration = int(params["duration"])
			self.gpio_pin = int(params["gpio_pin"])
		except KeyError as ke: # if config parameters are missing in file
			logging.error("Buzzer: Wasn't able to initialize the device, it seems there is a config parameter missing: %s" % ke)
			self.corrupted = True
			return
		except ValueError as ve: # if a parameter can't be parsed as int
			logging.error("Buzzer: Wasn't able to initialize the device, please check your configuration: %s" % ve)
			self.corrupted = True
			return

		try:
			GPIO.setmode(GPIO.BCM)
			GPIO.setup(self.gpio_pin, GPIO.OUT)
		except ValueError as ve: # GPIO pin number is not in valid range
			logging.error("Buzzer: The given pin number is not in a valid range: %s" % ve)
			self.corrupted = True
			return
		logging.debug("Buzzer: Audio device initialized") 
开发者ID:SecPi,项目名称:SecPi,代码行数:24,代码来源:buzzer.py

示例2: writeByte

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def writeByte(self, data):
        for i in range(0, 8):
            IO.output(self.__Clkpin, IO.LOW)
            if(data & 0x01):
                IO.output(self.__Datapin, IO.HIGH)
            else:
                IO.output(self.__Datapin, IO.LOW)
            data = data >> 1
            IO.output(self.__Clkpin, IO.HIGH)

        # wait for ACK
        IO.output(self.__Clkpin, IO.LOW)
        IO.output(self.__Datapin, IO.HIGH)
        IO.output(self.__Clkpin, IO.HIGH)
        IO.setup(self.__Datapin, IO.IN)

        while(IO.input(self.__Datapin)):
            sleep(0.001)
            if(IO.input(self.__Datapin)):
                IO.setup(self.__Datapin, IO.OUT)
                IO.output(self.__Datapin, IO.LOW)
                IO.setup(self.__Datapin, IO.IN)
        IO.setup(self.__Datapin, IO.OUT) 
开发者ID:timwaizenegger,项目名称:raspberrypi-examples,代码行数:25,代码来源:tm1637.py

示例3: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def __init__(self):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)

        GPIO.setup(self.MotorFront1, GPIO.OUT)
        GPIO.setup(self.MotorFront2, GPIO.OUT)
        GPIO.setup(self.MotorFront, GPIO.OUT)
        GPIO.output(self.MotorFront, 0)

        GPIO.setup(self.MotorBack1, GPIO.OUT)
        GPIO.setup(self.MotorBack2, GPIO.OUT)
        GPIO.setup(self.MotorBack, GPIO.OUT)
        GPIO.output(self.MotorBack, 0)
        self.BackPWM = GPIO.PWM(self.MotorBack,100)
        self.BackPWM.start(0)
        self.BackPWM.ChangeDutyCycle(0)
        
        self.direction = 0 
开发者ID:yazeedalrubyli,项目名称:SDRC,代码行数:20,代码来源:drive.py

示例4: InitHardware

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def InitHardware(self):

        # NOTE: This function assumes the underlying hardware is the LTE Cat 1 Pi Hat
        # http://wiki.seeedstudio.com/LTE_Cat_1_Pi_HAT/

        try:
            self.power_pin = 29
            self.reset_pin = 31
            GPIO.setmode(GPIO.BOARD)
            GPIO.setwarnings(False)
            GPIO.setup(self.power_pin, GPIO.OUT) # Setup module power pin
            GPIO.setup(self.reset_pin, GPIO.OUT) # Setup module reset pin
            GPIO.output(self.power_pin, False)
            GPIO.output(self.reset_pin, False)

            return self.PowerUp()
        except Exception as e1:
            self.LogErrorLine("Error in LTEPiHat:InitHardware: " + str(e1))
            return False
    #------------------LTEPiHat::PowerDown------------------------------------- 
开发者ID:jgyates,项目名称:genmon,代码行数:22,代码来源:mymodem.py

示例5: readUltrasonicSensor

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def readUltrasonicSensor():
    GPIO.setup(TRIGGER_PIN, GPIO.OUT)
    GPIO.setup(SENSOR_PIN, GPIO.IN)
    GPIO.output(TRIGGER_PIN, GPIO.LOW)
    time.sleep(0.3)
    GPIO.output(TRIGGER_PIN, True)
    time.sleep(0.00001)
    GPIO.output(TRIGGER_PIN, False)
    while GPIO.input(SENSOR_PIN) == 0:
        signaloff = time.time()
    while GPIO.input(SENSOR_PIN) == 1:
        signalon = time.time()
    timepassed = signalon - signaloff
    distance = timepassed * 17000
    if distance < threshold:
        return 1
    else:
        return 0 
开发者ID:nature1995,项目名称:ran-django-template,代码行数:20,代码来源:controller.py

示例6: saks_gpio_init

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def saks_gpio_init(self):
        #print 'saks_gpio_init'
        GPIO.setwarnings(False)
        GPIO.cleanup()
        GPIO.setmode(GPIO.BCM)

        GPIO.setup(PINS.BUZZER, GPIO.OUT)
        GPIO.output(PINS.BUZZER, GPIO.HIGH)

        for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]:
            GPIO.setup(p, GPIO.OUT)
            GPIO.output(p, GPIO.LOW)

        for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
            GPIO.setup(p, GPIO.OUT)
            GPIO.output(p, GPIO.HIGH)

        for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
            GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP) 
开发者ID:spoonysonny,项目名称:SAKS-SDK,代码行数:21,代码来源:sakshat.py

示例7: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def setup():
    """Setup piezo buzzer."""
    global _is_setup, pwm

    if _is_setup:
        return

    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(BUZZER, GPIO.OUT)

    # Set up the PWM and then set the pin to input
    # to prevent the signal from being output.
    # Since starting/stopping PWM causes a segfault,
    # this is the only way to manage the buzzer.

    pwm = GPIO.PWM(BUZZER, 1)
    GPIO.setup(BUZZER, GPIO.IN)
    pwm.start(50)

    _is_setup = True 
开发者ID:pimoroni,项目名称:rainbow-hat,代码行数:23,代码来源:buzzer.py

示例8: note

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def note(frequency, duration=1.0):
    """Play a single note.

    :param frequency: Musical frequency in hertz
    :param duration: Optional duration in seconds, use None to sustain note

    """
    global _timeout

    setup()

    if frequency <= 0:
        raise ValueError("Frequency must be > 0")

    if duration is not None and duration <= 0:
        raise ValueError("Duration must be > 0")

    clear_timeout()

    pwm.ChangeFrequency(frequency)
    GPIO.setup(BUZZER, GPIO.OUT)

    if duration is not None and duration > 0:
        _timeout = Timer(duration, stop)
        _timeout.start() 
开发者ID:pimoroni,项目名称:rainbow-hat,代码行数:27,代码来源:buzzer.py

示例9: show

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def show():
    """Output the buffer."""
    global _gpio_setup

    if not _gpio_setup:
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup([DAT, CLK, CS], GPIO.OUT)
        _gpio_setup = True

    GPIO.output(CS, 0)
    _sof()

    for pixel in pixels:
        r, g, b, brightness = pixel
        _write_byte(0b11100000 | brightness)
        _write_byte(b)
        _write_byte(g)
        _write_byte(r)

    _eof()
    GPIO.output(CS, 1) 
开发者ID:pimoroni,项目名称:rainbow-hat,代码行数:24,代码来源:apa102.py

示例10: set_74HC595_pins

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def set_74HC595_pins(self, DIR_LATCH, DIR_CLK, DIR_SER):
        """
        Set PINs used on Raspberry Pi to connect with 74HC595 module on
        Arduino Motor Shield

        :param int DIR_LATCH: LATCH PIN number
        :param int DIR_CLK: CLK PIN number
        :param int DIR_SER: SER  PIN number
        """
        self._DIR_LATCH = DIR_LATCH
        self._DIR_CLK = DIR_CLK
        self._DIR_SER = DIR_SER

        GPIO.setup(self._DIR_LATCH, GPIO.OUT)
        GPIO.setup(self._DIR_CLK, GPIO.OUT)
        GPIO.setup(self._DIR_SER, GPIO.OUT) 
开发者ID:lipoja,项目名称:AMSpi,代码行数:18,代码来源:AMSpi.py

示例11: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def __init__(self,
                 channel,
                 polarity=GPIO.FALLING,
                 pull_up_down=GPIO.PUD_UP,
                 debounce_time=0.08):
        if polarity not in [GPIO.FALLING, GPIO.RISING]:
            raise ValueError(
                'polarity must be one of: GPIO.FALLING or GPIO.RISING')

        self.channel = int(channel)
        self.polarity = polarity
        self.expected_value = polarity == GPIO.RISING
        self.debounce_time = debounce_time

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down)

        self.callback = None 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:21,代码来源:_button.py

示例12: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def setup(busnum=None):
	global openPWM, homePWM, pwm
	openPWM = 420
	homePWM = 700
	offset =0
	try:
		for line in open('config'):
			if line[0:8] == 'offset =':
				offset = int(line[9:-1])
	except:
		print("config error")
	openPWM += offset
	homePWM += offset
	if busnum == None:
		pwm = servo.PWM()                  # Initialize the servo controller.
	else:
		pwm = servo.PWM(bus_number=busnum) # Initialize the servo controller.
	pwm.frequency = 60 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:20,代码来源:smart_trash_can.py

示例13: main

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def main():
	setup()
	while 1:
		retry_game = True
		button = False
		recog=kws_test()
		say_exit = '종료'.decode('utf-8')
		if recog == 200:
			gt2vt.getText2VoiceStream("안녕하세요 영리한 휴지통입니다","./stc_opening.wav")
			gt2vt.play_file("./stc_opening.wav")
			time.sleep(0.8)
			while 1:
				if retry_game:
					text = gv2t.getVoice2Text()
					control_action(text)
					if(say_exit in text):
						gt2vt.getText2VoiceStream("감사합니다","./stc_thanku.wav")
						gt2vt.play_file("./stc_opening.wav")
						break
		else:
			print('Not play now ...') 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:23,代码来源:smart_trash_can.py

示例14: init_process

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def init_process():
	print " "
	print "MSG - [S100, T110 CO2 Sensor Driver on RASPI2, Please check log file : ", LOG_PATH
	print "MSG - now starting to read SERIAL PORT"
	print " "
	# HW setup, GPIO
	GPIO.setwarnings(False)
	GPIO.cleanup()
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(18, GPIO.OUT)
	GPIO.setup(23, GPIO.OUT)
	GPIO.setup(24, GPIO.OUT)
	GPIO.setup(25, GPIO.OUT)
	logger.info(' *start* GPIO all set, trying to open serial port, SW starting ')
	rledAllOn()

######################################################################
# START Here. Main
######################################################################

# set logger file 
开发者ID:jeonghoonkang,项目名称:BerePi,代码行数:23,代码来源:co2_t110.py

示例15: lcd_init

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import setup [as 别名]
def lcd_init():

  GPIO.setmode(GPIO.BCM)       # Use BCM GPIO numbers
  GPIO.setup(LCD_E, GPIO.OUT)  # E
  GPIO.setup(LCD_RS, GPIO.OUT) # RS
  GPIO.setup(LCD_D4, GPIO.OUT) # DB4
  GPIO.setup(LCD_D5, GPIO.OUT) # DB5
  GPIO.setup(LCD_D6, GPIO.OUT) # DB6
  GPIO.setup(LCD_D7, GPIO.OUT) # DB7
  #GPIO.setup(LED_ON, GPIO.OUT) # Backlight enable
  GPIO.setup(LCD_RED, GPIO.OUT) # RED Backlight enable
  GPIO.setup(LCD_GREEN, GPIO.OUT) # GREEN Backlight enable
  GPIO.setup(LCD_BLUE, GPIO.OUT) # BLUEBacklight enable

  # Initialise display
  lcd_byte(0x33,LCD_CMD) # 110011 Initialise
  lcd_byte(0x32,LCD_CMD) # 110010 Initialise
  lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
  lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
  lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
  lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  time.sleep(E_DELAY) 
开发者ID:jeonghoonkang,项目名称:BerePi,代码行数:24,代码来源:lcd.py


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