I am using hw-479 that looks like the picture below. I cannot find much of information for it but the Alibaba page says
The RGB LED module is made of a plug-in full-color LED. The PWM voltage input of the three pins of R G and B can adjust the intensity of three primary colors (red/blue/green) to achieve full-color color mixing. The Arduino's control of the module enables cool lighting effects.
Of course, since I am using a Pi, I cannot use that Arduino library. I wrote the following code, but it does not work. Turning individual colours by setting
GPIO.output(pin, HIGH) was successful, so I do not think the pin connections are wrong.
I wonder what is wrong with the code. First, I do not understand what the frequency should be. The example was using 50, so I used 50. Secondly, it seems that the
dc, the parameter of
start() ranges from 0, to 100, and 0 means the maximum power and 100 means the minimum power. Is that correct?
import RPi.GPIO as GPIO import time redPin = 11 greenPin = 13 bluePin = 15 def setValue(pin, value): GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.OUT) p = GPIO.PWM(pin, 50) if 0>value or value>255: raise Exception("0 to 255") #dc = 0 max, dc = 100 min dc = 100 - (float(value)/256.*100); p.start(dc) def setRGB(r,g,b): setValue(redPin, r) setValue(greenPin, g) setValue(bluePin, b) if __name__ == "__main__": print("Salmon") setRGB(0xFA, 0x80, 0x72) raw_input() print("Dark slate gray") setRGB(0x2F, 0x4F, 0x4F) raw_input() GPIO.cleanup()