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
Diff: GoalCounter.h
- Revision:
- 3:ce69ad70270a
- Parent:
- 1:eb4ee5706587
- Child:
- 4:fc48ef79f484
--- a/GoalCounter.h Sun Jan 13 16:27:23 2019 +0000 +++ b/GoalCounter.h Sun Jan 13 16:43:27 2019 +0000 @@ -3,16 +3,84 @@ #include "mbed.h" +/** GoalCounter class. + * Simple implementation of goal counter for table football using laser diode + * and phototransistor. Output of the phototransistor is connected to the digital + * input pin of MCU. When the laser beam is interrupted by ball passing the the cage + * Timer starts counting and measuring width of the pulse and if the duration of pulse + * is not longer than two seconds, goal is detected and _score variable is incremented. + * + * Pulse duration is also used for the calculation of ball passing speed. However, + * measurement is not precise. + * + * Example: + * @code + * #include "mbed.h" + * #include "GoalCounter.h" + * + * Timer t; + * GoalCounter gc(D2, &t); + * + * int main() { + * while(1) { + * if (gc.is_goal) + * goal(); // call some function + * } + * + * } + * + * @endcode + * + **/ + class GoalCounter { public: + /** + * Constructor + * + * @param pin Input pin where is the outpout of phototransistor connected + * @param timer reference to the Timer instance + * + */ GoalCounter(PinName pin, Timer * t); + /** + * Starts the timer, this function is called from the interrupt pin callback + */ void tstart(); + /** + * Stops the timer, this function is called from the interrupt pin callback + */ void tstop(); + /** + * Returns score + * @return score score of the game + */ uint8_t get_score(); + /** + * Returns time of a ball pass for a given score + * @param score of the game + * @return time of a ball pass in seconds + */ float get_balltime(uint8_t score); + /** + * Returns time of a ball pass for the current score + * @return time of a ball pass in seconds + */ float get_balltime(); + /** + * Returns speed of a ball pass for a given score + * @param score of the game + * @return speed of a ball pass in kph + */ float get_ballspeed(uint8_t score); + /** + * Returns speed of a ball pass for the current score + * @return speed of a ball pass in kph + */ float get_ballspeed(); + /** + * Variable is 1 when the goal is detected + */ volatile uint8_t is_goal; private: