X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=libraries%2Fcommon%2Fcommon.cpp;fp=libraries%2Fcommon%2Fcommon.cpp;h=b77c04602ee55539ed315f9198e56ab124aa0b9d;hb=9046a34c851a66149248ad1695eb51c7ac1ccd36;hp=cbf8fdd569db6eed18eb9971f5835a56020891f9;hpb=22da2a0f8203616aedbb746d4b4dbb4f7718ae58;p=sketchbook_andrea diff --git a/libraries/common/common.cpp b/libraries/common/common.cpp index cbf8fdd..b77c046 100644 --- a/libraries/common/common.cpp +++ b/libraries/common/common.cpp @@ -9,12 +9,26 @@ ////////////////////// // RGB LED -// Common anode +// Common anode / cat RGBLed::RGBLed(byte pinR, byte pinG, byte pinB) { redPin = pinR ; greenPin = pinG ; bluePin = pinB ; + common = 0 ; + + // Equvalente del Setup() per inizializzare i PIN + pinMode(redPin, OUTPUT); + pinMode(greenPin, OUTPUT); + pinMode(greenPin, OUTPUT); +}; + +RGBLed::RGBLed(byte pinR, byte pinG, byte pinB, byte com) { + // Per un common catode, inverte il valore max / min + redPin = pinR ; + greenPin = pinG ; + bluePin = pinB ; + common = com ; // Equvalente del Setup() per inizializzare i PIN pinMode(redPin, OUTPUT); @@ -24,9 +38,9 @@ RGBLed::RGBLed(byte pinR, byte pinG, byte pinB) { void RGBLed::SetColor (byte r, byte g, byte b) { // Imposta il colore di un LED RGB - analogWrite(redPin, r); - analogWrite(greenPin, g); - analogWrite(bluePin, b); + analogWrite(redPin, common - r); + analogWrite(greenPin, common - g); + analogWrite(bluePin, common - b); }; void RGBLed::Red () {