I am trying to run the coding below but have it so that when the sensor is hit a second time it runs a differet blink pattern. If touched once it blinks 5 or so times if touched a second time it blinks 6 times and so on. This is as far as i got and I'm clueless on how to proceed.
Here is the code...
/*
* Touch Sensor
LED lights up and writes "touch" when a sensor is hit
The circuit:
*LED connected from digital pin 13 to ground.
*Piezo connected from analog pin 0 to ground.
*/
#define PIEZOTHRESHOLD 20 // analog threshold for impact
#define PADNUM 1 // number of pads
int ledPin = 13; // LED connected to digital 13
int sensorPin = 14; // Sensor connected to analog pin 0
int val = 20;
// The setup() method runs once, when the sketch starts
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin(115200); // sets serial output rate
}
// the loop() method runs continuously
void loop()
{
// Loop through each sensor and begin blink pattern
// on digital output if impact exceeds
// the threshold
for(int i = 0; i < 1; i++) {
val = analogRead(i);
if(val > 20 ){
digitalWrite(ledPin, HIGH); // turns on LED
Serial.print(i);
Serial.print(",");
Serial.print("touch");
Serial.println();
digitalWrite(ledPin, LOW); // turns off LED
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
break;
}
}
}