PAW_Sensor: This library control the PAW sensor. This library get sensor values from the PAW sensor, and send these values to PC through serial-communication. And you need to convert these values to delta h using some module on PC. I create sample python module for this library. If you want to get this module, please access below page, https://github.com/HiroakiMatsuda/PAW-Sensor The PAW Sensor is developed by RT. If you need to get information about this sensors, please access below page. http://www.rt-shop.jp/index.php?main_page=product_info&cPath=42&products_id=1303

Dependents:   PAW_Sensor_HelloWorld

Committer:
matsu
Date:
Sun Nov 09 11:43:48 2014 +0000
Revision:
5:eae61a2a67b0
Parent:
4:ea00b3135f6e
Child:
6:a58ad4e085af
Fix example code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matsu 0:ebd7c54059ae 1 #ifndef PAW_H
matsu 0:ebd7c54059ae 2 #define PAW_H
matsu 0:ebd7c54059ae 3
matsu 0:ebd7c54059ae 4 #include "mbed.h"
matsu 0:ebd7c54059ae 5
matsu 0:ebd7c54059ae 6 #define STATE_1 0
matsu 0:ebd7c54059ae 7 #define STATE_2 1
matsu 0:ebd7c54059ae 8 #define STATE_3 2
matsu 0:ebd7c54059ae 9 #define STATE_4 3
matsu 0:ebd7c54059ae 10
matsu 2:6a493f73860c 11 struct paw_value
matsu 2:6a493f73860c 12 {
matsu 2:6a493f73860c 13 public:
matsu 2:6a493f73860c 14 short ch_1;
matsu 2:6a493f73860c 15 short ch_2;
matsu 2:6a493f73860c 16 short ch_3;
matsu 2:6a493f73860c 17 short ch_4;
matsu 2:6a493f73860c 18 short initial_photo_1;
matsu 2:6a493f73860c 19 short initial_photo_2;
matsu 2:6a493f73860c 20
matsu 2:6a493f73860c 21 paw_value()
matsu 2:6a493f73860c 22 {
matsu 2:6a493f73860c 23 ch_1 = 0;
matsu 2:6a493f73860c 24 ch_2 = 0;
matsu 2:6a493f73860c 25 ch_3 = 0;
matsu 2:6a493f73860c 26 ch_4 = 0;
matsu 2:6a493f73860c 27 initial_photo_1 = 0;
matsu 2:6a493f73860c 28 initial_photo_2 = 0;
matsu 2:6a493f73860c 29 }
matsu 2:6a493f73860c 30 };
matsu 0:ebd7c54059ae 31
matsu 0:ebd7c54059ae 32 /** PAW_Sensor Library
matsu 0:ebd7c54059ae 33 *
matsu 0:ebd7c54059ae 34 * Example:
matsu 0:ebd7c54059ae 35 * @code
matsu 0:ebd7c54059ae 36 *
matsu 0:ebd7c54059ae 37 #include "mbed.h"
matsu 0:ebd7c54059ae 38 #include "paw.h"
matsu 0:ebd7c54059ae 39
matsu 0:ebd7c54059ae 40 Serial pc( USBTX, USBRX );
matsu 0:ebd7c54059ae 41 const unsigned long baudrate = 115200;
matsu 0:ebd7c54059ae 42
matsu 0:ebd7c54059ae 43 // paw( LED1, LED2, PHOTO1, PHOTO2 )
matsu 0:ebd7c54059ae 44 PAW paw( p8, p9, p16, p17 );
matsu 0:ebd7c54059ae 45 paw_value g_value;
matsu 0:ebd7c54059ae 46
matsu 0:ebd7c54059ae 47 PAW paw_2( p10, p11, p18, p19 );
matsu 0:ebd7c54059ae 48 paw_value g_value_2;
matsu 0:ebd7c54059ae 49
matsu 0:ebd7c54059ae 50 Ticker run;
matsu 0:ebd7c54059ae 51
matsu 0:ebd7c54059ae 52
matsu 0:ebd7c54059ae 53 void run_paw_sensor()
matsu 0:ebd7c54059ae 54 {
matsu 0:ebd7c54059ae 55 if( paw.process_paw() == STATE_1 )
matsu 0:ebd7c54059ae 56 {
matsu 5:eae61a2a67b0 57 paw.print( &pc, 0 );
matsu 0:ebd7c54059ae 58 }
matsu 0:ebd7c54059ae 59 }
matsu 0:ebd7c54059ae 60
matsu 0:ebd7c54059ae 61 int main()
matsu 0:ebd7c54059ae 62 {
matsu 0:ebd7c54059ae 63 // Initializing Serial Communication
matsu 0:ebd7c54059ae 64 pc.baud( baudrate );
matsu 0:ebd7c54059ae 65 pc.format( 8, Serial::None, 1 );
matsu 0:ebd7c54059ae 66
matsu 0:ebd7c54059ae 67 run.attach_us(&run_paw_sensor, 500);
matsu 0:ebd7c54059ae 68
matsu 0:ebd7c54059ae 69 while(1);
matsu 0:ebd7c54059ae 70 }
matsu 0:ebd7c54059ae 71
matsu 0:ebd7c54059ae 72 * @endcode
matsu 0:ebd7c54059ae 73 */
matsu 0:ebd7c54059ae 74
matsu 0:ebd7c54059ae 75 class PAW {
matsu 0:ebd7c54059ae 76
matsu 0:ebd7c54059ae 77 public:
matsu 0:ebd7c54059ae 78
matsu 0:ebd7c54059ae 79 /** Create a PAW Sensor instance
matsu 0:ebd7c54059ae 80 *
matsu 0:ebd7c54059ae 81 * @param led_1 PAW Sensor's Pin 5
matsu 0:ebd7c54059ae 82 * @param led_2 PAW Sensor's Pin 4
matsu 0:ebd7c54059ae 83 * @param photo_1 PAW Sensor's Pin 3
matsu 0:ebd7c54059ae 84 * @param photo_2 PAW Sensor's Pin 2
matsu 0:ebd7c54059ae 85 */
matsu 0:ebd7c54059ae 86 PAW( PinName led_1, PinName led_2, PinName photo_1, PinName photo_2 );
matsu 0:ebd7c54059ae 87
matsu 0:ebd7c54059ae 88 /** Get values of PAW Sensor
matsu 0:ebd7c54059ae 89 *
matsu 0:ebd7c54059ae 90 * @return Return values of photosensor's voltage.
matsu 0:ebd7c54059ae 91 */
matsu 0:ebd7c54059ae 92 paw_value get_value();
matsu 0:ebd7c54059ae 93
matsu 0:ebd7c54059ae 94 /** Processing of Paw sensor. This fucntion must be performed periodically.
matsu 0:ebd7c54059ae 95 *
matsu 0:ebd7c54059ae 96 * @return Return current processing-state.
matsu 0:ebd7c54059ae 97 */
matsu 0:ebd7c54059ae 98 unsigned char process_paw();
matsu 0:ebd7c54059ae 99
matsu 0:ebd7c54059ae 100 /** Get current processing-state.
matsu 0:ebd7c54059ae 101 *
matsu 0:ebd7c54059ae 102 * @return Return current processing-state.
matsu 0:ebd7c54059ae 103 */
matsu 0:ebd7c54059ae 104 bool get_state();
matsu 0:ebd7c54059ae 105
matsu 0:ebd7c54059ae 106 /** Send values of PAW Sensor through serial-communication.
matsu 0:ebd7c54059ae 107 *
matsu 0:ebd7c54059ae 108 * @param Reference to serial object.
matsu 4:ea00b3135f6e 109 * @param ID of PAW Sensor. you can chose number from 0 to 255.
matsu 0:ebd7c54059ae 110 */
matsu 3:dfebf4e43c63 111 void print( Serial* pc, unsigned char id );
matsu 0:ebd7c54059ae 112
matsu 0:ebd7c54059ae 113 protected:
matsu 0:ebd7c54059ae 114 DigitalOut _led_1;
matsu 0:ebd7c54059ae 115 DigitalOut _led_2;
matsu 0:ebd7c54059ae 116 AnalogIn _photo_1;
matsu 0:ebd7c54059ae 117 AnalogIn _photo_2;
matsu 0:ebd7c54059ae 118
matsu 0:ebd7c54059ae 119 unsigned char _state;
matsu 0:ebd7c54059ae 120
matsu 0:ebd7c54059ae 121 paw_value _value;
matsu 0:ebd7c54059ae 122 };
matsu 0:ebd7c54059ae 123
matsu 0:ebd7c54059ae 124 #endif /*** PAW_H ***/