Created
July 19, 2020 04:44
-
-
Save luanpcweb/8252c3993f7ce118d6253b9735424fe8 to your computer and use it in GitHub Desktop.
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
#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