LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-03-2019, 12:25 AM   #1
MarkB2
LQ Newbie
 
Registered: Aug 2019
Distribution: Linux Mint
Posts: 5

Rep: Reputation: Disabled
Lightbulb [Raspberry Pi] Change LED blinking mode using PWM with python


So, i got this snes-like case for my raspi and it has functional buttons that turns off the raspi safely by using a python script. What i want to do is change the way the LED blinks as it is turning off from a on-off loop to a gradual blink using PWM. I already tested a simple script to see if it was possible and it worked:

Code:
import RPi.GPIO as IO
import time

IO.setwarnings(False)
IO.setmode (IO.BCM)
IO.setup(14,IO.OUT)

p = IO.PWM(14,100)
p.start(0)

while 1:

    for x in range (100):
        p.ChangeDutyCycle(x)
        time.sleep(0.005)
      
    for x in range (100):
        p.ChangeDutyCycle(100-x)
        time.sleep(0.005)
gpio.clean()
exit()
Pin 14 is the LED pin.

I tried inserting this code it into the script that handles the buttons and shutting down the system but nothing changes, it still blinks the same as before.

This is the script in question, and the blinking is handled at line 34.

The system i'm using is Recalbox.

Thanks in advance.
 
Old 09-03-2019, 01:17 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Show us the resulting new script with your special code inserted.
 
Old 09-03-2019, 02:10 AM   #3
MarkB2
LQ Newbie
 
Registered: Aug 2019
Distribution: Linux Mint
Posts: 5

Original Poster
Rep: Reputation: Disabled
I deleted it and reinstalled the original script. I basically removed the code that made the LED blink and inserted the new one, also initialized pin 14 as PWM like in the test script.
 
  


Reply

Tags
python, raspberrry pi, script



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Raspberry pi red LED on solidly with flashing green led. darkstarbyte Linux - Hardware 19 01-05-2013 06:54 PM
when hibernate to ram, power led keeps blinking cyrilng Linux - Hardware 10 06-02-2009 06:49 AM
nx6110 laptop, drivers installed with ndiswrapper but blinking led dragupl Linux - Wireless Networking 0 10-09-2006 02:07 PM
Hard disk led won't stop blinking AlleyTrotter Slackware 6 10-22-2005 10:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration