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

Dependents:   goal_counter_project

Committer:
nxf46245
Date:
Sat Jan 12 18:57:26 2019 +0000
Revision:
0:d00bd73d08f8
Child:
1:eb4ee5706587
First commit to GoalCounter library, still not a production version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxf46245 0:d00bd73d08f8 1 #include "GoalCounter.h"
nxf46245 0:d00bd73d08f8 2
nxf46245 0:d00bd73d08f8 3 GoalCounter::GoalCounter(PinName pin1, PinName pin2) : _interrupt1(pin1) {
nxf46245 0:d00bd73d08f8 4 _interrupt1.fall(callback(this, &GoalCounter::tstart1));
nxf46245 0:d00bd73d08f8 5 _interrupt1.rise(callback(this, &GoalCounter::tstop1));
nxf46245 0:d00bd73d08f8 6
nxf46245 0:d00bd73d08f8 7 // _interrupt2.fall(callback(this, &GoalCounter::tstart2));
nxf46245 0:d00bd73d08f8 8 // _interrupt2.rise(callback(this, &GoalCounter::tstop2));
nxf46245 0:d00bd73d08f8 9
nxf46245 0:d00bd73d08f8 10 Timer t1;
nxf46245 0:d00bd73d08f8 11 Timer t2;
nxf46245 0:d00bd73d08f8 12
nxf46245 0:d00bd73d08f8 13 _score1 = 0;
nxf46245 0:d00bd73d08f8 14 _score2 = 0;
nxf46245 0:d00bd73d08f8 15
nxf46245 0:d00bd73d08f8 16 _time1 = 0;
nxf46245 0:d00bd73d08f8 17 _time2 = 0;
nxf46245 0:d00bd73d08f8 18
nxf46245 0:d00bd73d08f8 19 // _balltimes1 = {0};
nxf46245 0:d00bd73d08f8 20 // _balltimes2 = {0};
nxf46245 0:d00bd73d08f8 21
nxf46245 0:d00bd73d08f8 22 is_goal1 = 0;
nxf46245 0:d00bd73d08f8 23 is_goal2 = 0;
nxf46245 0:d00bd73d08f8 24
nxf46245 0:d00bd73d08f8 25 }
nxf46245 0:d00bd73d08f8 26
nxf46245 0:d00bd73d08f8 27 void GoalCounter::tstart1() {
nxf46245 0:d00bd73d08f8 28 t1.start();
nxf46245 0:d00bd73d08f8 29 }
nxf46245 0:d00bd73d08f8 30
nxf46245 0:d00bd73d08f8 31 void GoalCounter::tstop1() {
nxf46245 0:d00bd73d08f8 32 t1.stop();
nxf46245 0:d00bd73d08f8 33 _time1 = t1.read();
nxf46245 0:d00bd73d08f8 34 t1.reset();
nxf46245 0:d00bd73d08f8 35
nxf46245 0:d00bd73d08f8 36 if ( _time1 > 0 && _time1 < 2 && _score1 < 10) {
nxf46245 0:d00bd73d08f8 37 _balltimes1[++_score1] = _time1;
nxf46245 0:d00bd73d08f8 38 is_goal1 = 1;
nxf46245 0:d00bd73d08f8 39 }
nxf46245 0:d00bd73d08f8 40 }
nxf46245 0:d00bd73d08f8 41
nxf46245 0:d00bd73d08f8 42 void GoalCounter::tstart2() {
nxf46245 0:d00bd73d08f8 43 t2.start();
nxf46245 0:d00bd73d08f8 44 }
nxf46245 0:d00bd73d08f8 45
nxf46245 0:d00bd73d08f8 46 void GoalCounter::tstop2() {
nxf46245 0:d00bd73d08f8 47 t2.stop();
nxf46245 0:d00bd73d08f8 48 _time2 = t2.read();
nxf46245 0:d00bd73d08f8 49 t2.reset();
nxf46245 0:d00bd73d08f8 50
nxf46245 0:d00bd73d08f8 51 if ( _time2 > 0 && _time2 < 2 && _score2 < 10) {
nxf46245 0:d00bd73d08f8 52 _balltimes2[++_score2] = _time2;
nxf46245 0:d00bd73d08f8 53 is_goal2 = 1;
nxf46245 0:d00bd73d08f8 54 }
nxf46245 0:d00bd73d08f8 55 }
nxf46245 0:d00bd73d08f8 56
nxf46245 0:d00bd73d08f8 57 uint8_t GoalCounter::get_score() {
nxf46245 0:d00bd73d08f8 58 return _score1;
nxf46245 0:d00bd73d08f8 59 }
nxf46245 0:d00bd73d08f8 60
nxf46245 0:d00bd73d08f8 61 float GoalCounter::get_balltime(uint8_t score) {
nxf46245 0:d00bd73d08f8 62 if (score <= 10 && score > 0)
nxf46245 0:d00bd73d08f8 63 return _balltimes1[score];
nxf46245 0:d00bd73d08f8 64 else
nxf46245 0:d00bd73d08f8 65 return -1;
nxf46245 0:d00bd73d08f8 66 }
nxf46245 0:d00bd73d08f8 67
nxf46245 0:d00bd73d08f8 68 float GoalCounter::get_balltime() {
nxf46245 0:d00bd73d08f8 69 return _balltimes1[_score1];
nxf46245 0:d00bd73d08f8 70
nxf46245 0:d00bd73d08f8 71 }
nxf46245 0:d00bd73d08f8 72
nxf46245 0:d00bd73d08f8 73 float GoalCounter::get_ballspeed(uint8_t score) {
nxf46245 0:d00bd73d08f8 74 if (score <= 10 && score > 0) {
nxf46245 0:d00bd73d08f8 75 float speed = 0.034f/_balltimes1[score]*3.6f;
nxf46245 0:d00bd73d08f8 76 return speed;
nxf46245 0:d00bd73d08f8 77 }
nxf46245 0:d00bd73d08f8 78 else
nxf46245 0:d00bd73d08f8 79 return -1;
nxf46245 0:d00bd73d08f8 80 }
nxf46245 0:d00bd73d08f8 81
nxf46245 0:d00bd73d08f8 82 float GoalCounter::get_ballspeed() {
nxf46245 0:d00bd73d08f8 83 float speed = 0.034f/_balltimes1[_score1]*3.6f;
nxf46245 0:d00bd73d08f8 84 return speed;
nxf46245 0:d00bd73d08f8 85 }
nxf46245 0:d00bd73d08f8 86
nxf46245 0:d00bd73d08f8 87
nxf46245 0:d00bd73d08f8 88
nxf46245 0:d00bd73d08f8 89
nxf46245 0:d00bd73d08f8 90
nxf46245 0:d00bd73d08f8 91