Two knock to activate

I'm trying to make my game start with 1 knock and end if you knock two times. Anyone know how to count knocks? I guess a timer is needed but im kinda lost here.

The current code im using is,

int knockPin = 3; //pin for incoming knock sensor
int ledPins[]= {5,6,7,8,9,10,11};

int knockVal; //value from knock sensor
int minimum = 400;
int limit = 1000; //how sensitive the knock sensor is, lower = higher sensitivity based on piezo and pull down resistor

boolean start = false; //check if games is started
int randomLed; //choose random led to light
int timer=0;
int knockTimes = 0; //check amount of knocks

void setup()
{
for(int i=0;i<sizeof(ledPins);i++)
{
pinMode(ledPins*,OUTPUT);*

  • }*
  • pinMode(knockPin, INPUT);*
  • Serial.begin(9600);*
    }

void loop()
{

  • //Serial.println(knockVal); //dump to serial for debugging?*

  • knockVal = analogRead(knockPin); //read the knock sensor*

  • if (knockVal < limit)*

  • {*

  • start = true;*

  • knockTimes = +1;*

  • timer ++;*

  • Serial.println(knockTimes);*

  • }*

  • if(start == true)*

  • {*

  • digitalWrite(randomLed, LOW);*

  • for(int i=0; i < 10; i++)*

  • {*

  • int randomVal1 = random(5,12);*

  • int randomVal2 = random(5,12);*

  • digitalWrite(randomVal1, HIGH);*

  • delay(70);*

  • digitalWrite(randomVal2, HIGH);*

  • delay(40);*

  • digitalWrite(randomVal1, LOW);*

  • delay(70);*

  • digitalWrite(randomVal2, LOW);*

  • delay(40);*

  • }*

  • start = false;*

  • randomLed = random(5,12);*

  • Serial.println(randomLed);*

  • digitalWrite(randomLed, HIGH); *

  • }*
    } [/size][/quote]
    Many thanks in advance!

I am sure that you can count knocks in the code. What you want to do is measure time between knocks.

If you learn how the blink without delay example works then you should see how to measure intervals.

But please, don't just glance, give up and ask. Learn.

What kind of sensor are you using? Something like the adxl345 has a built in tap sensor