This library provides simple interface for the table football goal counter based on a IR LED or laser diode and phototransistor.

Files at this revision

API Documentation at this revision

Comitter:
nxf46245
Date:
Sat Jan 12 18:57:26 2019 +0000
Child:
1:eb4ee5706587
Commit message:
First commit to GoalCounter library, still not a production version

Changed in this revision

GoalCounter.cpp Show annotated file Show diff for this revision Revisions of this file
GoalCounter.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GoalCounter.cpp	Sat Jan 12 18:57:26 2019 +0000
@@ -0,0 +1,91 @@
+#include "GoalCounter.h"
+
+GoalCounter::GoalCounter(PinName pin1, PinName pin2) : _interrupt1(pin1) {
+    _interrupt1.fall(callback(this, &GoalCounter::tstart1));
+    _interrupt1.rise(callback(this, &GoalCounter::tstop1));
+    
+//    _interrupt2.fall(callback(this, &GoalCounter::tstart2));
+//    _interrupt2.rise(callback(this, &GoalCounter::tstop2));
+    
+    Timer t1;
+    Timer t2;
+    
+    _score1 = 0;
+    _score2 = 0;
+    
+    _time1 = 0;
+    _time2 = 0;
+    
+//    _balltimes1 = {0};
+//    _balltimes2 = {0};
+    
+    is_goal1 = 0;
+    is_goal2 = 0;
+    
+}
+         
+void GoalCounter::tstart1() {
+    t1.start();
+}
+
+void GoalCounter::tstop1() {
+    t1.stop();
+    _time1 = t1.read();
+    t1.reset();
+    
+    if ( _time1 > 0 && _time1 < 2 && _score1 < 10) {
+       _balltimes1[++_score1] = _time1;
+       is_goal1 = 1;
+    }     
+}
+
+void GoalCounter::tstart2() {
+    t2.start();
+}
+
+void GoalCounter::tstop2() {
+    t2.stop();
+    _time2 = t2.read();
+    t2.reset();
+    
+    if ( _time2 > 0 && _time2 < 2 && _score2 < 10) {
+       _balltimes2[++_score2] = _time2;
+       is_goal2 = 1;
+    }     
+}
+
+uint8_t GoalCounter::get_score() {
+    return _score1;
+}
+
+float GoalCounter::get_balltime(uint8_t score) {
+    if (score <= 10 && score > 0)
+        return _balltimes1[score];
+    else
+        return -1;   
+}
+
+float GoalCounter::get_balltime() {
+    return _balltimes1[_score1];
+ 
+}
+
+float GoalCounter::get_ballspeed(uint8_t score) {
+    if (score <= 10 && score > 0) {
+        float speed = 0.034f/_balltimes1[score]*3.6f;
+        return speed;
+    }
+    else
+        return -1;   
+}
+
+float GoalCounter::get_ballspeed() {
+    float speed = 0.034f/_balltimes1[_score1]*3.6f;
+    return speed;
+}
+
+
+
+    
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GoalCounter.h	Sat Jan 12 18:57:26 2019 +0000
@@ -0,0 +1,32 @@
+#include "mbed.h"
+
+class GoalCounter {
+public:
+    GoalCounter(PinName pin1, PinName pin2);  
+    void tstart1();
+    void tstop1();
+    void tstart2();
+    void tstop2();
+    uint8_t get_score();
+    float get_balltime(uint8_t score);
+    float get_balltime();
+    float get_ballspeed(uint8_t score);
+    float get_ballspeed();
+    uint8_t is_goal1;
+    uint8_t is_goal2;
+
+
+private:
+    InterruptIn _interrupt1;
+//    InterruptIn _interrupt2;
+    volatile uint8_t _score1;
+    volatile uint8_t _score2;
+    Timer t1;
+    Timer t2;
+    float _balltimes1[11];
+    float _time1;
+    float _balltimes2[11];
+    float _time2; 
+      
+};
+