Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

raspberry pi pwm controlled leds

import RPi.GPIO as GPIO             
from time import sleep              

redLED = 18				
blueLED = 12            
greenLED = 19         

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

GPIO.setup(redLED,GPIO.OUT)    
GPIO.setup(blueLED,GPIO.OUT)   
GPIO.setup(greenLED,GPIO.OUT)  

red_pwm = GPIO.PWM(redLED,1000)
blue_pwm = GPIO.PWM(blueLED,1000) 
green_pwm = GPIO.PWM(greenLED,1000) 

red_pwm.start(0)			
blue_pwm.start(0)                       
green_pwm.start(0)                      

print("AH Shit! Here we go again! Press CTRL+C to exit")

try:
    while True:                                         
        for duty in range(0,101,1):                     
            red_pwm.ChangeDutyCycle(duty)               
            sleep(0.01)                                 
        sleep(0.5)                                      

        for duty in range(100,-1,-1):                   
            red_pwm.ChangeDutyCycle(duty)               
            sleep(0.01)                                 
        sleep(0.5)                                      
		
        for duty in range (0, 101, 1):                  
            blue_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

        for duty in range (100, -1, -1):                
            blue_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

        for duty in range(0,101,1):                     
            green_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

        for duty in range(100,-1,-1):                   
            green_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

except KeyboardInterrupt: 		
    red_pwm.stop() 			
    blue_pwm.stop() 
    green_pwm.stop()
    GPIO.cleanup()
Comment

PREVIOUS NEXT
Code Example
Python :: how to convert ordereddict to dict in python 
Python :: repeating a program in python 
Python :: html to image pygame python 
Python :: pie plot chance size python 
Python :: how to use query in ms access with python 
Python :: With Python, it is possible to use the ** operator to calculate powers 
Python :: test python package without rebuilding 
Python :: nvidia-smi with user name 
Python :: Fill area under line plot 
Python :: token validation in flask socket 
Python :: queue data structure in python 
Python :: python regex compile 
Python :: pytube.exceptions.RegexMatchError: __init__: could not find match for ^w+W 
Python :: python datediff days 
Python :: dft numpy amplitude 
Python :: bagging algorithm 
Python :: Python Code for Checking if a number is an Odd number 
Python :: python sort by last name using lambda 
Python :: ansible custom module 
Python :: dropping original values after merging scaled values 
Python :: send notification from pc to phone using python 
Python :: how to enumerate the names inside a list python 
Python :: run windows command and get output python 
Python :: antal riksdagsledamöter 
Python :: python import file from same level 
Python :: qlabel click python 
Python :: connect elasticsearch cloud with python terminal 
Python :: The module in NAME could not be imported: django.contrhtmlib.auth.password_validation.UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALIDATORS setting. 
Python :: extrapolate python 
Python :: python numpy find local minima 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =