Marek Vitula / Mbed OS goal_counter_project

Dependencies:   GoalCounter WS2812 PixelArray

Revision:
0:24f846b68c77
Child:
2:f04959a6fd61
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GoalCounter.cpp	Thu Jan 10 14:48:03 2019 +0000
@@ -0,0 +1,59 @@
+#include "GoalCounter.h"
+
+GoalCounter::GoalCounter(PinName pin) : _interrupt(pin) {
+    _interrupt.fall(this, &GoalCounter::tstart);
+    _interrupt.rise(this, &GoalCounter::tstop);
+//    _balltimes = {0};
+    _score= 0;   
+}
+         
+void GoalCounter::tstart() {
+    t.start();
+}
+
+void GoalCounter::tstop() {
+    t.stop();
+    _time = t.read();
+    t.reset();
+    
+    if ( _time > 0 && _time < 2 && _score < 10) {
+       _balltimes[++_score] = _time;
+       goal = 1;
+//       wait(1);
+        }     
+}
+
+uint8_t GoalCounter::get_score() {
+    return _score;
+}
+
+float GoalCounter::get_balltime(uint8_t score) {
+    if (score <= 10 && score > 0)
+        return _balltimes[score];
+    else
+        return -1;   
+}
+
+float GoalCounter::get_balltime() {
+    return _balltimes[_score];
+ 
+}
+
+float GoalCounter::get_ballspeed(uint8_t score) {
+    if (score <= 10 && score > 0) {
+        float speed = 0.034f/_balltimes[score]*3.6f;
+        return speed;
+    }
+    else
+        return -1;   
+}
+
+float GoalCounter::get_ballspeed() {
+    float speed = 0.034f/_balltimes[_score]*3.6f;
+    return speed;
+}
+
+
+    
+
+