#include <blinker.h>
#include <mapper.h>
// So everyone wants newbies to write blink without delay. This is good
// because delay() is bad. Well, here's the simple way to do it..
#define MIN_PULSE 10 // Pulse, how long for pin to be high.
#define MAX_PULSE 5000
#define MIN_PERIOD 100 // Period, how long between high starts.
#define MAX_PERIOD 10000
float currentPeriod;
float currentPulse;
// Allocate a global blinker object.
blinker aBlinker(2);
mapper periodMapper(0,1023,MIN_PERIOD,MAX_PERIOD);
mapper pulseMapper(0,1023,MIN_PULSE,MAX_PULSE);
void setup() {
Serial.begin(9600);
currentPeriod = -1;
currentPulse = -1;
aBlinker.setOnOff(true); // Fire it up.
}
void loop() {
float newPeriod;
float newPulse;
idle();
newPeriod = periodMapper.map(analogRead(A0));
newPulse = pulseMapper.map(analogRead(A1));
if (newPeriod!=currentPeriod) {
aBlinker.setPeriod(newPeriod);
currentPeriod = newPeriod;
Serial.print("Period :");
Serial.print(currentPeriod/1000);
Serial.println(" seconds");
}
if (newPulse!=currentPulse) {
aBlinker.setPulse(newPulse);
currentPulse = newPulse;
Serial.print("Pulse :");
Serial.print(currentPulse/1000);
Serial.println(" seconds");
}
}
Period
Pulse