Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Skip to content
- Search or jump to…
- Pull requests
- Issues
- Marketplace
- Explore
- @lxzlxz Sign out
- 1
- 0 1 nextbowen/ECE4564-P3 Private
- Code Issues 0 Pull requests 0 Projects 0 Wiki Insights
- ECE4564-P3/LED_PWM.py
- aed0a04 5 days ago
- @lxzlxz lxzlxz fixed PWM_LED
- @lxzlxz @guancongyi
- 85 lines (66 sloc) 2.66 KB
- import RPi.GPIO as GPIO
- import time
- class LED_PWM_CLASS:
- def __init__(self):
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(12, GPIO.OUT) # Green
- GPIO.setup(16, GPIO.OUT) # Red
- GPIO.setup(25, GPIO.OUT) # Blue
- self.GreenPWM = GPIO.PWM(12, 100)
- self.RedPWM = GPIO.PWM(16, 100)
- self.BluePWM = GPIO.PWM(25, 100)
- self.BlueIntensity = 0
- self.GreenIntensity = 0
- self.RedIntensity = 0
- self.LED_status = 0
- self.GreenPWM.start(self.GreenIntensity)
- self.RedPWM.start(self.RedIntensity)
- self.BluePWM.start(self.BlueIntensity)
- self.color = ''
- def blink_once(self, gpio_port_number):
- GPIO.output(gpio_port_number, GPIO.HIGH)
- time.sleep(0.4)
- GPIO.output(gpio_port_number, GPIO.LOW)
- time.sleep(0.4)
- def set_LED(self, new_color, new_intensity):
- if self.LED_status == 1:
- if new_color == 'red':
- #self.RedPWM.start(self.RedIntensity)
- self.RedIntensity = new_intensity
- self.RedPWM.ChangeDutyCycle(new_intensity)
- temp = "Successfully set red's intensity to " + str(self.RedIntensity)
- print(temp)
- elif new_color == 'green':
- #self.GreenPWM.start(self.GreenIntensity)
- self.GreenIntensity = new_intensity
- self.GreenPWM.ChangeDutyCycle(new_intensity)
- temp = "Successfully set green's intensity to " + str(self.GreenIntensity)
- print(temp)
- elif new_color == 'blue':
- #self.BluePWM.start(self.BlueIntensity)
- self.BlueIntensity = new_intensity
- self.BluePWM.ChangeDutyCycle(new_intensity)
- temp = "Successfully set blue's intensity to " + str(self.BlueIntensity)
- print(temp)
- elif self.LED_status == 0:
- pass
- def turn_on_led(self):
- self.LED_status = 1
- self.RedPWM.start(self.RedIntensity)
- self.GreenPWM.start(self.GreenIntensity)
- self.BluePWM.start(self.BlueIntensity)
- print("LED on")
- def turn_off_led(self):
- #GPIO.output(12, GPIO.LOW)
- #GPIO.output(16, GPIO.LOW)
- #GPIO.output(25, GPIO.LOW)
- self.GreenPWM.stop()
- self.BluePWM.stop()
- self.RedPWM.stop()
- self.LED_status = 0
- print("LED off")
- def get_led_info(self):
- return {'blue':self.BlueIntensity, 'green': self.GreenIntensity, 'red': self.RedIntensity, 'status': self.LED_status}
- def parse_command(self, dic):
- self.set_LED(dic['color'], dic['intensity'])
- © 2018 GitHub, Inc.
- Terms
- Privacy
- Security
- Status
- Help
- Contact GitHub
- Pricing
- API
- Training
- Blog
- About
- Press h to open a hovercard with more details.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement