const int SWITCH_PIN = 7; // the number of the switch pin
const int LED_PIN = 3; // the number of the LED pin
const int DELAY_PIN = A1;
const int fMin = 150; // set the flasher min
const int fMax = 1000; // set the flaser max
bool lampState = LOW;
int delayTime = 100; // set initial value of flasher speed
int switchState = 0; // variable for reading the switch status
void setup() {
// initialize the LED pin as an output:
pinMode(LED_PIN, OUTPUT);
// initialize the switch pin as an pull-up input:
// the pull-up input pin will be HIGH when the switch is open and LOW when the switch is closed.
pinMode(SWITCH_PIN, INPUT_PULLUP);
pinMode(DELAY_PIN, INPUT);
}
void loop() {
// read the state of the pushbutton and variable resistor value:
delayTime = map(analogRead(DELAY_PIN), 0, 1023, fMin, fMax);
switchState = digitalRead(SWITCH_PIN);
// control LED according to the state of switch
if(switchState == LOW) {
digitalWrite(LED_PIN, lampState); // flash LED
lampState = !lampState;
delay(delayTime);
} // If switch is closed
else // otherwise
digitalWrite(LED_PIN, LOW); // turn off LED
}