/* BALLISTIC CHRONOGRAPH
*** NOT FOR DISTRIBUTION ***
20 character 4 line I2C Liquid Crystal Display
Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"
Connect Vcc and Ground, SDA to A4, SCL to A5 on Arduino Nano
Connect the menu UP button to pin A1
Connect the menu DOWN button to pin A0
Connect the menu OK button to pin D3
First IR sensor (OPL550) input pin D10
SecondIR sensor (OPL550) input pin D11
***ENSURE CORRECT SENSOR SEPARATION DISTANCE IS SELECTED BELOW (line 177 *********)
ENSURE THAT ALL LIBRARIES ARE DOWNLOADED TO YOUR SYSTEM FIRST
John W 16/06/2021 [email protected]
*/
#include <Wire.h>
#include <OneButton.h>
#include <LiquidCrystal.h>
#define sensor_1 12 //D12 SW 420 first sensor input pin
#define sensor_2 11 //D12 SW 420 second sensor input pin
void(* resetFunc) (void) = 0; //Reset fuction voi
OneButton buttonUP(4, true); //Digital pin 4 for OK button
OneButton buttonDW(2, true); //Digital pin 2 for DOWN button
OneButton buttonOK(3, true); //Digital pin 3 for UP button
float fps = 0; //storage for feet per sec value (VELOCITY EN)
float pWeight; //Arrow weight in grains
float elap, ms, joule; //time beetwin sensor1 and sensor2, M/S, Joule
float fpstotal = 0; //fps total for average
float average = 0;
float jtotal = 0; //Feet * lbs total for average
float energy = 0; // Energy ??????
float distance = 0.6; //ditance beetwin two sensor here 0,60 meter
const int LCD_COLS = 16; // LCD geometry colums
const int LCD_ROWS = 2; // LCD geometry rows
int one = 1; //pellet weight loop control.... serve ancora ????
int counter_shots = 0; //increment after each shot
unsigned long time1; //tempo al sensore 1
unsigned long time2; //tempo al sensore 2
LiquidCrystal lcd(10, 9, 8, 7, 6, 5); //Parametri LCD
void setup() {
//Serial.begin(9600);
lcd.begin(LCD_COLS, LCD_ROWS); //Inizializza LCD
pWeight = 420; //Peso freccia standard qui 420
buttonOK.attachClick(click1); //-----------------------------------------------
buttonOK.attachLongPressStop(pressStop1); //Attach different..
buttonUP.attachClick(click2); //..buttons actions
buttonDW.attachClick(click3); //-----------------------------------------------
pinMode (sensor_1, INPUT);
pinMode (sensor_2, INPUT);
//digitalWrite(sensor_1, LOW);
//digitalWrite(sensor_2, LOW);
lcd.clear(); //pulisci LCD
lcd.setCursor(0, 0); //Start at character 3 on line 0 (*****character 0 is the first(LH)character****line 0 is TOP LINE****)
lcd.print("Cronografo V 1.0"); //Print
delay(5000); //Aspetta 5 secondi
lcd.clear(); //pulisci LCD
lcd.setCursor(3, 0); //Posizione cursore
lcd.print("ARCIERI DI"); //Print
lcd.setCursor(5, 1); //Posizione cursore
lcd.print("ASCOLI"); //Print
delay(5000); //Aspetta 5 secondi
lcd.clear(); //pulisci LCD
lcd.setCursor(2, 0); //Posizione cursore
lcd.print("PESO FRECCIA"); //Print
lcd.setCursor(3, 1); //Print
lcd.print(pWeight, 0); //Print
lcd.setCursor(8, 1); //Posizione cursore
lcd.print("grani"); //Print
lcd.setCursor(0, 1); //Posizione cursore Dove no da fastidio
}
void loop()
{
buttonOK.tick(); //-----------------------------------------------
buttonUP.tick(); //Read button state
buttonDW.tick(); //-----------------------------------------------
}
void click1() { //Event simple click for OK (button OK)
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Aspetto il colpo"); //Print
lcd.blink(); //display flashing cursor
while (digitalRead(sensor_1) == 0); //pellet timing
//while (digitalRead(firstsensor_1));
time1 = micros();
while (digitalRead(sensor_2) == 0); //pellet timing
//while (digitalRead(secondsensor_2));
time2 = micros();
// -- Calcoli -- Calcoli
elap = time2 - time1; // elapsed time in microsecond
ms = distance * 1000000 /elap; // metres per second calculation (elap in microseconds)
fps = ms * 3.28084; // feet for second (304,8 (feet * mm) * 1000mm )
joule = (pWeight*0.0000647989*ms*ms)/2; // mv2/2 -- KG * M2 / S2
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("# ");
delay(300);
lcd.print(++counter_shots);
delay(300);
// Serial.print("FPS\t");
lcd.setCursor(6, 0); //Start at character 0 on line 1
lcd.print(fps , 0);
lcd.setCursor(10, 0);
lcd.print(" fps");
delay(300);
lcd.setCursor(1, 1); //Start at character 11 on line 1
lcd.print(ms,0 );
lcd.setCursor(4, 1);
lcd.print("mps");
lcd.setCursor(8, 1); //Start at character 1 on line 2
lcd.print(joule, 2 );
lcd.print(" J");
delay(5000);
fpstotal = fpstotal + fps; // averaging code after 5 shots
average = fpstotal / (counter_shots);
jtotal = jtotal + joule;
energy = jtotal / (counter_shots);
lcd.clear();
//if (counter_shots == 5) {
lcd.setCursor(2, 0); //Start at character 4 on line 0
lcd.print ("MEDIA ");
//lcd.setCursor(0, 1);
lcd.print (counter_shots);
lcd.print (" TIRI");
lcd.setCursor(2, 1);
lcd.print(average, 0);
lcd.print (" fps");
lcd.setCursor(10, 1);
lcd.print(energy, 0);
lcd.print (" J");
//lcd.setCursor(14, 2);
lcd.setCursor(19, 1);
//}
}
void reset_variables() {
time1 = 0;
time2 = 0;
}
// HOPE YOU HAVE FUN USING THIS ! CONTACT EMAIL ABOVE FOR QUERIES
void pressStop1() { //Event end of long press to tare before weight shaft
resetFunc();
}
void click2() { //Event simple click for TARE before spine (button 3)
pWeight = pWeight + 5;
lcd.setCursor(3, 1);
lcd.print(pWeight, 0);
lcd.setCursor(3, 3);
}
void click3() { //Event simple click for TARE before spine (button 3)
pWeight = pWeight - 5;
lcd.setCursor(3, 1);
lcd.print(pWeight, 0);
lcd.setCursor(3, 3);
}