//Importing needed packages
#include <Wire.h>
#include <LiquidCrystal.h>
#include <GY6050.h>
#include <math.h>
//creating an instance of class GY6050
GY6050 gyro(0x68); // Create Gyro object with "0x68" as I2C addres (most likely the address of your MPU6050)
//CREATING an instance of LCD class,..
LiquidCrystal lcd(12, 11, 5, 4, 6, 7);
//creating variables for arduino pins
int shinai = A4;
int tsuki = A3;
int dou = A2;
int kote = A1;
int men = A0;
//creating a threshold value to check for a hit
int threshold = 150;
//creating variable for force,..
double f = 0.0;
//function for waiting,...
int waiting(){
//clearing the LCD
lcd.clear();
//writing 'READY'to LCD
lcd.write("READY!!!!");
if (analogRead(tsuki) && analogRead(shinai) < threshold){
//if threshold is greater than voltage on TSUKI pin, means there is a hit,..
//return 4
return 4;
}
if ((analogRead(dou) < threshold) && (analogRead(shinai) < threshold)){
//similarly, for do return 3........
return 3;
}
if (analogRead(kote)&& analogRead(shinai) < threshold){
return 2;
}
if (analogRead(men) && analogRead(shinai) < threshold){
return 1;
}
//else
return 0;
}
//================================================
//function for FORCE..
double force(int v){
double F = 0.0;
//for formula of FORCE,
//take two points, x1,y1 and x2,y2, where X is Force, Y is the votage reading,.
//now use two-point linear equation to estimate the linear behaviour of the circuit,.
//we can create an equation for Force and Voltage..
//and then putting the voltage in the equation v,.. we can get the force
F = ((v-121)/(-0.267))+0.5;
return F;
}
//===========================================
//function for showing MSG on LCD and saving data...
void show_msg(int number,double vf){
//passing in the number from the function of waiting,..(HIT number)
//and velocity
if (number == 0){
f = force(analogRead(shinai));
lcd.clear();
lcd.write("INVALID STRIKE!!!");
lcd.setCursor(0,1);
Serial.print("U");
Serial.print('\t');
Serial.print(vf);
Serial.print('\t');
Serial.println(f);
lcd.write("S: ");
lcd.print(vf);
lcd.setCursor(8,1);
lcd.write("F: ");
lcd.print(f);
int start = millis();
while(millis() - start <2000){
delay(100);
lcd.noDisplay();
delay(100);
lcd.display();
}
lcd.clear();
}
if (number == 1){
//if hit is at head
//calculate force using the function over the voltage reading,..
f = force(analogRead(men));
//clearing LCD
lcd.clear();
//writing MEN hit on LCD
lcd.write("MEN STRIKE!!!");
//setting cursor to line 2,... row 1, col 0
lcd.setCursor(0,1);
//writing speed
lcd.write("S: ");
lcd.print(vf);
//shifting to col-8
lcd.setCursor(8,1);
//writing FORCE
lcd.write("F: ");
//using PRINT function as double can not be written using Write function,..
lcd.print(f);
//now sending data to COM port using Serial protocol,
//sending data in format:
// "D 5.00(V) 10(F)"
//Separated by TABS
Serial.print("D");
Serial.print('\t');
Serial.print(vf);
Serial.print('\t');
Serial.println(f);
//now looping for 2 seconds = 2000milliseconds
int start = millis();
while(millis() - start <2000){
//flashing LCD, using ON, and then wait 150ms and then OFF, and repeat
delay(150);
lcd.noDisplay();
delay(150);
lcd.display();
}
//clearing..
lcd.clear();
}
//Similar to above....
if (number == 2){
f = force(analogRead(kote));
lcd.clear();
lcd.write("KOTE STRIKE!!!");
Serial.print("R");
Serial.print('\t');
Serial.print(vf);
Serial.print('\t');
Serial.println(f);
lcd.setCursor(0,1);
lcd.write("S: ");
lcd.print(vf);
lcd.setCursor(8,1);
lcd.write("F: ");
lcd.print(f);
int start = millis();
while(millis() - start <2000){
delay(150);
lcd.noDisplay();
delay(150);
lcd.display();
}
lcd.clear();
}
if (number == 3){
lcd.clear();
f = force(analogRead(dou));
lcd.write("DO STRIKE!!!");
Serial.print("L");
Serial.print('\t');
Serial.print(vf);
Serial.print('\t');
Serial.println(f);
lcd.setCursor(0,1);
lcd.write("S: ");
lcd.print(vf);
lcd.setCursor(8,1);
lcd.write("F: ");
lcd.print(f);
int start = millis();
while(millis() - start <2000){
delay(150);
lcd.noDisplay();
delay(150);
lcd.display();
}
lcd.clear();
}
if (number == 4){
f = force(analogRead(tsuki));
lcd.clear();
lcd.write("TSUKI STRIKE!!!");
lcd.setCursor(0,1);
Serial.print("U");
Serial.print('\t');
Serial.print(vf);
Serial.print('\t');
Serial.println(f);
lcd.write("S: ");
lcd.print(vf);
lcd.setCursor(8,1);
lcd.write("F: ");
lcd.print(f);
int start = millis();
while(millis() - start <2000){
delay(100);
lcd.noDisplay();
delay(100);
lcd.display();
}
lcd.clear();
}
lcd.setCursor(0, 0);
}
I'm trying to code in which when two sensors, the weapon(shinai) sensor hit the sensor from the armor, it will display on the LCD which part of the armor got hit. I already tested the program and it always displays which part of the armor got hit even though the weapon(shinai) sensor was not the one hitting the armor sensor