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:
Sun Jan 13 16:43:27 2019 +0000
Revision:
3:ce69ad70270a
Parent:
1:eb4ee5706587
Child:
4:fc48ef79f484
updated docs;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxf46245 1:eb4ee5706587 1 #ifndef GOALCOUNTER_H
nxf46245 1:eb4ee5706587 2 #define GOALCOUNTER_H
nxf46245 1:eb4ee5706587 3
nxf46245 0:d00bd73d08f8 4 #include "mbed.h"
nxf46245 0:d00bd73d08f8 5
nxf46245 3:ce69ad70270a 6 /** GoalCounter class.
nxf46245 3:ce69ad70270a 7 * Simple implementation of goal counter for table football using laser diode
nxf46245 3:ce69ad70270a 8 * and phototransistor. Output of the phototransistor is connected to the digital
nxf46245 3:ce69ad70270a 9 * input pin of MCU. When the laser beam is interrupted by ball passing the the cage
nxf46245 3:ce69ad70270a 10 * Timer starts counting and measuring width of the pulse and if the duration of pulse
nxf46245 3:ce69ad70270a 11 * is not longer than two seconds, goal is detected and _score variable is incremented.
nxf46245 3:ce69ad70270a 12 *
nxf46245 3:ce69ad70270a 13 * Pulse duration is also used for the calculation of ball passing speed. However,
nxf46245 3:ce69ad70270a 14 * measurement is not precise.
nxf46245 3:ce69ad70270a 15 *
nxf46245 3:ce69ad70270a 16 * Example:
nxf46245 3:ce69ad70270a 17 * @code
nxf46245 3:ce69ad70270a 18 * #include "mbed.h"
nxf46245 3:ce69ad70270a 19 * #include "GoalCounter.h"
nxf46245 3:ce69ad70270a 20 *
nxf46245 3:ce69ad70270a 21 * Timer t;
nxf46245 3:ce69ad70270a 22 * GoalCounter gc(D2, &t);
nxf46245 3:ce69ad70270a 23 *
nxf46245 3:ce69ad70270a 24 * int main() {
nxf46245 3:ce69ad70270a 25 * while(1) {
nxf46245 3:ce69ad70270a 26 * if (gc.is_goal)
nxf46245 3:ce69ad70270a 27 * goal(); // call some function
nxf46245 3:ce69ad70270a 28 * }
nxf46245 3:ce69ad70270a 29 *
nxf46245 3:ce69ad70270a 30 * }
nxf46245 3:ce69ad70270a 31 *
nxf46245 3:ce69ad70270a 32 * @endcode
nxf46245 3:ce69ad70270a 33 *
nxf46245 3:ce69ad70270a 34 **/
nxf46245 3:ce69ad70270a 35
nxf46245 0:d00bd73d08f8 36 class GoalCounter {
nxf46245 0:d00bd73d08f8 37 public:
nxf46245 3:ce69ad70270a 38 /**
nxf46245 3:ce69ad70270a 39 * Constructor
nxf46245 3:ce69ad70270a 40 *
nxf46245 3:ce69ad70270a 41 * @param pin Input pin where is the outpout of phototransistor connected
nxf46245 3:ce69ad70270a 42 * @param timer reference to the Timer instance
nxf46245 3:ce69ad70270a 43 *
nxf46245 3:ce69ad70270a 44 */
nxf46245 1:eb4ee5706587 45 GoalCounter(PinName pin, Timer * t);
nxf46245 3:ce69ad70270a 46 /**
nxf46245 3:ce69ad70270a 47 * Starts the timer, this function is called from the interrupt pin callback
nxf46245 3:ce69ad70270a 48 */
nxf46245 1:eb4ee5706587 49 void tstart();
nxf46245 3:ce69ad70270a 50 /**
nxf46245 3:ce69ad70270a 51 * Stops the timer, this function is called from the interrupt pin callback
nxf46245 3:ce69ad70270a 52 */
nxf46245 1:eb4ee5706587 53 void tstop();
nxf46245 3:ce69ad70270a 54 /**
nxf46245 3:ce69ad70270a 55 * Returns score
nxf46245 3:ce69ad70270a 56 * @return score score of the game
nxf46245 3:ce69ad70270a 57 */
nxf46245 0:d00bd73d08f8 58 uint8_t get_score();
nxf46245 3:ce69ad70270a 59 /**
nxf46245 3:ce69ad70270a 60 * Returns time of a ball pass for a given score
nxf46245 3:ce69ad70270a 61 * @param score of the game
nxf46245 3:ce69ad70270a 62 * @return time of a ball pass in seconds
nxf46245 3:ce69ad70270a 63 */
nxf46245 0:d00bd73d08f8 64 float get_balltime(uint8_t score);
nxf46245 3:ce69ad70270a 65 /**
nxf46245 3:ce69ad70270a 66 * Returns time of a ball pass for the current score
nxf46245 3:ce69ad70270a 67 * @return time of a ball pass in seconds
nxf46245 3:ce69ad70270a 68 */
nxf46245 0:d00bd73d08f8 69 float get_balltime();
nxf46245 3:ce69ad70270a 70 /**
nxf46245 3:ce69ad70270a 71 * Returns speed of a ball pass for a given score
nxf46245 3:ce69ad70270a 72 * @param score of the game
nxf46245 3:ce69ad70270a 73 * @return speed of a ball pass in kph
nxf46245 3:ce69ad70270a 74 */
nxf46245 0:d00bd73d08f8 75 float get_ballspeed(uint8_t score);
nxf46245 3:ce69ad70270a 76 /**
nxf46245 3:ce69ad70270a 77 * Returns speed of a ball pass for the current score
nxf46245 3:ce69ad70270a 78 * @return speed of a ball pass in kph
nxf46245 3:ce69ad70270a 79 */
nxf46245 0:d00bd73d08f8 80 float get_ballspeed();
nxf46245 3:ce69ad70270a 81 /**
nxf46245 3:ce69ad70270a 82 * Variable is 1 when the goal is detected
nxf46245 3:ce69ad70270a 83 */
nxf46245 1:eb4ee5706587 84 volatile uint8_t is_goal;
nxf46245 0:d00bd73d08f8 85
nxf46245 0:d00bd73d08f8 86 private:
nxf46245 1:eb4ee5706587 87 InterruptIn * _interrupt;
nxf46245 1:eb4ee5706587 88 volatile uint8_t _score;
nxf46245 1:eb4ee5706587 89 Timer * _t;
nxf46245 1:eb4ee5706587 90 float _balltimes[11];
nxf46245 1:eb4ee5706587 91 float _time;
nxf46245 0:d00bd73d08f8 92
nxf46245 0:d00bd73d08f8 93 };
nxf46245 0:d00bd73d08f8 94
nxf46245 1:eb4ee5706587 95 #endif