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
|
@ -1,39 +1,41 @@
|
||||
#ifndef SLOWPWM_h
|
||||
#define SLOWPWM_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class slowPWM {
|
||||
private:
|
||||
byte outputPin;
|
||||
byte dutyCycle;
|
||||
unsigned long period;
|
||||
unsigned long lastSwitchTime;
|
||||
byte outputState;
|
||||
|
||||
public:
|
||||
void begin(byte pin, unsigned long per) {
|
||||
outputPin = pin;
|
||||
period = per;
|
||||
lastSwitchTime = 0;
|
||||
outputState = LOW;
|
||||
pinMode(pin, OUTPUT);
|
||||
}
|
||||
|
||||
void compute(byte duty) {
|
||||
unsigned long onTime = (dutyCycle * period) / 100;
|
||||
unsigned long offTime = period - onTime;
|
||||
unsigned long currentTime = millis();
|
||||
|
||||
if (outputState == HIGH && (currentTime - lastSwitchTime >= onTime)) {
|
||||
lastSwitchTime = currentTime;
|
||||
outputState = LOW;
|
||||
}
|
||||
if (outputState == LOW && (currentTime - lastSwitchTime >= offTime)) {
|
||||
lastSwitchTime = currentTime;
|
||||
outputState = HIGH;
|
||||
}
|
||||
digitalWrite(outputPin, outputState);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#ifndef SLOWPWM_h
|
||||
#define SLOWPWM_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class slowPWM {
|
||||
private:
|
||||
byte outputPin;
|
||||
unsigned long period;
|
||||
unsigned long lastSwitchTime;
|
||||
byte outputState;
|
||||
|
||||
public:
|
||||
void begin(byte pin, unsigned long per) {
|
||||
outputPin = pin;
|
||||
period = per;
|
||||
lastSwitchTime = 0;
|
||||
outputState = LOW;
|
||||
pinMode(pin, OUTPUT);
|
||||
Serial.println("Setup PWM");
|
||||
}
|
||||
|
||||
void compute(byte duty) {
|
||||
unsigned long onTime = (duty * period) / 100;
|
||||
unsigned long offTime = period - onTime;
|
||||
unsigned long currentTime = millis();
|
||||
|
||||
if (duty == 0) {
|
||||
outputState = LOW;
|
||||
} else if (outputState == HIGH && (currentTime - lastSwitchTime >= onTime)) {
|
||||
lastSwitchTime = currentTime;
|
||||
outputState = LOW;
|
||||
|
||||
} else if (outputState == LOW && (currentTime - lastSwitchTime >= offTime)) {
|
||||
lastSwitchTime = currentTime;
|
||||
outputState = HIGH;
|
||||
}
|
||||
digitalWrite(outputPin, outputState);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user