Line endings
This commit is contained in:
parent
f9d9005c3b
commit
ff48bcb52d
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
* text=auto
|
@ -6,7 +6,6 @@
|
|||||||
class slowPWM {
|
class slowPWM {
|
||||||
private:
|
private:
|
||||||
byte outputPin;
|
byte outputPin;
|
||||||
byte dutyCycle;
|
|
||||||
unsigned long period;
|
unsigned long period;
|
||||||
unsigned long lastSwitchTime;
|
unsigned long lastSwitchTime;
|
||||||
byte outputState;
|
byte outputState;
|
||||||
@ -18,18 +17,21 @@ class slowPWM {
|
|||||||
lastSwitchTime = 0;
|
lastSwitchTime = 0;
|
||||||
outputState = LOW;
|
outputState = LOW;
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
|
Serial.println("Setup PWM");
|
||||||
}
|
}
|
||||||
|
|
||||||
void compute(byte duty) {
|
void compute(byte duty) {
|
||||||
unsigned long onTime = (dutyCycle * period) / 100;
|
unsigned long onTime = (duty * period) / 100;
|
||||||
unsigned long offTime = period - onTime;
|
unsigned long offTime = period - onTime;
|
||||||
unsigned long currentTime = millis();
|
unsigned long currentTime = millis();
|
||||||
|
|
||||||
if (outputState == HIGH && (currentTime - lastSwitchTime >= onTime)) {
|
if (duty == 0) {
|
||||||
|
outputState = LOW;
|
||||||
|
} else if (outputState == HIGH && (currentTime - lastSwitchTime >= onTime)) {
|
||||||
lastSwitchTime = currentTime;
|
lastSwitchTime = currentTime;
|
||||||
outputState = LOW;
|
outputState = LOW;
|
||||||
}
|
|
||||||
if (outputState == LOW && (currentTime - lastSwitchTime >= offTime)) {
|
} else if (outputState == LOW && (currentTime - lastSwitchTime >= offTime)) {
|
||||||
lastSwitchTime = currentTime;
|
lastSwitchTime = currentTime;
|
||||||
outputState = HIGH;
|
outputState = HIGH;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user