Millis and Button trigger problem

You know what? Millis timers are hard for us beginners. I've done the tutorials and read the posts but I still have trouble getting a Millis timer to trigger an event.
I want to light up an LED on pin 13 ( and also pulse a motor relay) for the duration specified in an array. The array is indexed by the button on pin 7. This works fine for one cycle. But at the end of that millis timer - let's say array item 4 which is 500 milliseconds, I want to turn off the LED, wait for trigger input from pin 6. When that pin goes LOW, wait 1000 (for the motor to spin down) and light the LED on 13. And repeat. The pin 6 trigger is an external programmable camera timer which fires the camera and triggers pin 6 every x seconds.
My code is probably a sloppy mess but if anybody is willing to wade through it, I would greatly appreciate it. Thanks.

#include <LiquidCrystal.h>

//Sketch to create an adjustable blink pattern on an LED and relay.
//ON and OFF values selected from an array via a button on 7 and from an external timer on 6.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long previousMillis;     // will store last time LED was updated
unsigned long peg;
const int ledPin = 13; // also relay connected here
const int buttonPin = 7;
const int triggerPin = 6;
int increment[] = {
  100, 200, 300, 400, 500, 600, 700, 800, 1000}; // LED on times
int lastButton; // saves the button state
int buttonState;
int triggerState;
int lastTrigger;
int buttonPresses = 4;

void setup() {
  pinMode(ledPin,OUTPUT);  
  pinMode(buttonPin,INPUT_PULLUP);
  pinMode(triggerPin,INPUT_PULLUP);
  lcd.begin(16,2);
  lcd.print("Motor: "); 
  buttonState = digitalRead(buttonPin);
  triggerState = digitalRead(triggerPin);
  peg = millis();
  digitalWrite(ledPin,HIGH); // start off with the LED on
 }

void loop() {

  if (buttonPresses >= 9) // reset buttonpresses counter at 9 to 0
  {
    buttonPresses = 0; 
  }
  lcd.setCursor(11,0);
  lcd.print(increment[buttonPresses]);
  lcd.print(" ");
  int lastButton = digitalRead(buttonPin);
  if (lastButton != buttonState) {     // the button state has changed
    if (lastButton == LOW) {           // check if the button is pressed
      buttonPresses++;          // increment the buttonPresses variable
    }
  }
  buttonState = lastButton; 

  //start millis timer and correct processing timing error
  unsigned long currentMillis = millis() - ((millis() - peg) % 100); 
  if((currentMillis - previousMillis) >= increment[buttonPresses]) 
  {
    // save the last LED-off time
    previousMillis = currentMillis;

    digitalWrite(ledPin, LOW);
  } 
  int triggerState = digitalRead(triggerPin);
  unsigned long triggerStart = millis();
  if (lastTrigger != triggerState) {
    if (triggerState == LOW)  {
      if (millis() - triggerStart > 1000) 
      {
        digitalWrite(ledPin, HIGH);
      }
    }
  }
  triggerState = lastTrigger;  
 }

Millis timers are hard for us beginners.

I can't imagine why. It's how YOU would perform the action that you are asking the Arduino to do.

but I still have trouble getting a Millis timer to trigger an event.

Because you are thinking of it as a timer. It isn't, any more that the watch on your wrist is. The millis() function returns the time it was called (relative to when the Arduino started). If you are going to do things based on that return value, you need to think of the value as an event time, NOT as a timer.

void loop() {

  if (buttonPresses >= 9) // reset buttonpresses counter at 9 to 0
  {
    buttonPresses = 0; 
  }

Huh? The first thing that should happen in loop is for you to check the switch(es) that manipulate buttonPresses. Then, deal with what buttonPresses has become.

  int lastButton = digitalRead(buttonPin);

Meaningful names would REALLY help. The value being stored in this variable is the state of the pin. It has nothing to do with which switch was last pressed, as this name seems to imply.

  if (lastButton != buttonState) {     // the button state has changed

Wouldn't currState and prevState make more sense? Wouldn't it be more obvious what is being compared?

  unsigned long currentMillis = millis() - ((millis() - peg) % 100);

What is being stored in this variable bears no relationship to the name of the variable. Try again.

  int triggerState = digitalRead(triggerPin);
  unsigned long triggerStart = millis();

Much better names.

  if (lastTrigger != triggerState) {

Sigh. What's being compared does not seem to have a relationship.

      if (millis() - triggerStart > 1000)

Magic numbers should be avoided. The number means something to you. Store the number in a variable with that name.

This is how you run an event every 1000ms:

unsigned long prev_millis ;

void setup ()
{
  ..
  prev_millis = millis () ;
  ..
}

#define DELAY 1000

void loop ()
{
  ..
  if (millis () - prev_millis >= DELAY)  // must use inequality, millis() sometimes jumps 2
  {
    do_something () ;
    prev_millis += DELAY ;   // update for next time, don't call millis() which might have changed
  }
  ..
}

For handling a button and debouncing it, here's one suggestion:

#define BUTTON 9  // the pin

#define IDLE 0  // pin states
#define DEBOUNCE 1
#define ON 2

#define DEBOUNCE_DELAY 30  // delay before recognise button

byte  button_state = IDLE ;
unsigned long button_pressed ;  // used for delay timing

void setup ()
{
  ..
  pinMode (BUTTON, INPUT_PULLUP) ;  // button from pin to ground, activate pullup
  ..
}

void loop ()
{
  ..
  if (! digitalRead (BUTTON))  // button active LOW (pull-up)
  {
     if (button_state == IDLE)
     {
       button_pressed = millis () ;
       button_state = DEBOUNCE ;
     }
     else if (button_state == DEBOUNCE && millis () - button_pressed >= DEBOUNCE_DELAY)
     {
       button_state = ON ;  // ON state prevents further action till button released
       do_something () ;  // this is when we know button definitely pressed, called only once
     }
  }
  else
  {
    button_state = IDLE ;
  }
  ..
}

Thank you MarkT and PaulS so much for your direction and encouragement. I was getting close to walking away. You can wander off in the wrong direction so easily with this stuff. You've given me a lot to work with. And more reading required! I'll report back in a couple of days. Thanks again.

Dave, have you read these excellent pieces on state machines?

http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

Thanks JimboZA. Reading them now! Very helpful!

State machines are flavour of the year.... another member did a really good youtube on them too, trying to find.

Ah, found it. Go and have a look at this

That's great JimboZA! Everybody who has had a problem understanding BLINK WITHOUT DELAY should watch this and then watch it again 3 times! I'm going to take everything you all have suggested and rebuild my sketch. Report back on the weekend. Cheers

Been busting my brain for days. Couldn't get millis to work the way I wanted. Finally got this sketch to work when I realized this is not a millis application or at least doesn't need to be. The events I wanted to trigger can more easily be timed with a short delay.
Thanks to Paul for naming advice and Mark for debounce code. I used the Bounce library for the trigger switch so I could go off the falling edge. I couldn't figure out how to use that library with two switches so I kept Mark's debounce routine for buttonPin1. Also picked up the void function technique thanks to Jimbo's referral. Here is what is working now.

#include <Bounce2.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int buttonPin1 = 7;
const int IDLE = 0;
const int DEBOUNCE = 1;
const int ON = 2;
int DEBOUNCE_DELAY = 30;
byte button_state = IDLE;
unsigned long button_pressed;
const int triggerPin = 6;

int increment[] = {
  100, 200, 300, 400, 500, 600, 700, 800, 1000}; // LED on times
int buttonPresses = 4;
const int ledPin = 13; // motor relay attached
Bounce debouncer = Bounce();

void setup()
{
  pinMode(ledPin,OUTPUT); 
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(triggerPin,INPUT);
  digitalWrite(triggerPin,HIGH);
  debouncer.attach(triggerPin);
  debouncer.interval(20);
  lcd.begin(16,2);
  lcd.print("Motor: ");
  digitalWrite(ledPin,LOW);
}  

void loop()
{
  motorValue();
  // trigger.Update();
  // if (trigger.clicks >= 1)
  boolean stateChanged = debouncer.update();
  int state = debouncer.read();

  // Detect the falling edge
  if ( stateChanged && state == HIGH )
  {
    delay(1000);
    digitalWrite(ledPin,HIGH);
    delay(increment[buttonPresses]);
    digitalWrite(ledPin,LOW);
  }
}

void motorValue()
{
  if (! digitalRead (buttonPin1))  // button active LOW (pull-up)
  {
    if (button_state == IDLE)
    {
      button_pressed = millis () ;
      button_state = DEBOUNCE ;
    }
    else if (button_state == DEBOUNCE && millis () - button_pressed >= DEBOUNCE_DELAY)
    {
      button_state = ON ;  // ON state prevents further action till button released
      buttonPresses++;  // this is when we know button definitely pressed, called only once
    }
  }
  else
  {
    button_state = IDLE ;
  }

  if (buttonPresses >= 9) 
  {
    buttonPresses = 0;
  }
  lcd.setCursor(11,0);
  lcd.print(increment[buttonPresses]);
  lcd.print(" ");
}