# RGB LED Driver
This software can be used to drive an analog RGB LED strip using a raspberry pi
and Adafruit's [16-channel 12-bit PWM/Servo Driver - PCA9685](https://raw2.github.com/apexskier/rgbLED/master/LED_Strip_bb.png):
## The Circuit
Here's the basic idea:
- Hook up the pi to the PCA9685 breakout board using the I2C connections.
- Connect the pi's 3.3V output to VCC on the PCA9685 breakout board. Leave V+
- Follow this tutorial for the RGB LED strips:
- I used N-channel MOSFETs - three of them, one for each channel
- Connect the +12V from the LED strip to an external power supply (do NOT
use your pi for this!)
- Connect the ground side of the power supply to the pi ground
- Instead of using the PWM outputs from the arduino, we'll use the PWM
outputs from the PCA9685.
- Connect up the PWM output 0 to the MOSFET with the red wire from the
LED strip. Output 1 goes to green, output 2 goes to blue.
- [WiringPi2 Python](https://github.com/WiringPi/WiringPi2-Python)
This program is designed to be included as a python module, but also has some
command line options. It, or any python code importing it, must be run as root
(sudo), because of the I2C interface.
### CLI Options
- `-c [hex color]` - Sets the led strip to the color specified.
- `-t` - Runs a test of a couple things. Use as a demo.
- `-o` - Turn the led strip off after other actions.
### As a module
from rgbDriver import RGBDriver
rgb_driver = RGBDriver()
Methods in the module use tuples to describe rgb colors: `(red_value,
green_value, blue_value)`. Each color value can range between 0 and 4095, due
to the PWM driver's 12 bit resolution. The `convert_eight_to_twelve_bit()`
method can convert a standard 0 to 255 color value to this scale.
To describe a color you can use the string representation of a hex color code
and the method `hex_to_rgb()` to convert it or `set_hex_color()` and
`to_hex_color()` to use it directly.
The driver keeps a property `current_color` that stores the led strip's current
color (in theory). This is used internally to smoothly transition from one
color to another.
Two types of color setting methods exist. `to_...` will transition a color
change over a set time. The last argument of any `to_...` method is that
transition time in milliseconds (default 300ms). `set_...` will set a color
Currently supported methods are:
- `to_rgb(rgb, fade=DEFAULT)`, `set_rgb(rgb)`
- `to_rand(r_range=(0, 4095), g_range=(0, 4095), b_range=(0, 4095), fade=DEFAULT)`, `set_rand(r_range=(0, 4095), g_range=(0, 4095), b_range=(0, 4095))`
- `to_hex_color(color, fade=DEFAULT)`, `set_hex_color(color)`
- I've got a basic single color led strip and an extra N-channel MOSFET that I
want to control.
- Set current_color var after setting up pwm.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.