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);
if ((millis() - previousMillis) > speed / 256) {
brightness++; // Incrementiamo la luminosita'
previousMillis = millis();
- Serial.println(brightness);
};
}
if ((millis() - previousMillis) > speed / 256) {
brightness--; // Incrementiamo la luminosita'
previousMillis = millis();
- Serial.println(brightness);
};
}
if ((millis() - previousMillis) > speed / 512) {
brightness = brightness + increment; // Incrementiamo la luminosita'
previousMillis = millis();
- Serial.println(brightness);
analogWrite(ledPin, brightness);
if (brightness == 0 || brightness == 255) { // Reverse direction
increment = -increment ;