コード例 #1
0
ファイル: pwm_test2.py プロジェクト: vad-babushkin/NPi.GPIO
import NPi.GPIO as GPIO
import time

PIN_NUM = 12
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM, GPIO.OUT)

frequency = 50
p = GPIO.PWM(PIN_NUM, frequency)
p.start(0)

try:
    while True:
        for dutyCycle in range(0, 100, 5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
        for dutyCycle in range(100, 0, -5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
except KeyboardInterrupt:
    pass

p.stop()
GPIO.cleanup()
コード例 #2
0
#/usr/bin/env python
import NPi.GPIO as GPIO
import time

try:
    input = raw_input
except NameError:
    pass

PIN_NUM = 11

GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM, GPIO.OUT)

p = GPIO.PWM(PIN_NUM, 0.5)
p.start(50)

input("Press Enter to stop:")

p.stop()
GPIO.cleanup()