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 resistorboolean start = false; //check if games is started
int randomLed; //choose random led to light
int timer=0;
int knockTimes = 0; //check amount of knocksvoid 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!