From: eaman Date: Sat, 28 Jan 2017 01:37:30 +0000 (+0100) Subject: RGB common anodo X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=9046a34c851a66149248ad1695eb51c7ac1ccd36;p=sketchbook_andrea RGB common anodo --- 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 () { diff --git a/libraries/common/common.h b/libraries/common/common.h index f5a763c..0af9d45 100644 --- a/libraries/common/common.h +++ b/libraries/common/common.h @@ -43,9 +43,11 @@ class RGBLed { byte redValue ; byte greenValue ; byte blueValue ; + byte common ; public: RGBLed (byte pinR, byte pinG, byte pinB) ; + RGBLed (byte pinR, byte pinG, byte pinB, byte com) ; void SetColor (byte r, byte g, byte b) ; void Red (); void Green (); diff --git a/libraries/common/examples/rgb/rgb.ino b/libraries/common/examples/rgb/rgb.ino index 98c980b..ed7a564 100644 --- a/libraries/common/examples/rgb/rgb.ino +++ b/libraries/common/examples/rgb/rgb.ino @@ -11,15 +11,13 @@ void setup() { } // Instanziamo un LED -RGBLed led(11, 10, 9); //Istanziamo un oggetto led facente parte - // della classe RGBLed +RGBLed led(11, 10,9); //Istanziamo un oggetto led (common catodo) +// facente parte della classe RGBLed +//RGBLed led(10, 9, 11,255); // Inizializzazione Common anodo, valori invertiti void loop() { led.Red(); - delay(1000); - led.SetColor(255, 0, 255) ; // Mettiamo il LED in Green - delay(1000); - led.Off(); + } /* Colori disponibili: