This is Neal.
I am making Nerf Target Sensor Vests for my Nerf Tag game.
What I made happen is that when the piezo sensors senses pressure, the number of pressure is subtracted from a bigger number until it hits 0. And when it hits zero my servo closes a blind over the goggles of the person to tell them that they have been tagged. After a certain amount of time the blinds open back up so that the person can play again. Also there are LEDs that light up when the person is tagged. Also the numbers are displayed on a LCD the person wears as a watch.
Here is my code:
Code: Select all
#include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
#define LED 13// FOR LED
Adafruit_LiquidCrystal lcd(0);
Servo myservo1;
Servo myservo2;
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
const int threshold = 50;
int health = 500;
// 6 total sensor readings (from 0 to 5)
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
int pos =0;
int deaths=1;// gonna be number of deaths
void setup()
{
// pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
pinMode(LED, OUTPUT);//FOR LED
Serial.begin(9600);
Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");
// sg90
lcd.begin (20 , 4);
lcd.clear();
Serial.begin(9600);
myservo1.attach(9);
myservo1.write(0);//was 0
myservo2.attach(10);
myservo2.write(45);//was 179
}
void loop()
{
do
{
myservo1.detach();
myservo2.detach();
sensorReading = analogRead(knockSensor);
lcd.setCursor(0, 1);
Serial.println(health);
lcd.println(health);
if (sensorReading > threshold) {
Serial.println("Knock!");
health = health - sensorReading;
Serial.print(sensorReading);
lcd.print(sensorReading);
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading1= analogRead(knockSensor1);
if (sensorReading1 > threshold) {
Serial.println("Knock!");
health = health - sensorReading1;
Serial.print(sensorReading1);
lcd.print(sensorReading1);
int sensorValue = analogRead(A1);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading2= analogRead(knockSensor2);
if (sensorReading2 > threshold) {
Serial.println("Knock!");
health = health - sensorReading2;
Serial.print(sensorReading2);
lcd.print(sensorReading2);
int sensorValue = analogRead(A2);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading3= analogRead(knockSensor3);
if (sensorReading3 > threshold) {
Serial.println("Knock!");
health = health - sensorReading3;
Serial.print(sensorReading3);
lcd.print(sensorReading3);
int sensorValue = analogRead(A3);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading4= analogRead(knockSensor4);
if (sensorReading4 > threshold) {
Serial.println("Knock!");
health = health - sensorReading4;
Serial.print(sensorReading4);
lcd.print(sensorReading4);
int sensorValue = analogRead(A6);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading5= analogRead(knockSensor5);
if (sensorReading5 > threshold) {
Serial.println("Knock!");
health = health - sensorReading5;
Serial.print(sensorReading5);
lcd.print(sensorReading5);
int sensorValue = analogRead(A7);
Serial.println(sensorValue);
delay(1);
}
} while (health > 1);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);//was 2000 // FOR LED IN ARDUINO
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
/*
digitalWrite(LED, HIGH);
delay(2000); //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
*/
myservo1.attach(9);
myservo2.attach(10);
delay(15);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
delay(1000);
lcd.setCursor(0, 2);
Serial.println(deaths); //showind number of deaths on the lcd
lcd.println(deaths);
deaths= deaths + 1;// adding deaths
health = 500;
}
I would like to do a basic scoring system like the ones used for laser tag when the score shows how many times the player has been tagged for both teams that will show up on the LCDs of their vest.
Do you know how I could do this?
It surely isn't too hard because laser tag has it.