Skip to content

Instantly share code, notes, and snippets.

@luanpcweb
Created July 19, 2020 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luanpcweb/8252c3993f7ce118d6253b9735424fe8 to your computer and use it in GitHub Desktop.
Save luanpcweb/8252c3993f7ce118d6253b9735424fe8 to your computer and use it in GitHub Desktop.
#Define Libraries
import RPi.GPIO as gpio
import time
gpio.setwarnings(False)
#Configuring GPIO
gpio.setmode(gpio.BOARD)
gpio.setup(38,gpio.OUT)
gpio.setup(40,gpio.OUT)
#Configure the pwm objects and initialize its value
pwmBlue = gpio.PWM(38,100)
pwmBlue.start(0)
pwmRed = gpio.PWM(40,100)
pwmRed.start(100)
#Create the dutycycle variables
dcBlue = 0
dcRed = 100
#Loop infinite
while True:
#increment gradually the luminosity
pwmBlue.ChangeDutyCycle(dcBlue)
time.sleep(0.05)
dcBlue = dcBlue + 1
if dcBlue == 100:
dcBlue = 0
#decrement gradually the luminosity
pwmRed.ChangeDutyCycle(dcRed)
time.sleep(0.05)
dcRed = dcRed - 1
if dcRed == 0:
dcRed = 100
#End code
gpio.cleanup()
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment