python类PWM的实例源码

CandleSimulation.py 文件源码 项目:52-Weeks-of-Pi 作者: grantwinney 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def red_light():
    p = GPIO.PWM(R, 300)
    p.start(100)
    pwms.append(p)
    while True:
        p.ChangeDutyCycle(min(random.randint(75, 100) * math.pow(intensity + 0.1, 0.75), 100) if intensity > 0 else 0)
        rand_flicker_sleep()
earthquakepi.py 文件源码 项目:earthquakepi 作者: rgrokett 项目源码 文件源码 阅读 68 收藏 0 点赞 0 评论 0
def motor2(mag):    # If needed, use on/off motor instead of PWM
    GPIO.output(MOTORPIN, True)
    time.sleep(int(mag))
    GPIO.output(MOTORPIN, False)
    return
EdBot.py 文件源码 项目:CamJam-Robotic_kit 作者: Corteil 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, pin_fw, pin_bw):
        self._invert = False
        self.pin_fw = pin_fw
        self.pin_bw = pin_bw
        self._speed = 0

        GPIO.setup(self.pin_fw, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(self.pin_bw, GPIO.OUT, initial=GPIO.LOW)

        self.pwm_fw = GPIO.PWM(self.pin_fw, 100)
        self.pwm_fw.start(0)

        self.pwm_bw = GPIO.PWM(self.pin_bw, 100)
        self.pwm_bw.start(0)
initio.py 文件源码 项目:AI-Robot 作者: ssebastian 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def init():
    global p, q, a, b
    # Initialise the PWM device using the default address

    #use physical pin numbering
    GPIO.setmode(GPIO.BOARD)
    #print GPIO.RPI_REVISION

    #set up digital line detectors as inputs
    GPIO.setup(lineRight, GPIO.IN) # Right line sensor
    GPIO.setup(lineLeft, GPIO.IN) # Left line sensor

    #Set up IR obstacle sensors as inputs
    GPIO.setup(irFL, GPIO.IN) # Left obstacle sensor
    GPIO.setup(irFR, GPIO.IN) # Right obstacle sensor

    #use pwm on inputs so motors don't go too fast
    GPIO.setup(L1, GPIO.OUT)
    p = GPIO.PWM(L1, 20)
    p.start(0)

    GPIO.setup(L2, GPIO.OUT)
    q = GPIO.PWM(L2, 20)
    q.start(0)

    GPIO.setup(R1, GPIO.OUT)
    a = GPIO.PWM(R1, 20)
    a.start(0)

    GPIO.setup(R2, GPIO.OUT)
    b = GPIO.PWM(R2, 20)
    b.start(0)

    startServos()

# cleanup(). Sets all motors off and sets GPIO to standard values
pi_pwm.py 文件源码 项目:qudi 作者: Ulm-IQO 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setupPins(self):
        """ Set Raspberry Pi GPIO pins to the right mode.
        """
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.enapin, GPIO.OUT)
        GPIO.setup(self.enbpin, GPIO.OUT)
        GPIO.setup(self.inapin, GPIO.OUT)
        GPIO.setup(self.inbpin, GPIO.OUT)
        GPIO.setup(self.pwmpin, GPIO.OUT)
        GPIO.setup(self.fanpin, GPIO.OUT)
        GPIO.setup(self.diapin, GPIO.IN)
        GPIO.setup(self.dibpin, GPIO.IN)
        self.p = GPIO.PWM(self.pwmpin, self.freq)
pi_pwm.py 文件源码 项目:qudi 作者: Ulm-IQO 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def startPWM(self):
        """ Start the PWM output.
        """
        GPIO.output(self.fanpin, True)
        GPIO.output(self.enapin, True)
        GPIO.output(self.enbpin, True)
        GPIO.output(self.inapin, True)
        GPIO.output(self.inbpin, False)

        # Setup PWM and DMA channel 0
        self.p.start(0)
        self.dutycycle = 0
pi_pwm.py 文件源码 项目:qudi 作者: Ulm-IQO 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def stopPWM(self):
        """ Stop the PWM output.
        """
        # Stop PWM
        self.p.stop()
        GPIO.output(self.enapin, False)
        GPIO.output(self.enbpin, False)
        GPIO.output(self.inapin, False)
        GPIO.output(self.inbpin, False)
        GPIO.output(self.fanpin, False)
pi_pwm.py 文件源码 项目:qudi 作者: Ulm-IQO 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def changeDutyCycle(self, duty):
        """ Set the PWM duty cycle in percent.

            @param float duty: PWM duty cycle 0 < duty < 100
        """
        self.dutycycle = 0
        if duty >= 0:
            GPIO.output(self.inapin, True)
            GPIO.output(self.inbpin, False)
        else:
            GPIO.output(self.inapin, False)
            GPIO.output(self.inbpin, True)
        self.p.ChangeDutyCycle(abs(duty))
passive.py 文件源码 项目:indi-lite-tools 作者: GuLinux 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, gpio):
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(gpio, GPIO.OUT)
        self.pwm = GPIO.PWM(gpio, 1)
CANopen.py 文件源码 项目:canopen-rpi 作者: bggardner 项目源码 文件源码 阅读 61 收藏 0 点赞 0 评论 0
def __init__(self, channel, init_state):
        import RPi.GPIO as GPIO
        GPIO.setup(channel, GPIO.OUT)
        self._pwm = GPIO.PWM(channel, init_state.get('Frequency'))
        self._pwm.start(init_state.get('DutyCycle'))
L298NHBridge.py 文件源码 项目:raspberry 作者: ykevin 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def InitPWM(self): 
        # Here we configure the GPIO settings for the left and right motors spinning speed. 
        # It defines the two GPIO pins used as input on the L298 H-Bridge to set the motor speed with a PWM signal.
        self.leftmotorpwm.start(0)
        self.leftmotorpwm.ChangeDutyCycle(0)
        self.rightmotorpwm.start(0)
        self.rightmotorpwm.ChangeDutyCycle(0)
L298NHBridge.py 文件源码 项目:raspberry 作者: ykevin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def InitPWM(self): 
        # Here we configure the GPIO settings for the left and right motors spinning speed. 
        # It defines the two GPIO pins used as input on the L298 H-Bridge to set the motor speed with a PWM signal.
        self.leftmotorpwm.start(0)
        self.leftmotorpwm.ChangeDutyCycle(0)
        self.rightmotorpwm.start(0)
        self.rightmotorpwm.ChangeDutyCycle(0)
rgb_led.py 文件源码 项目:Raspberry-GPIO-Test 作者: rabidllamaofdoom 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_new_color(pin, frequency):
    GPIO.setup(pin, GPIO.OUT)    
    return GPIO.PWM(pin, frequency)
cylon_led.py 文件源码 项目:Raspberry-GPIO-Test 作者: rabidllamaofdoom 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_new_led(pin, frequency):
    GPIO.setup(pin, GPIO.OUT)
    return GPIO.PWM(pin, frequency)
pwm_led_02.py 文件源码 项目:Raspberry-GPIO-Test 作者: rabidllamaofdoom 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_new_led(pin, frequency):
    GPIO.setup(pin, GPIO.OUT)
    return GPIO.PWM(pin, frequency)

#execution
dcMotor.py 文件源码 项目:autonoom 作者: autonoom 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, motorPin):
        self.motorPin = motorPin
        # Setup GPIO
        # Broadcom SOCKET channel is used as standard
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.motorPin, GPIO.OUT)
        # Setup PWM with 100KHz
        self.motor = GPIO.PWM(self.motorPin, 100)
        # Start PWM
        self.motor.start(0)
        # Start on speed zero
        self.setZero()
servoMotor.py 文件源码 项目:autonoom 作者: autonoom 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, servoPin):
        self.servoPin = servoPin
        # Setup GPIO
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.servoPin, GPIO.OUT)
        # Setup PWM with 100KHz
        self.servo = GPIO.PWM(self.servoPin, 100)
        # Start PWM with dutycycle of 0%
        self.servo.start(0)
        self.zeroPosition()  # Set position to zero at start
beebot.py 文件源码 项目:ropi 作者: ThumbGen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def initGPIO():
    global p, q, a, b
    #use physical pin numbering
    GPIO.setmode(GPIO.BOARD)

    #set up digital line detectors as inputs
    GPIO.setup(lineRight, GPIO.IN) # Right line sensor
    GPIO.setup(lineLeft, GPIO.IN) # Left line sensor

    #use pwm on inputs so motors don't go too fast
    GPIO.setup(L1, GPIO.OUT)
    p = GPIO.PWM(L1, 20)
    p.start(0)

    GPIO.setup(L2, GPIO.OUT)
    q = GPIO.PWM(L2, 20)
    q.start(0)

    GPIO.setup(R1, GPIO.OUT)
    a = GPIO.PWM(R1, 20)
    a.start(0)

    GPIO.setup(R2, GPIO.OUT)
    b = GPIO.PWM(R2, 20)
    b.start(0)

    threadC = threading.Thread(target=wheelCount)
    threadC.start()

# spinLeft(speed): Sets motors to turn opposite directions at speed. 0 <= speed <= 100
pi2go.py 文件源码 项目:ropi 作者: ThumbGen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setAllLEDs (red, green, blue):
  for i in range(4):
    setLED(i, red, green, blue)

# End of RGB LED Functions
#======================================================================


#======================================================================
# White LED Functions
# (Pi2Go-Lite only)
#
# LsetLED(LED, value): Sets the LED specified to OFF == 0 or ON == 1
# TODO: take value from 0 to 100 and use as percentage PWM value
hwa.py 文件源码 项目:softconsole 作者: kevinkahn 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def initOS():
    global backlight
    os.environ['SDL_FBDEV'] = '/dev/fb1'
    os.environ['SDL_MOUSEDEV'] = '/dev/input/touchscreen'
    os.environ['SDL_MOUSEDRV'] = 'TSLIB'
    os.environ['SDL_VIDEODRIVER'] = 'fbcon'

    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(18, GPIO.OUT)
    backlight = GPIO.PWM(18, 1024)
    backlight.start(100)


问题


面经


文章

微信
公众号

扫码关注公众号