+// Spegne il LED
+ SetColor(255,255,255);
+};
+
+
+
+/////////////////////////////////////
+// Lampeggiatore
+// Constructor
+Lampeggiatore::Lampeggiatore(int pin)
+{
+ ledPin = pin;
+ pinMode(ledPin, OUTPUT);
+ ledState = LOW;
+ previousMillis = 0;
+ interval = 500;
+};
+
+// Una funzione facente parte di una classe prende il nome di "metodo" della stessa:
+void Lampeggiatore::Invert() {
+ // Inverte il lampeggio
+ ledState = HIGH ;
+}
+
+void Lampeggiatore::Blink() {
+ // Illumina il led a 500ms
+
+ if(millis() + shift - previousMillis > interval) {
+
+ // if the LED is off turn it on and vice-versa:
+ ledState = !ledState ; // Inverti il LED
+ // set the LED with the ledState of the variable:
+ digitalWrite(ledPin, ledState);
+ // save the last time you blinked the LED
+ previousMillis += interval;
+ }
+};
+
+void Lampeggiatore::Blink(long time, long drift ) {
+ // Illumina il led secondo un intervallo passato come argomento
+
+ shift = drift;
+ if(millis() + shift - previousMillis > time) {
+ // if the LED is off turn it on and vice-versa:
+ ledState = !ledState ; // Inverti il LED
+ // set the LED with the ledState of the variable:
+ digitalWrite(ledPin, ledState);
+ // save the last time you blinked the LED
+ previousMillis += time;
+ }
+};
+
+void Lampeggiatore::Blink(long up, long down, long drift ) {
+ // Illumina il ledB precisando ontime e downtime
+
+ shift = drift;
+ if((ledState == HIGH)&& (millis() + shift - previousMillis > up)) {
+ // save the last time you blinked the LED
+ previousMillis += up;
+ ledState = LOW ;
+ }
+ else if((ledState == LOW)&& (millis() + shift - previousMillis > down)) {
+ previousMillis += down;
+ ledState = HIGH ;
+ }
+
+ // set the LED with the ledState of the variable:
+ digitalWrite(ledPin, ledState);
+};
+
+void Lampeggiatore::High() {
+ // Accende il LED
+
+ digitalWrite(ledPin, HIGH);
+}
+
+void Lampeggiatore::Low() {
+ // Spegne il LED
+
+ digitalWrite(ledPin, LOW);
+}
+
+void Lampeggiatore::Swap() {
+ // Inverte lo stato del LED
+
+ digitalWrite(ledPin, !digitalRead(ledPin));
+}
+
+/////////////////////////////////////
+// Pwm
+// Constructor
+Pwm::Pwm(int pin)
+// Gestione del PWM utilizzando millis
+// per non bloccare il processore con delay
+// Warning: serialWrite puo' interferire con i tempi.
+{
+ ledPin = pin;
+ pinMode(ledPin, OUTPUT);
+ previousMillis = 0;
+ byte brightness = 0 ;
+ increment = 1;
+};
+
+void Pwm::Up(long speed, long drift) {
+ // Aumenta linearmente la luminosita' usanndo millis()
+ // quindi senza bloccare il processore
+ // Viene usato un float, in alternativa un coseno
+
+ if (millis() != previousMillis) { // si potrebbe togliere
+ shift = drift;
+ brightness = 255.0 /(float)speed * (millis() + shift);
+ analogWrite(ledPin, brightness);
+
+ previousMillis = millis();
+ };
+}
+
+void Pwm::lUp(long speed, long drift) {
+ // Aumenta usanndo millis() con correzione luminosita' LED
+ // quindi senza bloccare il processore
+ // Viene usato un float, in alternativa un coseno
+
+ if (millis() != previousMillis) { // si potrebbe togliere
+ shift = drift;
+ brightness = 255.0 /(float)speed * (millis() + shift);
+ analogWrite(ledPin, lum(brightness));
+
+ previousMillis = millis();
+ };
+}
+
+void Pwm::Down(long speed, long drift) {
+ // Riduce linearmente la luminosita' usanndo millis()
+ // quindi senza bloccare il processore
+
+ if (millis() != previousMillis) {
+ shift = drift;
+ brightness = 255 - 255.0 /(float)speed * (millis() + shift) ;
+ analogWrite(ledPin, brightness);
+
+ previousMillis = millis();