Create this program

Dependencies:   mbed HCSR04 HMC6352 PID TextLCD

Committer:
KoiShin_Sakana
Date:
Tue Aug 11 13:11:05 2015 +0000
Revision:
6:44c3bfbe2553
Parent:
5:e07e380ddb93
update dribbler.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KoiShin_Sakana 3:901d18b901b4 1 /**
KoiShin_Sakana 5:e07e380ddb93 2 * @file : kicker.h (1.0)
KoiShin_Sakana 3:901d18b901b4 3 * @brief : kick the ball
KoiShin_Sakana 3:901d18b901b4 4 * @author : Shinnosuke KOIKE
KoiShin_Sakana 5:e07e380ddb93 5 * @date : 2015/08/08
KoiShin_Sakana 3:901d18b901b4 6 */
KoiShin_Sakana 3:901d18b901b4 7
KoiShin_Sakana 3:901d18b901b4 8 #ifndef KICKER_H
KoiShin_Sakana 3:901d18b901b4 9 #define KICKER_H
KoiShin_Sakana 3:901d18b901b4 10
KoiShin_Sakana 3:901d18b901b4 11 #include "mbed.h"
KoiShin_Sakana 3:901d18b901b4 12
KoiShin_Sakana 3:901d18b901b4 13 class Kicker {
KoiShin_Sakana 5:e07e380ddb93 14 public:
KoiShin_Sakana 5:e07e380ddb93 15 Kicker(PinName kicker_, PinName brightness_);
KoiShin_Sakana 5:e07e380ddb93 16 ~Kicker();
KoiShin_Sakana 5:e07e380ddb93 17 void kick(void);
KoiShin_Sakana 5:e07e380ddb93 18
KoiShin_Sakana 5:e07e380ddb93 19 private:
KoiShin_Sakana 5:e07e380ddb93 20 DigitalOut kicker;
KoiShin_Sakana 5:e07e380ddb93 21 DigitalIn brightness;
KoiShin_Sakana 5:e07e380ddb93 22 Timer timer;
KoiShin_Sakana 5:e07e380ddb93 23 bool enableKick;
KoiShin_Sakana 5:e07e380ddb93 24 void count(void);
KoiShin_Sakana 3:901d18b901b4 25 };
KoiShin_Sakana 3:901d18b901b4 26
KoiShin_Sakana 5:e07e380ddb93 27 // initialize
KoiShin_Sakana 5:e07e380ddb93 28 Kicker::Kicker(PinName kicker_, PinName brightness_):
KoiShin_Sakana 5:e07e380ddb93 29 kicker(kicker_), brightness(brightness_) {
KoiShin_Sakana 5:e07e380ddb93 30 }
KoiShin_Sakana 5:e07e380ddb93 31
KoiShin_Sakana 5:e07e380ddb93 32 // end timer
KoiShin_Sakana 5:e07e380ddb93 33 Kicker::~Kicker() {
KoiShin_Sakana 5:e07e380ddb93 34 timer.reset();
KoiShin_Sakana 5:e07e380ddb93 35 timer.stop();
KoiShin_Sakana 5:e07e380ddb93 36 }
KoiShin_Sakana 5:e07e380ddb93 37
KoiShin_Sakana 5:e07e380ddb93 38 // count and set a kick flag
KoiShin_Sakana 5:e07e380ddb93 39 void Kicker::count(void) {
KoiShin_Sakana 5:e07e380ddb93 40 timer.start();
KoiShin_Sakana 5:e07e380ddb93 41 float val = timer.read();
KoiShin_Sakana 6:44c3bfbe2553 42 if (val >= 2) {
KoiShin_Sakana 5:e07e380ddb93 43 this->enableKick = 1;
KoiShin_Sakana 5:e07e380ddb93 44 }
KoiShin_Sakana 5:e07e380ddb93 45 }
KoiShin_Sakana 5:e07e380ddb93 46
KoiShin_Sakana 5:e07e380ddb93 47 // if ball exist before their's eyes and was set a kick flag, kick the ball
KoiShin_Sakana 5:e07e380ddb93 48 void Kicker::kick(void) {
KoiShin_Sakana 5:e07e380ddb93 49 this->count();
KoiShin_Sakana 5:e07e380ddb93 50 if (brightness == 0 && enableKick == 1) {
KoiShin_Sakana 5:e07e380ddb93 51 kicker = 1;
KoiShin_Sakana 5:e07e380ddb93 52 timer.reset();
KoiShin_Sakana 5:e07e380ddb93 53 this->enableKick = 0;
KoiShin_Sakana 5:e07e380ddb93 54 }
KoiShin_Sakana 5:e07e380ddb93 55 }
KoiShin_Sakana 5:e07e380ddb93 56
KoiShin_Sakana 5:e07e380ddb93 57 #endif
KoiShin_Sakana 5:e07e380ddb93 58
KoiShin_Sakana 5:e07e380ddb93 59 /**
KoiShin_Sakana 5:e07e380ddb93 60 * example program
KoiShin_Sakana 5:e07e380ddb93 61
KoiShin_Sakana 5:e07e380ddb93 62 #include "mbed.h"
KoiShin_Sakana 5:e07e380ddb93 63 #include "kicker.h"
KoiShin_Sakana 5:e07e380ddb93 64
KoiShin_Sakana 5:e07e380ddb93 65 int main(void) {
KoiShin_Sakana 5:e07e380ddb93 66 Kicker kicker(D0, D1);
KoiShin_Sakana 5:e07e380ddb93 67 while (1) {
KoiShin_Sakana 5:e07e380ddb93 68 kicker.kick();
KoiShin_Sakana 5:e07e380ddb93 69 }
KoiShin_Sakana 5:e07e380ddb93 70 }
KoiShin_Sakana 5:e07e380ddb93 71 */