HOme Sheriff And Lamp
Dependencies: CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed
Fork of HoSAL by
main.cpp@2:3c7526a1893a, 2015-08-11 (annotated)
- Committer:
- uasonice
- Date:
- Tue Aug 11 16:30:37 2015 +0000
- Revision:
- 2:3c7526a1893a
- Parent:
- 0:35211a622a44
- Child:
- 3:8c4e0e7c8cea
update get_distance(); support param instance handle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uasonice | 0:35211a622a44 | 1 | #include "mbed.h" |
uasonice | 0:35211a622a44 | 2 | #include "hcsr04.h" |
uasonice | 0:35211a622a44 | 3 | #include "rev_Hcsr04.h" |
uasonice | 0:35211a622a44 | 4 | |
uasonice | 0:35211a622a44 | 5 | #define DEBUG_TYPE 1 |
uasonice | 0:35211a622a44 | 6 | #define P_ uart.printf |
uasonice | 0:35211a622a44 | 7 | #include "rev_config.h" |
uasonice | 0:35211a622a44 | 8 | |
uasonice | 0:35211a622a44 | 9 | |
uasonice | 0:35211a622a44 | 10 | #define CHECK_DISTANCE 1000 |
uasonice | 0:35211a622a44 | 11 | |
uasonice | 0:35211a622a44 | 12 | #if 0 |
uasonice | 0:35211a622a44 | 13 | int sum_dist[3] = {0,}; //ryuhs74@20150712 - |
uasonice | 0:35211a622a44 | 14 | int avg_dist = 0; //ryuhs74@20150712 - |
uasonice | 0:35211a622a44 | 15 | int index_dist = 0; //ryuhs74@20150712 - |
uasonice | 0:35211a622a44 | 16 | #endif |
uasonice | 0:35211a622a44 | 17 | |
uasonice | 0:35211a622a44 | 18 | Serial uart(USBTX, USBRX); // tx, rx |
uasonice | 0:35211a622a44 | 19 | |
uasonice | 2:3c7526a1893a | 20 | //HCSR04 sensor(D12, D11); |
uasonice | 2:3c7526a1893a | 21 | HCSR04 *g_pHcrs; |
uasonice | 0:35211a622a44 | 22 | |
uasonice | 0:35211a622a44 | 23 | DigitalOut led1(LED1); //server listning status |
uasonice | 0:35211a622a44 | 24 | DigitalOut led2(LED2); //socket connecting status |
uasonice | 0:35211a622a44 | 25 | |
uasonice | 0:35211a622a44 | 26 | ////////////////////////////////////////////////////////////////////////// |
uasonice | 0:35211a622a44 | 27 | Ticker ledTick; |
uasonice | 0:35211a622a44 | 28 | |
uasonice | 0:35211a622a44 | 29 | ////////////////////////////////////////////////////////////////////////// |
uasonice | 0:35211a622a44 | 30 | void ledTickfunc() |
uasonice | 0:35211a622a44 | 31 | { |
uasonice | 0:35211a622a44 | 32 | led1 = !led1; |
uasonice | 0:35211a622a44 | 33 | } |
uasonice | 0:35211a622a44 | 34 | |
uasonice | 0:35211a622a44 | 35 | ////////////////////////////////////////////////////////////////////////// |
uasonice | 0:35211a622a44 | 36 | int main() |
uasonice | 0:35211a622a44 | 37 | { |
uasonice | 0:35211a622a44 | 38 | ledTick.attach(&ledTickfunc,0.5); |
uasonice | 0:35211a622a44 | 39 | |
uasonice | 0:35211a622a44 | 40 | uart.baud(115200); |
uasonice | 2:3c7526a1893a | 41 | DM_fLN("init"); |
uasonice | 0:35211a622a44 | 42 | |
uasonice | 2:3c7526a1893a | 43 | g_pHcrs = new HCSR04(D12, D11); |
uasonice | 0:35211a622a44 | 44 | while(1) { |
uasonice | 2:3c7526a1893a | 45 | get_distance(g_pHcrs); |
uasonice | 0:35211a622a44 | 46 | wait_ms(1000); |
uasonice | 0:35211a622a44 | 47 | } |
uasonice | 0:35211a622a44 | 48 | } |
uasonice | 0:35211a622a44 | 49 | |
uasonice | 0:35211a622a44 | 50 |