'Detecting two wires contacting with an Arduino
I've just started messing around with arduinos, and I decided to start off by making a simple fencing game. I am trying to detect when a foil contacts their opponent's vest and then award a point to the relevant team but simply put it's not doing that
bool player1IsHitting;
bool player2IsHitting;
int player1Score;
int player2Score;
int player1Pin = 0;
int player2Pin = 1;
void setup() {
// put your setup code here, to run once:
player1IsHitting = false;
player2IsHitting = false;
player1Score = 0;
player2Score = 0;
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if ((digitalRead(player1Pin) >= LOW)&(player1IsHitting == false)){
player1Score++;
player1IsHitting = true;
Serial.print ("p1Scr: ");
Serial.println (player1Score);
Serial.print ("p2Scr: ");
Serial.println (player2Score);
delay(500);
}
if ((digitalRead(player2Pin) == LOW)&(player2IsHitting == false)){
player2Score++;
player2IsHitting = true;
Serial.print ("p1Scr: ");
Serial.println (player1Score);
Serial.print ("p2Scr: ");
Serial.println (player2Score);
delay(500);
}
if (digitalRead(player1Pin)==HIGH){
player1IsHitting = false;
}
if (digitalRead(player2Pin)==HIGH){
player2IsHitting = false;
}
}
Any help with this would be greatly appreciated, Thank You!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|