Академический Документы
Профессиональный Документы
Культура Документы
I was in need of MOSFETs in order to drive the 3 RGB channels, and again found some cheap ones on
eBay I received a few days ago.
Today was a good opportunity for doing some basic tests. My first step was to control the color of the
RGB LED Strip with the help of the MOSFETs and an Arduino.
Before your read the rest of this blog post, you should read Adafruit tutorial on RGB LED Strips and Bildr
tutorial on MOSFETs.
I mostly did what Adafruit tutorial explains, except I added 10kΩ resistors, between each control/gate
pins and ground (so 3 resistors for a RGB strip), in order to force the signal to LOW until the Arduino kicks
in!
Breadboard
Controlling the LEDs via RGB colors, like the Adafruit example, is nice, but when you want smoother
color transitions HSV or HSL (hue, saturation and lightness) is a better way to do it. Usually you keep the
same saturation and lightness and only change hue.
// Note that there's some legacy code left in here which seems to do nothing
#define DELAY 20
//long deltas[3] = { 5, 6, 7 };
long rgb[3];
long rgbval;
// for reasons unknown, if value !=0, the LED doesn't light. Hmm ...
/*
R 250/600 = 107/256
G 250/950 = 67/256
B 250/250 = 256/256
*/
long k, temp_value;
void setup () {
randomSeed(analogRead(4));
for (k=0; k<3; k++) {
pinMode(RED + k, OUTPUT);
rgb[k]=0;
void loop() {
hue += HUE_DELTA;
hue=0.0;
rgb[0] = (rgbval & 0x00FF0000) >> 16; // there must be better ways
delay(DELAY);
float m, n, f;
// not very elegant way of dealing with out of range: return black
return 0L;
i = floor(h);
f = h - i;
if ( !(i&1) ) {
f = 1 - f; // if i is even
m = v * (1 - s);
n = v * (1 - s * f);
switch {
case 6:
case 0:
case 1:
case 2:
case 3:
return long(m * 255 ) * 65536 + long( n * 255 ) * 256 + long( v * 255);
case 4:
case 5:
Co
float getTemp(){
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {v