Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed C12832 Servo
IR_Dist.h@0:cfa7fee348c5, 2018-11-20 (annotated)
- Committer:
- mazmonem
- Date:
- Tue Nov 20 12:29:44 2018 +0000
- Revision:
- 0:cfa7fee348c5
Pet feeder code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mazmonem | 0:cfa7fee348c5 | 1 | /* File: IR_Dist.h |
| mazmonem | 0:cfa7fee348c5 | 2 | * Author: Geert Huisman |
| mazmonem | 0:cfa7fee348c5 | 3 | * Board: STM NUCLEO F401RE, |
| mazmonem | 0:cfa7fee348c5 | 4 | * Hardware: IR Range GP20A41SK, |
| mazmonem | 0:cfa7fee348c5 | 5 | * |
| mazmonem | 0:cfa7fee348c5 | 6 | * Desc: driver for GP20A41SK IR Distance sensor. The returned range |
| mazmonem | 0:cfa7fee348c5 | 7 | * is in units of cm meters. |
| mazmonem | 0:cfa7fee348c5 | 8 | * |
| mazmonem | 0:cfa7fee348c5 | 9 | * |
| mazmonem | 0:cfa7fee348c5 | 10 | * |
| mazmonem | 0:cfa7fee348c5 | 11 | */ |
| mazmonem | 0:cfa7fee348c5 | 12 | |
| mazmonem | 0:cfa7fee348c5 | 13 | /* EXAMPLE |
| mazmonem | 0:cfa7fee348c5 | 14 | #include "mbed.h" |
| mazmonem | 0:cfa7fee348c5 | 15 | #include "IR_Dist.h" |
| mazmonem | 0:cfa7fee348c5 | 16 | |
| mazmonem | 0:cfa7fee348c5 | 17 | //A0 Analoogin |
| mazmonem | 0:cfa7fee348c5 | 18 | IR_Dist IRSense(A0); |
| mazmonem | 0:cfa7fee348c5 | 19 | int main() { |
| mazmonem | 0:cfa7fee348c5 | 20 | while(1) { |
| mazmonem | 0:cfa7fee348c5 | 21 | |
| mazmonem | 0:cfa7fee348c5 | 22 | float distance = IRSense.distance(); |
| mazmonem | 0:cfa7fee348c5 | 23 | printf("distance %2.0f \n",distance); |
| mazmonem | 0:cfa7fee348c5 | 24 | wait(1.0); |
| mazmonem | 0:cfa7fee348c5 | 25 | |
| mazmonem | 0:cfa7fee348c5 | 26 | } |
| mazmonem | 0:cfa7fee348c5 | 27 | } |
| mazmonem | 0:cfa7fee348c5 | 28 | */ |
| mazmonem | 0:cfa7fee348c5 | 29 | |
| mazmonem | 0:cfa7fee348c5 | 30 | #ifndef IR_Dist_H |
| mazmonem | 0:cfa7fee348c5 | 31 | #define IR_Dist_H |
| mazmonem | 0:cfa7fee348c5 | 32 | #include "mbed.h" |
| mazmonem | 0:cfa7fee348c5 | 33 | |
| mazmonem | 0:cfa7fee348c5 | 34 | class IR_Dist { |
| mazmonem | 0:cfa7fee348c5 | 35 | public: |
| mazmonem | 0:cfa7fee348c5 | 36 | IR_Dist(PinName a); |
| mazmonem | 0:cfa7fee348c5 | 37 | float Equation(); |
| mazmonem | 0:cfa7fee348c5 | 38 | float distance(); |
| mazmonem | 0:cfa7fee348c5 | 39 | |
| mazmonem | 0:cfa7fee348c5 | 40 | private: |
| mazmonem | 0:cfa7fee348c5 | 41 | AnalogIn IRSens; |
| mazmonem | 0:cfa7fee348c5 | 42 | int16_t volts; |
| mazmonem | 0:cfa7fee348c5 | 43 | float som, correction, distance_cm; |
| mazmonem | 0:cfa7fee348c5 | 44 | }; |
| mazmonem | 0:cfa7fee348c5 | 45 | |
| mazmonem | 0:cfa7fee348c5 | 46 | #endif |