Example of tilt detection for LSM6DSL in X-NUCLEO-IKS01A2
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of Tilt_IKS01A2 by
Tilt Detection Demo Application based on sensor expansion board X-NUCLEO-IKS01A2
Main function is to show how to detect the tilt 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 tilt the board and then view the notification using an hyper terminal. When the tilt event is detected, the LED is switched on for a while.
- the user button can be used to enable/disable the tilt detection feature.
Diff: main.cpp
- Revision:
- 7:369954b853d4
- Parent:
- 6:54b10a8fb90f
- Child:
- 8:a7c8d10449a3
--- a/main.cpp Wed Nov 23 16:46:31 2016 +0000 +++ b/main.cpp Thu Nov 24 16:46:13 2016 +0000 @@ -49,19 +49,19 @@ InterruptIn mybutton(USER_BUTTON); DigitalOut myled(LED1); -volatile int tilt = 0; +volatile int mems_event = 0; volatile int toggle_tilt_enable = 0; static int tilt_is_enabled = 1; -void pressed(); -void tilt_cb(); +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(&tilt_cb); + acc_gyro->AttachINT1IRQ(&INT1_cb); /* Enable LSM6DSL accelerometer */ acc_gyro->Enable_X(); @@ -82,8 +82,8 @@ } } - if (tilt) { - tilt = 0; + if (mems_event) { + mems_event = 0; LSM6DSL_Event_Status_t status; acc_gyro->Get_Event_Status(&status); if (status.TiltStatus) { @@ -99,10 +99,10 @@ } } -void pressed() { +void pressed_cb() { toggle_tilt_enable = 1; } -void tilt_cb() { - tilt = 1; +void INT1_cb() { + mems_event = 1; }