-1

When I run this code I’m expecting to get a led that brightens but I get a led that dims.

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11,GPIO.OUT)

dc=0

LED=GPIO.PWM(11,100)

LED.start(dc)

while 0<=dc<=100:

   dc+=1

   if 0<=dc<=100:

      LED.ChangeDutyCycle(dc)

      time.sleep(0.01)
1
  • Sorry I didn’t know how to format my code using my phone but it’s relatively simple so sorry for the inconvenience
    – Hamza
    Jul 15 '20 at 10:33
0

Presumably rather than GPIO to LED+ then LED- to ground your connection is 3V3 to LED+ then LED- to GPIO. That would account for the dimming rather than brightening.

I have ignored the resistor which will be somewhere in series in both the above cases.

You can either change the LED connections or reverse the while loop to count down rather than up.

4
  • As an FYI, it's better to use the GPIO as a current sink so it doens't have to deliver the current to drive the LED. GPIO's are better at sinking than sourcing.
    – Swedgin
    Jul 15 '20 at 11:09
  • Thank you for taking time out of your day to answer a newbie🤩 I understand what you said but this isn’t the case with me because I’m using an adeept RGB LED that has 4 pins one is + and the other 3 are colors , I connected the + to the 5 V pin and the three colors to GPIO pins. Again... I’m just a high school student that wants to learn more. So u got any ideas?
    – Hamza
    Jul 15 '20 at 11:28
  • 2
    Never connect one end of a component to 5V if the other is connected to a Pi GPIO.
    – joan
    Jul 15 '20 at 11:58
  • Regardless of the dangerous powering from 5V rather than 3V3 my answer is unchanged. The simplest solution is to count down rather than up.
    – joan
    Jul 15 '20 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.