From: Andrea Manni Date: Tue, 28 Nov 2017 18:46:33 +0000 (+0100) Subject: Common, cambiato il behaiour di RGB LED: X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;ds=sidebyside;h=c5a3dc4a9cc7eea224814fee4b00575e726105fa;p=sketchbook_andrea Common, cambiato il behaiour di RGB LED: il default e' 0 = common catodo Per farlo common anodo passare 1 come parametro --- diff --git a/libraries/common/common.cpp b/libraries/common/common.cpp index e99f202..4a886b2 100644 --- a/libraries/common/common.cpp +++ b/libraries/common/common.cpp @@ -21,7 +21,7 @@ RGBLed::RGBLed(byte pinR, byte pinG, byte pinB) { redPin = pinR ; greenPin = pinG ; bluePin = pinB ; - common = 255 ; + common = 0 ; // Equvalente del Setup() per inizializzare i PIN pinMode(redPin, OUTPUT); @@ -44,17 +44,24 @@ RGBLed::RGBLed(byte pinR, byte pinG, byte pinB, byte com) { void RGBLed::SetColor (byte r, byte g, byte b) { // Imposta il colore di un LED RGB - analogWrite(redPin, common - r); - analogWrite(greenPin, common - g); - analogWrite(bluePin, common - b); + if (common == 0) { + analogWrite(redPin, r); + analogWrite(greenPin, g); + analogWrite(bluePin, b); + } else { + analogWrite(redPin, 255 - r); + analogWrite(greenPin, 255 - g); + analogWrite(bluePin, 255 - b); + } + // Debug #ifdef DEBUG - Serial.print(common - r); + Serial.print(r); Serial.print("-"); - Serial.print(common - g); + Serial.print(g); Serial.print("-"); - Serial.print(common - b); + Serial.print(b); while(1); #endif diff --git a/libraries/common/common.h b/libraries/common/common.h index 9768961..440abf4 100644 --- a/libraries/common/common.h +++ b/libraries/common/common.h @@ -48,7 +48,7 @@ class RGBLed { byte redValue ; byte greenValue ; byte blueValue ; - byte common ; + boolean common ; public: RGBLed (byte pinR, byte pinG, byte pinB) ; diff --git a/libraries/common/examples/rgb/rgb.ino b/libraries/common/examples/rgb/rgb.ino index 7e1026d..b1b243e 100644 --- a/libraries/common/examples/rgb/rgb.ino +++ b/libraries/common/examples/rgb/rgb.ino @@ -13,8 +13,8 @@ void setup() { // Instanziamo un LED RGBLed led(11, 10,9); //Istanziamo un oggetto led (default common catodo) // facente parte della classe RGBLed -// RGBLed led(11, 10,9,255); // Stessa cosa: 255 = common catodo = (255 - value) -//RGBLed led(10,9,11,0); // Inizializzazione Common anodo +// RGBLed led(11, 10,9,0); // Stessa cosa: 255 = common catodo = (255 - value) +//RGBLed led(10,9,11,1); // Inizializzazione Common anodo void loop() { led.Red();