Create this program
Dependencies: mbed HCSR04 HMC6352 PID TextLCD
infrared.h@6:44c3bfbe2553, 2015-08-11 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
KoiShin_Sakana | 2:a8bbf677e774 | 1 | /** |
KoiShin_Sakana | 5:e07e380ddb93 | 2 | * @file : infrared.h (1.0) |
KoiShin_Sakana | 3:901d18b901b4 | 3 | * @brief : examine point the ball exist |
KoiShin_Sakana | 2:a8bbf677e774 | 4 | * @author : Shinnosuke KOIKE |
KoiShin_Sakana | 2:a8bbf677e774 | 5 | * @date : 2015/08/04 |
KoiShin_Sakana | 2:a8bbf677e774 | 6 | */ |
KoiShin_Sakana | 2:a8bbf677e774 | 7 | |
KoiShin_Sakana | 2:a8bbf677e774 | 8 | #ifndef INFRARED_H |
KoiShin_Sakana | 2:a8bbf677e774 | 9 | #define INFRARED_H |
KoiShin_Sakana | 2:a8bbf677e774 | 10 | |
KoiShin_Sakana | 2:a8bbf677e774 | 11 | #include "mbed.h" |
KoiShin_Sakana | 2:a8bbf677e774 | 12 | |
KoiShin_Sakana | 2:a8bbf677e774 | 13 | class Infrared { |
KoiShin_Sakana | 3:901d18b901b4 | 14 | public: |
KoiShin_Sakana | 3:901d18b901b4 | 15 | Infrared(PinName front, PinName frontLeft, PinName left, PinName backLeft, |
KoiShin_Sakana | 3:901d18b901b4 | 16 | PinName back, PinName backRight, PinName right, PinName frontRight); |
KoiShin_Sakana | 3:901d18b901b4 | 17 | char findBallPos(void); |
KoiShin_Sakana | 3:901d18b901b4 | 18 | |
KoiShin_Sakana | 3:901d18b901b4 | 19 | private: |
KoiShin_Sakana | 3:901d18b901b4 | 20 | BusIn infraredData; |
KoiShin_Sakana | 3:901d18b901b4 | 21 | }; |
KoiShin_Sakana | 3:901d18b901b4 | 22 | |
KoiShin_Sakana | 3:901d18b901b4 | 23 | class AnalogInfrared { |
KoiShin_Sakana | 3:901d18b901b4 | 24 | public: |
KoiShin_Sakana | 3:901d18b901b4 | 25 | AnalogInfrared(PinName front, PinName frontLeft, PinName left, PinName backLeft, |
KoiShin_Sakana | 3:901d18b901b4 | 26 | PinName back, PinName backRight, PinName right, PinName frontRight); |
KoiShin_Sakana | 3:901d18b901b4 | 27 | void findBallPosAndDist(char data[]); |
KoiShin_Sakana | 3:901d18b901b4 | 28 | |
KoiShin_Sakana | 3:901d18b901b4 | 29 | private: |
KoiShin_Sakana | 3:901d18b901b4 | 30 | AnalogIn analogFront; |
KoiShin_Sakana | 3:901d18b901b4 | 31 | AnalogIn analogFrontLeft; |
KoiShin_Sakana | 3:901d18b901b4 | 32 | AnalogIn analogLeft; |
KoiShin_Sakana | 3:901d18b901b4 | 33 | AnalogIn analogBackLeft; |
KoiShin_Sakana | 3:901d18b901b4 | 34 | AnalogIn analogBack; |
KoiShin_Sakana | 3:901d18b901b4 | 35 | AnalogIn analogBackRight; |
KoiShin_Sakana | 3:901d18b901b4 | 36 | AnalogIn analogRight; |
KoiShin_Sakana | 3:901d18b901b4 | 37 | AnalogIn analogFrontRight; |
KoiShin_Sakana | 2:a8bbf677e774 | 38 | }; |
KoiShin_Sakana | 2:a8bbf677e774 | 39 | |
KoiShin_Sakana | 5:e07e380ddb93 | 40 | // initialize |
KoiShin_Sakana | 3:901d18b901b4 | 41 | Infrared::Infrared(PinName front, PinName frontLeft, PinName left, PinName backLeft, |
KoiShin_Sakana | 3:901d18b901b4 | 42 | PinName back, PinName backRight, PinName right, PinName frontRight): |
KoiShin_Sakana | 3:901d18b901b4 | 43 | infraredData(front, frontLeft, left, backLeft, back, backRight, right, frontRight) { |
KoiShin_Sakana | 3:901d18b901b4 | 44 | } |
KoiShin_Sakana | 3:901d18b901b4 | 45 | |
KoiShin_Sakana | 5:e07e380ddb93 | 46 | // return ball position |
KoiShin_Sakana | 3:901d18b901b4 | 47 | char Infrared::findBallPos(void) { |
KoiShin_Sakana | 3:901d18b901b4 | 48 | char data = infraredData; |
KoiShin_Sakana | 3:901d18b901b4 | 49 | return data; |
KoiShin_Sakana | 3:901d18b901b4 | 50 | } |
KoiShin_Sakana | 3:901d18b901b4 | 51 | |
KoiShin_Sakana | 5:e07e380ddb93 | 52 | // initialize |
KoiShin_Sakana | 3:901d18b901b4 | 53 | AnalogInfrared::AnalogInfrared(PinName front, PinName frontLeft, PinName left, PinName backLeft, |
KoiShin_Sakana | 3:901d18b901b4 | 54 | PinName back, PinName backRight, PinName right, PinName frontRight): |
KoiShin_Sakana | 3:901d18b901b4 | 55 | analogFront(front), analogFrontLeft(frontLeft), analogLeft(left), analogBackLeft(backLeft), |
KoiShin_Sakana | 3:901d18b901b4 | 56 | analogBack(back), analogBackRight(backRight), analogRight(right), analogFrontRight(frontRight) { |
KoiShin_Sakana | 3:901d18b901b4 | 57 | } |
KoiShin_Sakana | 3:901d18b901b4 | 58 | |
KoiShin_Sakana | 5:e07e380ddb93 | 59 | // return ball position and distance |
KoiShin_Sakana | 3:901d18b901b4 | 60 | void AnalogInfrared::findBallPosAndDist(char data[]) { |
KoiShin_Sakana | 3:901d18b901b4 | 61 | data[0] = analogFront; |
KoiShin_Sakana | 3:901d18b901b4 | 62 | data[1] = analogFrontLeft; |
KoiShin_Sakana | 3:901d18b901b4 | 63 | data[2] = analogLeft; |
KoiShin_Sakana | 3:901d18b901b4 | 64 | data[3] = analogBackLeft; |
KoiShin_Sakana | 3:901d18b901b4 | 65 | data[4] = analogBack; |
KoiShin_Sakana | 3:901d18b901b4 | 66 | data[5] = analogBackRight; |
KoiShin_Sakana | 3:901d18b901b4 | 67 | data[6] = analogRight; |
KoiShin_Sakana | 3:901d18b901b4 | 68 | data[7] = analogFrontRight; |
KoiShin_Sakana | 3:901d18b901b4 | 69 | } |
KoiShin_Sakana | 3:901d18b901b4 | 70 | |
KoiShin_Sakana | 2:a8bbf677e774 | 71 | #endif |
KoiShin_Sakana | 5:e07e380ddb93 | 72 | |
KoiShin_Sakana | 5:e07e380ddb93 | 73 | /** |
KoiShin_Sakana | 5:e07e380ddb93 | 74 | * example program(normal) |
KoiShin_Sakana | 5:e07e380ddb93 | 75 | |
KoiShin_Sakana | 5:e07e380ddb93 | 76 | #include "mbed.h" |
KoiShin_Sakana | 5:e07e380ddb93 | 77 | #include "infrared.h" |
KoiShin_Sakana | 5:e07e380ddb93 | 78 | |
KoiShin_Sakana | 5:e07e380ddb93 | 79 | int main(void) { |
KoiShin_Sakana | 5:e07e380ddb93 | 80 | Infrared infrared(D0, D1, D2, D3, D4, D5, D6, D7); |
KoiShin_Sakana | 5:e07e380ddb93 | 81 | while (1) { |
KoiShin_Sakana | 5:e07e380ddb93 | 82 | char data = infrared.findBallPos(); |
KoiShin_Sakana | 5:e07e380ddb93 | 83 | pc.printf("%d\r\n", data); // for example, display "11000001" |
KoiShin_Sakana | 5:e07e380ddb93 | 84 | } |
KoiShin_Sakana | 5:e07e380ddb93 | 85 | } |
KoiShin_Sakana | 5:e07e380ddb93 | 86 | |
KoiShin_Sakana | 5:e07e380ddb93 | 87 | * example program(analog) |
KoiShin_Sakana | 5:e07e380ddb93 | 88 | |
KoiShin_Sakana | 5:e07e380ddb93 | 89 | #include "mbed.h" |
KoiShin_Sakana | 5:e07e380ddb93 | 90 | #include "infrared.h" |
KoiShin_Sakana | 5:e07e380ddb93 | 91 | |
KoiShin_Sakana | 5:e07e380ddb93 | 92 | int main(void) { |
KoiShin_Sakana | 5:e07e380ddb93 | 93 | int data[8]; |
KoiShin_Sakana | 5:e07e380ddb93 | 94 | AnalogInfrared analogInfrared(D0, D1, D2, D3, D4, D5, D6, D7); |
KoiShin_Sakana | 5:e07e380ddb93 | 95 | while (1) { |
KoiShin_Sakana | 5:e07e380ddb93 | 96 | analogInfrared.findBallPosAndDist(data); |
KoiShin_Sakana | 5:e07e380ddb93 | 97 | for (int i = 0; i < 8; i++) { |
KoiShin_Sakana | 5:e07e380ddb93 | 98 | pc.printf("%f\r\n", data[i]); // for example, display "123, 212, 0, 0, ..." |
KoiShin_Sakana | 5:e07e380ddb93 | 99 | } |
KoiShin_Sakana | 5:e07e380ddb93 | 100 | } |
KoiShin_Sakana | 5:e07e380ddb93 | 101 | } |
KoiShin_Sakana | 5:e07e380ddb93 | 102 | */ |