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


Python GPIO.PWM属性代码示例

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


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

示例1: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [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

示例2: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def __init__(self):
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.dir_pin, GPIO.OUT)
        GPIO.setup(self.pulse_pin, GPIO.OUT)
        GPIO.setup(self.ms1_pin, GPIO.OUT)
        GPIO.setup(self.ms2_pin, GPIO.OUT)
        GPIO.setup(self.sleep_pin, GPIO.OUT)
        GPIO.setup(self.reset_pin, GPIO.OUT)
        dir=False
        GPIO.output(self.dir_pin, dir)
        GPIO.output(self.pulse_pin, False)
        GPIO.output(self.ms1_pin, True)
        GPIO.output(self.ms2_pin, False)
        GPIO.output(self.sleep_pin, False)
        GPIO.output(self.reset_pin, True)
        self.p1 = GPIO.PWM(self.pulse_pin, self.pulse_freq) 
开发者ID:jphfilm,项目名称:rpi-film-capture,代码行数:18,代码来源:control.py

示例3: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [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

示例4: write

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def write(self, reason, value):
        status = True

        if reason == 'OUT':
            GPIO.output(PIN_OUT, value)
        elif reason == 'TRIG':
            GPIO.output(PIN_OUT, GPIO.HIGH)
            time.sleep(0.1)
            GPIO.output(PIN_OUT, GPIO.LOW)
            value = 0
        elif reason == 'PWM':
            if value == 0:
                self.pwm.stop()
            else:
                self.pwm.start(self.getParam('DC'))
        elif reason == 'DC':
            self.pwm.ChangeDutyCycle(value)
        elif reason == 'FREQ':
            self.pwm.ChangeFrequency(value)
        else:
            status = False

        if status:
            self.setParam(reason, value)
        return status 
开发者ID:paulscherrerinstitute,项目名称:pcaspy,代码行数:27,代码来源:rpi_gpio.py

示例5: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def __init__(self, red_pin, green_pin, blue_pin):
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        self.RED_PIN, self.GREEN_PIN, self.BLUE_PIN = red_pin, green_pin, blue_pin

        GPIO.setup(self.RED_PIN, GPIO.OUT)
        self.red_pwm = GPIO.PWM(self.RED_PIN, 500)
        self.red_pwm.start(0)
        
        GPIO.setup(self.GREEN_PIN, GPIO.OUT)
        self.green_pwm = GPIO.PWM(self.GREEN_PIN, 500)
        self.green_pwm.start(0)
        
        GPIO.setup(self.BLUE_PIN, GPIO.OUT)
        self.blue_pwm = GPIO.PWM(self.BLUE_PIN, 500)
        self.blue_pwm.start(0) 
开发者ID:simonmonk,项目名称:squid,代码行数:18,代码来源:squid.py

示例6: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def setup():
	global p_R, p_G, p_B
	# Set the GPIO modes to BCM Numbering
	GPIO.setmode(GPIO.BCM)
	# Set all LedPin's mode to output, 
	# and initial level to High(3.3v)
	for i in pins:
		GPIO.setup(pins[i], GPIO.OUT, initial=GPIO.HIGH)

	# Set all led as pwm channel,
	#  and frequece to 2KHz
	p_R = GPIO.PWM(pins['Red'], 2000)
	p_G = GPIO.PWM(pins['Green'], 2000)
	p_B = GPIO.PWM(pins['Blue'], 2000)

	# Set all begin with value 0
	p_R.start(0)
	p_G.start(0)
	p_B.start(0)

# Define a MAP function for mapping values.
# Like from 0~255 to 0~100 
开发者ID:sunfounder,项目名称:SunFounder_Super_Kit_V3.0_for_Raspberry_Pi,代码行数:24,代码来源:05_rgb.py

示例7: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def setup():#Motor initialization
	global pwm_A, pwm_B
	GPIO.setwarnings(False)
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(Motor_A_EN, GPIO.OUT)
	GPIO.setup(Motor_B_EN, GPIO.OUT)
	GPIO.setup(Motor_A_Pin1, GPIO.OUT)
	GPIO.setup(Motor_A_Pin2, GPIO.OUT)
	GPIO.setup(Motor_B_Pin1, GPIO.OUT)
	GPIO.setup(Motor_B_Pin2, GPIO.OUT)

	motorStop()
	try:
		pwm_A = GPIO.PWM(Motor_A_EN, 1000)
		pwm_B = GPIO.PWM(Motor_B_EN, 1000)
	except:
		pass 
开发者ID:adeept,项目名称:Adeept_RaspTank,代码行数:19,代码来源:move.py

示例8: blink

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def blink(self, on=1, off=-1):
        """Blinks an LED by working out the correct PWM frequency/duty cycle

        @param self Object pointer.
        @param on Time the LED should stay at 100%/on
        @param off Time the LED should stay at 0%/off"""

        self.stop()

        if off == -1:
            off = on

        off = float(off)
        on = float(on)

        total = off + on

        duty_cycle = 100.0 * (on/total)

        # Use pure PWM blinking, because threads are ugly
        self.frequency(1.0/total)
        self.duty_cycle(duty_cycle)
        self.blinking = True

        return True 
开发者ID:pimoroni,项目名称:explorer-hat,代码行数:27,代码来源:__init__.py

示例9: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def setup():
	global p_R, p_G, p_B
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(Rpin, GPIO.OUT)
	GPIO.setup(Gpin, GPIO.OUT)
	GPIO.setup(Bpin, GPIO.OUT)

	p_R = GPIO.PWM(Rpin, 2000) # Set Frequece to 2KHz
	p_G = GPIO.PWM(Gpin, 2000)
	p_B = GPIO.PWM(Bpin, 2000)

	p_R.start(100)
	p_G.start(100)
	p_B.start(100)
	err = pylirc.init("ircontrol", "./lircrc", blocking)
	print(err)
	if (err == 0):
		raise IOError("IR init error!") 
开发者ID:sunfounder,项目名称:SunFounder_SensorKit_for_RPi2,代码行数:20,代码来源:23_ircontrol.py

示例10: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def setup(Rpin, Gpin, Bpin):
	global pins
	global p_R, p_G, p_B
	pins = {'pin_R': Rpin, 'pin_G': Gpin, 'pin_B': Bpin}
	GPIO.setmode(GPIO.BOARD)       # Numbers GPIOs by physical location
	for i in pins:
		GPIO.setup(pins[i], GPIO.OUT)   # Set pins' mode is output
		GPIO.output(pins[i], GPIO.HIGH) # Set pins to high(+3.3V) to off led
	
	p_R = GPIO.PWM(pins['pin_R'], 2000)  # set Frequece to 2KHz
	p_G = GPIO.PWM(pins['pin_G'], 1999)
	p_B = GPIO.PWM(pins['pin_B'], 5000)
	
	p_R.start(100)      # Initial duty Cycle = 0(leds off)
	p_G.start(100)
	p_B.start(100) 
开发者ID:sunfounder,项目名称:SunFounder_SensorKit_for_RPi2,代码行数:18,代码来源:02_rgb_led.py

示例11: write_pwm

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def write_pwm(self, gpio, pwm_value, queue_id=None):
        try:
            if queue_id is not None:
                self._logger.debug("running scheduled queue id %s", queue_id)
            for pwm in self.pwm_instances:
                if gpio in pwm:
                    pwm_object = pwm[gpio]
                    old_pwm_value = pwm['duty_cycle'] if 'duty_cycle' in pwm else -1
                    if not self.to_int(old_pwm_value) == self.to_int(pwm_value):
                        pwm['duty_cycle'] = pwm_value
                        pwm_object.start(pwm_value) #should be changed back to pwm_object.ChangeDutyCycle() but this
                        # was causing errors.
                        self._logger.debug("Writing PWM on gpio: %s value %s", gpio, pwm_value)
                    self.update_ui()
                    if queue_id is not None:
                        self.stop_queue_item(queue_id)
                    break
        except Exception as ex:
            self.log_error(ex)
            pass 
开发者ID:vitormhenrique,项目名称:OctoPrint-Enclosure,代码行数:22,代码来源:__init__.py

示例12: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def __init__(self, red, green, blue, pinmode=GPIO.BOARD, freq=50):
        GPIO.setmode(pinmode)
        self.pins = {
            "red": red,
            "green": green,
            "blue": blue
            }
        for pin in self.pins.values():
            GPIO.setup(pin, GPIO.OUT)

        # Turn all on and all off
        for pin in self.pins.values():
            GPIO.output(pin, GPIO.HIGH)
            GPIO.output(pin, GPIO.LOW)

        self.pwms = dict([
             (name, GPIO.PWM(pin, freq))
             for name, pin in self.pins.items()
            ])
        for pwm in self.pwms.values():
            pwm.start(0) 
开发者ID:PacktPublishing,项目名称:Mastering-GUI-Programming-with-Python,代码行数:23,代码来源:three_color_led_gui.py

示例13: screen_off

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

    screen.canvas.fill(black)
    pygame.display.update()
    if backlightControl == "3.5r":
        process = subprocess.call("echo '0' > /sys/class/backlight/soc\:backlight/brightness", shell=True)
    elif backlightControl == "4dpi-24":
        process = subprocess.call("echo '0' > /sys/class/backlight/24-hat-pwm/brightness", shell=True)
    elif backlightControl == "pi70":
        process = subprocess.call("echo '1' > /sys/class/backlight/rpi_backlight/bl_power", shell=True)
    elif backlightControl == "hyperpixel4":
        process = subprocess.call("echo '1' > /sys/class/backlight/rpi_backlight/brightness", shell=True)
    else:
        backlight = GPIO.PWM(18, 0.1)
        backlight.start(0)

    process = subprocess.call("setterm -term linux -back black -fore white -clear all", shell=True)
    return()


# Input loop for touch event 
开发者ID:Re4son,项目名称:Kali-Pi,代码行数:23,代码来源:kalipi.py

示例14: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def __init__(self):
        GPIO_motor_1 = 18  # GPIO setting (BCM coding)
        GPIO_motor_4 = 23
        GPIO_motor_5 = 24
        GPIO_motor_6 = 25

        GPIO.setup(GPIO_motor_1, GPIO.OUT)  # GPIO input/output definiation
        GPIO.setup(GPIO_motor_4, GPIO.OUT)
        GPIO.setup(GPIO_motor_5, GPIO.OUT)
        GPIO.setup(GPIO_motor_6, GPIO.OUT)

        self.motor_1 = GPIO.PWM(GPIO_motor_1, 500)  # PWM initialization: 500 Hz
        self.motor_4 = GPIO.PWM(GPIO_motor_4, 500)
        self.motor_5 = GPIO.PWM(GPIO_motor_5, 500)
        self.motor_6 = GPIO.PWM(GPIO_motor_6, 500)

        self.motor_1.start(0)  # motors start
        self.motor_4.start(0)
        self.motor_5.start(0)
        self.motor_6.start(0) 
开发者ID:Mingrui-Yu,项目名称:RaspberryCar,代码行数:22,代码来源:move.py

示例15: led_pwm_handler

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import PWM [as 别名]
def led_pwm_handler(frequency=None, duty_cycle=None):
    """
    Change PWM frequency and/or duty cycle for LED.

    Optional arguments:
      - frequency (float): Change to frequency in Hz.
      - duty_cycle (float): Change to duty cycle in percent.
    """

    ret = {}

    if frequency != None:
        led_pwm.ChangeFrequency(frequency)  # Hz

    if duty_cycle != None:
        led_pwm.ChangeDutyCycle(duty_cycle)  # %

    return ret 
开发者ID:autopi-io,项目名称:autopi-core,代码行数:20,代码来源:spm_manager.py


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