I'm entering a pinewood derby model car race and I am trying to accomplish the following:
- activate a Knight Rider array of 6 LEDS with a capactitive touch switch
- run the Knight Rider array
- turn off the array after 2 minutes
- 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);
}
}