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
GoalCounter.cpp
- Committer:
- nxf46245
- Date:
- 2019-01-13
- Revision:
- 3:ce69ad70270a
- Parent:
- 2:cb1c7db56434
- Child:
- 4:fc48ef79f484
File content as of revision 3:ce69ad70270a:
#include "GoalCounter.h" GoalCounter::GoalCounter(PinName pin, Timer * t) : _t(t) { InterruptIn *_interrupt = new InterruptIn(pin); _interrupt->fall(callback(this, &GoalCounter::tstart)); _interrupt->rise(callback(this, &GoalCounter::tstop)); _score = 0; _time = 0; is_goal = 0; } void GoalCounter::tstart() { _t->start(); } void GoalCounter::tstop() { _t->stop(); _time = _t->read(); _t->reset(); if ( _time > 0 && _time < 2 && _score < 10) { _score++; _balltimes[_score] = _time; is_goal = 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; }