#include <blinker.h>
#include <mechButton.h>
//***********************************************
// Custom pwmBlinker class.
//***********************************************
class waveBlinker : public squareWave {
public:
waveBlinker(int inPin);
virtual ~waveBlinker(void);
void setWavePeriod(float inPeriod); // Sets wave for on time.
void setWavePulse(float inPulse); // Sets wave for on time.
virtual void pulseOn(void);
virtual void pulseOff(void);
protected:
blinker* ourBlinker;
};
waveBlinker::waveBlinker(int inPin) {
ourBlinker = new blinker(inPin);
}
waveBlinker::~waveBlinker(void) { }
void waveBlinker::setWavePeriod(float inPeriod) { ourBlinker->setPeriod(inPeriod); }
void waveBlinker::setWavePulse(float inPulse) { ourBlinker->setPulse(inPulse); }
void waveBlinker::pulseOn(void) { ourBlinker->setOnOff(true); }
void waveBlinker::pulseOff(void) { ourBlinker->setOnOff(false); }
//***********************************************
// The program
//***********************************************
mechButton toggle(4);
bool running;
waveBlinker ourSignalGen(3);
blinker heartBeat(2);
void setup() {
ourSignalGen.setPeriod(500); // Overall period. ms
ourSignalGen.setPulse(200); // Overall on time. ms
ourSignalGen.setWavePeriod(0.1); // 1/10 ms -> 10Khz
ourSignalGen.setWavePulse(0.05); // 1/20 ms -> 50% duty.
ourSignalGen.setOnOff(true); // FIre up the signal.
heartBeat.setOnOff(true); // FIre up the heartbeat.
toggle.setCallback(btnClk);
running = true;
}
void btnClk(void) {
if (!toggle.getState()) {
if (running) {
ourSignalGen.setOnOff(false);
heartBeat.setOnOff(false);
running = false;
} else {
ourSignalGen.setOnOff(true);
heartBeat.setOnOff(true);
running = true;
}
}
}
// Do the magic.
void loop() { idle(); }