Skip to content

Instantly share code, notes, and snippets.

@ritiek

ritiek/test_led.py

Last active Feb 3, 2020
Embed
What would you like to do?
Tests an LED connected via GPIO to Raspberry Pi with software defined PWM
#!/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
You can’t perform that action at this time.