#include <PinChangeInterrupt.h>
#define LED_PIN 12
#define FASTER_BUTTON 3
#define SLOWER_BUTTON 2
int ledDelay = 200;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
pinMode(FASTER_BUTTON, INPUT_PULLUP);
pinMode(SLOWER_BUTTON, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(FASTER_BUTTON), faster, CHANGE);
attachInterrupt(digitalPinToInterrupt(SLOWER_BUTTON), slower, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_PIN, HIGH);
delay(200);
digitalWrite(LED_PIN, LOW);
delay(ledDelay);
/*
I have made the LED to be ON for 200ms (constant)
Only the OFF state will vary.
The LED will blink faster or slower.
*/
}
void faster() {
if(digitalRead(FASTER_BUTTON) == HIGH) {
Serial.println("Frequency Increased");
if(ledDelay > 200) {
ledDelay -= 200;
}
else {
Serial.println("Caannot lower the delay than this");
}
}
}
void slower() {
if(digitalRead(SLOWER_BUTTON) == HIGH) {
Serial.println("Frequency Decreased");
ledDelay += 200;
}
}