40 lines
546 B
C++
40 lines
546 B
C++
// Out.cpp
|
|
#include "Out.h"
|
|
|
|
Out::Out(unsigned byte pin) {
|
|
pin = pin;
|
|
state = LOW;
|
|
|
|
div = 1;
|
|
cycle = 0;
|
|
|
|
dur = 0;
|
|
width = 25;
|
|
// this needs to dynamically change with width
|
|
len = period * (width / 100);
|
|
|
|
pinMode(pin, OUTPUT);
|
|
}
|
|
|
|
void Out::turnOn() {
|
|
cycle += 1;
|
|
if (cycle == div) {
|
|
state = HIGH;
|
|
digitalWrite(pin, state);
|
|
dur = millis();
|
|
|
|
cycle = 0;
|
|
}
|
|
}
|
|
|
|
void Out::turnOff() {
|
|
if (state == HIGH && millis() - dur >= len) {
|
|
state = LOW;
|
|
digitalWrite(pin, state);
|
|
dur = 0;
|
|
}
|
|
}
|
|
|
|
int Out::getState() {
|
|
return state;
|
|
}
|