Is this possible?

I'm entering a pinewood derby model car race and I am trying to accomplish the following:

  1. activate a Knight Rider array of 6 LEDS with a capactitive touch switch
  2. run the Knight Rider array
  3. turn off the array after 2 minutes
  4. reset the circuit so that it is ready for reactivation by the capacitive touch switch.

The pinewood derby rules don't allow the use of a mechanical switch and the lights would start (via capacitive switch) when the car was picked up and placed on the track. So far I've managed to combine 2 sketches for the cap switch and the Knight Rider array (thanks to info gleaned in this forum & at Sparkfun) but I'm at an impass as to how to accomplish my goals. Any info steering me in the right direction would be very much appreciated.

/*
 This sketch shows how to use the SparkFun AT42QT1010 Breakout
 Board. If you touch the Capacitive Touch area on the breakout
 board, the LED attached to the Arduino will light up (in addition
 to the LED on the AT42QT1010 breakout board).

  Hardware connections:

 Uno Pin    AT42QT1010 Board  Function

 +5V        VDD               Power supply
 GND        GND               Ground
 2          OUT               Capacitive touch state output
 */

// Constants
const int TOUCH_BUTTON_PIN = 8;  // Input pin for touch state
const int LED_PIN = 12;          // Pin number for LED

// Global Variables
int buttonState = 0;             // Variable for reading button
int pinArray[] = {2, 3, 4, 5, 6, 7}; //from KR
int count = 0;                      //from KR
int timer = 15;                     //from KR

void setup() {

  // Configure button pin as input 
  pinMode(TOUCH_BUTTON_PIN, INPUT);

  // Configure LED pin as output
  pinMode(LED_PIN, OUTPUT);
  
  //from KR
  for (count=0;count<6;count++) 
    pinMode(pinArray[count], OUTPUT);

}

void loop(){ 

  // Read the state of the capacitive touch board
  buttonState = digitalRead(TOUCH_BUTTON_PIN);

  // If a touch is detected, turn on the LED
  if (buttonState == HIGH) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }
  for (count=0;count<5;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count + 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
  for (count=5;count>0;count--) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count - 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
}

See "blink without delay".

Mark

Thanks Mark, but I'm not sure that the Blink W/O Delay addresses my need to prolong the tasks in my loop. Perhaps I could use millis as a count down timer?

[quote author=agligan link=topic=212989.msg1560596#msg1560596 date=1390581093][/quote]
[code  // If a touch is detected, turn on the LED
  if (buttonState == HIGH) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }

Not wrong, but all of that could be replaced by one line of codedigitalWrite(LED_PIN, buttonState);
As holmes4 suggested, get rid of all your delays and use the 'blink without delay' as an example of how to do it.