Example of free fall detection for LSM6DSL in X-NUCLEO-IKS01A2
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of FreeFall_IKS01A2 by
Free Fall Detection Demo Application based on sensor expansion board X-NUCLEO-IKS01A2
Main function is to show how to detect the free fall event using the sensor expansion board and send a notification using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.
After connection has been established:
- the user can try to leave falling the board and then view the notification using an hyper terminal. When the free fall is detected, the LED is switched on for a while.
- the user button can be used to enable/disable the free fall detection feature.
Diff: main.cpp
- Revision:
- 7:8d01cc2032b8
- Parent:
- 6:f9bbe6142ac5
- Child:
- 8:b460ca90deb9
--- a/main.cpp Wed Nov 23 16:45:16 2016 +0000 +++ b/main.cpp Thu Nov 24 16:44:39 2016 +0000 @@ -49,19 +49,19 @@ InterruptIn mybutton(USER_BUTTON); DigitalOut myled(LED1); -volatile int free_fall = 0; +volatile int mems_event = 0; volatile int toggle_free_fall_enable = 0; static int free_fall_is_enabled = 1; -void pressed(); -void freefall(); +void pressed_cb(); +void INT1_cb(); /* Simple main function */ int main() { /* Attach callback to User button press */ - mybutton.fall(&pressed); + mybutton.fall(&pressed_cb); /* Attach callback to LSM6DSL INT1 */ - acc_gyro->AttachINT1IRQ(&freefall); + acc_gyro->AttachINT1IRQ(&INT1_cb); /* Enable LSM6DSL accelerometer */ acc_gyro->Enable_X(); @@ -82,8 +82,8 @@ } } - if (free_fall) { - free_fall = 0; + if (mems_event) { + mems_event = 0; LSM6DSL_Event_Status_t status; acc_gyro->Get_Event_Status(&status); if (status.FreeFallStatus) { @@ -99,10 +99,10 @@ } } -void pressed() { +void pressed_cb() { toggle_free_fall_enable = 1; } -void freefall() { - free_fall = 1; +void INT1_cb() { + mems_event = 1; }