before   BlOG   next
Paintball Chrono
Paintball Chrono



paintball_chrono.ino
#include < Wire.h>

// include the library code:
#include < LiquidCrystal.h>

// Aktualisierungsintervall Display
unsigned long actdisplay = 1000;
// Anzahl der Schleifendurchläufe calibrate
unsigned int count = 500;
// Abweichung Multiplyer (ab wann wird die Schranke ausgelöst HINT: *0.5) (Für IR Einstrahlung)
unsigned int multiply = 3;
// Abweichung Addy (Schwelle vom Minimum abzuziehen - Empfindlichkeit)
unsigned int addy = 50;

// maximaler Zeitraum einer Messung (micros)
unsigned long timeout = 1000000;  // 1000000 ist eine Sekunde
// Meldungslesezeit
unsigned int meldezeit = 1000;

unsigned long lastdisplay = 0+actdisplay;


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

unsigned int sensorA7 = 0;
unsigned int sensorA6 = 0;
unsigned int sensorA5 = 0;
unsigned int irstat = 0;

unsigned long time0 = 0;
unsigned long A7time = 0;
unsigned long A6time = 0;
unsigned long A5time = 0;

unsigned long lastbreak0;

float etime20;
float etime101;
float etime102;

float gesch20;
float gesch101;
float gesch102;

unsigned long sensorA7onsch = 0; unsigned long sensorA6onsch = 0; unsigned long sensorA5onsch = 0;
unsigned long sensorA7onmax = 0; unsigned long sensorA6onmax = 0; unsigned long sensorA5onmax = 0;
unsigned long sensorA7onmin = 1023; unsigned long sensorA6onmin = 1023; unsigned long sensorA5onmin = 1023;

unsigned long sensorA7offsch = 0; unsigned long sensorA6offsch = 0; unsigned long sensorA5offsch = 0;
unsigned long sensorA7offmax = 0; unsigned long sensorA6offmax = 0; unsigned long sensorA5offmax = 0;
unsigned long sensorA7offmin = 1023; unsigned long sensorA6offmin = 1023; unsigned long sensorA5offmin = 1023;

unsigned long A7Schwelle = 0; unsigned long A6Schwelle = 0; unsigned long A5Schwelle = 0;

void setup() {
  // PIN 6,7,8 sind die IR LED, am Anfang auf OUTPUT und LOW setzen
  pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT); 
  ironoff(0);
  
  // LCD initialisieren
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  // Name und Versionsinformationen
  lcd.print("T.E.E.    Chrono");
  lcd.setCursor(0, 1);
  lcd.print("Version: 0.6    ");
  delay(meldezeit);                  // Lesezeit

  lcd.clear(); lcd.setCursor(0, 0); lcd.print("[ ] calibrate IR   ");

  // Sensoren auslesen und Mittelwert bilden (Status aus) 
  delay(150);  // kurz warten

  for (int i=0; i sensorA7) {sensorA7offmin = sensorA7;}; if (sensorA7offmax < sensorA7) {sensorA7offmax = sensorA7;};
   if (sensorA6offmin > sensorA6) {sensorA6offmin = sensorA6;}; if (sensorA6offmax < sensorA6) {sensorA6offmax = sensorA6;};
   if (sensorA5offmin > sensorA5) {sensorA5offmin = sensorA5;}; if (sensorA5offmax < sensorA5) {sensorA5offmax = sensorA5;};
  }
  sensorA7offsch = sensorA7offsch/count; sensorA6offsch = sensorA6offsch/count; sensorA5offsch = sensorA5offsch/count;
  
  lcd.setCursor(0, 1);
  lcd.print(sensorA5offsch); lcd.print(" "); 
  lcd.print(sensorA6offsch); lcd.print(" "); 
  lcd.print(sensorA7offsch);
  delay(meldezeit);
  
  lcd.setCursor(1, 0); lcd.print("*");
  // IR-LED @ 8,7,6 auf HIGH
  ironoff(1);

  // Sensoren auslesen und Mittelwert bilden (Status an) 
  delay(150);  // kurz warten

  for (int i=0; i sensorA7) {sensorA7onmin = sensorA7;}; if (sensorA7onmax < sensorA7) {sensorA7onmax = sensorA7;};
   if (sensorA6onmin > sensorA6) {sensorA6onmin = sensorA6;}; if (sensorA6onmax < sensorA6) {sensorA6onmax = sensorA6;};
   if (sensorA5onmin > sensorA5) {sensorA5onmin = sensorA5;}; if (sensorA5onmax < sensorA5) {sensorA5onmax = sensorA5;};
  }
  sensorA7onsch = sensorA7onsch/count; sensorA6onsch = sensorA6onsch/count; sensorA5onsch = sensorA5onsch/count;
  
  lcd.clear(); lcd.setCursor(0, 0); lcd.print("[*] calibrate IR   ");
  lcd.setCursor(0, 1);
  lcd.print(sensorA5onsch); lcd.print(" "); 
  lcd.print(sensorA6onsch); lcd.print(" "); 
  lcd.print(sensorA7onsch);

  delay(meldezeit);
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Sensorschwelle"); lcd.setCursor(0, 1);

  A5Schwelle = sensorA5onmin-((((sensorA5onmax-sensorA5onmin)+sensorA5offmax)*multiply)+addy);
  if (A5Schwelle > 1023) {A5Schwelle = sensorA5onmin-addy;};
  A6Schwelle = sensorA6onmin-((((sensorA6onmax-sensorA6onmin)+sensorA6offmax)*multiply)+addy);
  if (A6Schwelle > 1023) {A6Schwelle = sensorA6onmin-addy;};
  A7Schwelle = sensorA7onmin-((((sensorA7onmax-sensorA7onmin)+sensorA7offmax)*multiply)+addy);
  if (A7Schwelle > 1023) {A7Schwelle = sensorA7onmin-addy;};
  
  lcd.print(A5Schwelle); lcd.print(" "); 
  lcd.print(A6Schwelle); lcd.print(" "); 
  lcd.print(A7Schwelle);  
  delay(meldezeit); lcd.clear(); count=0;
}

void loop() {
  time0 = micros();

  if (A7timetime0-timeout) || (A5time>time0-timeout)) && (A6time= lastdisplay) {
    // displayir();
    displayhit();
  };
  count++;
};

void displayhit () {
  lcd.setCursor(11, 1);
  lcd.print("["); 
  if (sensorA5 < A5Schwelle) { lcd.print("*"); } else {lcd.print("o");};
  if (sensorA6 < A6Schwelle) { lcd.print("*"); } else {lcd.print("o");};
  if (sensorA7 < A7Schwelle) { lcd.print("*"); } else {lcd.print("o");};

  lcd.print("]"); 
  
  if (A7time > A5time) {
    etime20 = A7time - A5time; 
  }
  else if (A7time < A5time) {
    etime20 = A5time - A7time; 
  };
  if (A7time > A6time) {
    etime101 = A7time - A6time;
  }
  else if (A7time < A6time) {
    etime101 = A6time - A7time;
  };
  if (A5time > A6time) {
    etime102 = A5time - A6time;
  }
  else if (A5time < A6time) {
    etime102 = A6time - A5time;
  };
  gesch101 = 1/((etime101)/100000);
  gesch102 = 1/((etime102)/100000);
  gesch20 = 1/((etime20)/200000);
  // lcd.setCursor(0, 0); lcd.print("m/s: "); lcd.print(gesch20); 
  lcd.setCursor(0, 0); 
  lcd.print(int((gesch102*3.28083989501)+0.5));
  lcd.print("|");
  lcd.print(int((gesch101*3.28083989501)+0.5));
  lcd.print("|");
  lcd.print(int((gesch20*3.28083989501)+0.5));
  lcd.print("           "); 
  lcd.setCursor(13, 0); 
  lcd.print("fps");
  lcd.setCursor(0, 1);
  lcd.print("10|10|20");
  // lcd.print(A7time); lcd.print("|"); lcd.print(A6time); lcd.print("|"); lcd.print(A5time);
  lastdisplay = millis();
};

void displayir () {
  lcd.setCursor(0, 0);
  lcd.print("1: "); lcd.print(sensorA5); lcd.print("|"); 
  lcd.setCursor(9, 0);
  lcd.print("2: "); lcd.print(sensorA6); lcd.print("|");
  lcd.setCursor(0, 1);
  lcd.print("3: "); lcd.print(sensorA7); lcd.print("           ");  
  lcd.setCursor(9, 1); 
  lcd.print("IR: ["); 
  if (irstat == 0) { lcd.print(" ");}
  else {lcd.print("*");};
  lcd.print("]");
  // lcd.print(count);
  lastdisplay = millis();
}

void ironoff (boolean anoderaus) {
  if (anoderaus == 1) { digitalWrite(8, HIGH); digitalWrite(7, HIGH); digitalWrite(6, HIGH); irstat = 1; }
  else { digitalWrite(8, LOW); digitalWrite(7, LOW); digitalWrite(6, LOW); irstat = 0; };
}




before   BlOG   next

seemly