![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Image Zoom In/out Sample. This program uses GraphicsFramework library and GP2Y0A21YK sensor. Please use distance sensor in the range of 10-30cm.
Dependencies: GR-PEACH_video GraphicsFramework R_BSP mbed-rtos mbed
Fork of RGA_HelloWorld by
About GP2Y0A21YK
GP2Y0A21YK is a distance sensor and can be controlled by using the AnalogIn.
The range of this sensor is 10-80cm.
- Datasheet of GP2Y0A21YK
https://www.sparkfun.com/datasheets/Components/GP2Y0A21YK.pdf
About wiring
Sensor | GR-PEACH |
White wire | A0 |
Orange wire | GND |
Black wire | 5.0V |
Revision 6:6cad61e4a4c1, committed 2016-05-20
- Comitter:
- 1050186
- Date:
- Fri May 20 02:33:41 2016 +0000
- Parent:
- 5:ac895a9527ab
- Commit message:
- Modify main.cpp
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ac895a9527ab -r 6cad61e4a4c1 main.cpp --- a/main.cpp Fri May 13 07:10:27 2016 +0000 +++ b/main.cpp Fri May 20 02:33:41 2016 +0000 @@ -55,18 +55,18 @@ } static float get_distance(void) { - float tmp[10]; + float tmp = 0; float data = 0; float distance = 0; int cnt; for (cnt = 0; cnt < 10; cnt++) { - tmp[cnt] = ain; - if (tmp[cnt] == 0) { + if (ain == 0) { return 0; } + tmp = tmp + ain; } - data = (tmp[0]+tmp[1]+tmp[2]+tmp[3]+tmp[4]+tmp[5]+tmp[6]+tmp[7]+tmp[8]+tmp[9]) / 10; + data = tmp / 10; if ((data >= 0.121) && (data <= 0.970)) { distance = 26.663 * pow((data * 3.3), -1.25); }