Last active
February 3, 2020 09:56
-
-
Save ritiek/f14d9419d5182c6936bc70b5b2c28048 to your computer and use it in GitHub Desktop.
Tests an LED connected via GPIO to Raspberry Pi with software defined PWM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import RPi.GPIO as GPIO | |
import time | |
import sys | |
out_pin = int(sys.argv[1]) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setwarnings(False) | |
GPIO.setup(out_pin, GPIO.OUT) | |
time_off = 0.001 | |
def output(out_pin, duty_cycle, time_off): | |
time_on = (time_off*int(duty_cycle))/(100-int(duty_cycle)) | |
time.sleep(time_off) | |
GPIO.output(out_pin, GPIO.HIGH) | |
time.sleep(time_on) | |
GPIO.output(out_pin, GPIO.LOW) | |
time.sleep(0.001) | |
while True: | |
for duty_cycle in range(100): | |
output(out_pin, duty_cycle, time_off) | |
for duty_cycle in range(99, -1, -1): | |
output(out_pin, duty_cycle, time_off) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment