Hello all I am working building a custom pop a shot game. You might have seen these before at arcades. It is essentially a basketball hoop that every time you score the counter goes up. How i am thinking of doing this is using an IR sender and a IR receiver to act as a break beam. These would be attached to the rim and anytime the ball goes through the need it would trigger the ardiuno. A couple of thoughts i had about this is if the ball goes in and the net comes up to break the beam again. So i implemented a time that a shot can only count every so many seconds. The real issue i have is how sensitive the sensors are. If a threw the basketball as hard as I could to the rim I could probably shake the rim enough the beam would break. So i was thinking I should add a timer that started counting when the beam was broken that it would only register the point if the be was broken so long (ie the time a ball would take to go through the rim. I do not know how to set this second timer up. Below is my code. Any thoughts would be greatly appreciated. Thank you.
#include <Keyboard.h>
#include <elapsedMillis.h>
#define LEDPIN 13
#define SENSORPIN 4
elapsedMillis timeElapsed;
//elapsedMillis breakTime;
int sensorState = 0;
int lastState = 0;
int interval = 1500;
//int basketballTime = 200;
void setup(){
pinMode(LEDPIN, OUTPUT);
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH);
Serial.begin(9600);
Keyboard.begin();
}
void loop(){
sensorState = digitalRead(SENSORPIN);
Serial.println(timeElapsed);
if(sensorState == LOW)
{
digitalWrite(LEDPIN, HIGH);
}
else{
digitalWrite(LEDPIN, LOW);
}
if(sensorState && !lastState){
Serial.println("Unbroken");
}
if(!sensorState && lastState && timeElapsed > interval){
Serial.println("Broken");
Keyboard.write('k');
timeElapsed = 0;
}
lastState = sensorState;
}