Here is a start. I did the button processing and created a skeleton for the state machine and timing.
const int LED = 2;
const int Button = 4;
const int timeOn = A3;
const int timeOff = A4;
enum StateEnum
{
STATE_IDLE,
STATE_LEDON,
STATE_LEDOFF
};
StateEnum state = STATE_IDLE;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(Button, INPUT_PULLUP);
}
void loop()
{
static int lastButtonState = digitalRead(Button);
static unsigned long prevMillis;
int buttonState = digitalRead(Button);
unsigned long onVal = analogRead(timeOn);
onVal = map(onVal, 0, 1023, 50, 500);
unsigned long offVal = analogRead(timeOff);
offVal = map(offVal, 0, 1023, 50, 500);
unsigned long currMillis = millis();
if (buttonState != lastButtonState)
{
delay(50);
if (buttonState == LOW)
{
if (state == STATE_IDLE)
{
// set up to start flashing
prevMillis = millis();
digitalWrite(LED, HIGH);
state = STATE_LEDON;
}
else
{
// Turn off LED go to idle state
digitalWrite(LED, LOW);
state = STATE_IDLE;
}
}
lastButtonState = buttonState;
}
switch (state)
{
case STATE_IDLE:
break;
case STATE_LEDON:
// check to see if on time has expired. If so then turn LED off and transition to STATE_LEDOFF
break;
case STATE_LEDOFF:
// check to see if off time has expired. If so then turn LED on and transition to STATE_LEDON
break;
}
}