Example of pedometer for LSM6DSL in X-NUCLEO-IKS01A2
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of Pedometer_IKS01A2 by
Pedometer Demo Application based on sensor expansion board X-NUCLEO-IKS01A2
Main function is to show how to count steps 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 shake the board to simulate the steps and then view the notification using an hyper terminal. When a new step is detected, the LED is switched on for a while.
- the user button can be used to reset the step counter.
Diff: main.cpp
- Revision:
- 7:3c8564ed9986
- Parent:
- 6:153ff83ae370
- Child:
- 8:f81be59738d1
diff -r 153ff83ae370 -r 3c8564ed9986 main.cpp --- a/main.cpp Wed Nov 23 16:45:55 2016 +0000 +++ b/main.cpp Thu Nov 24 16:45:36 2016 +0000 @@ -49,21 +49,21 @@ InterruptIn mybutton(USER_BUTTON); DigitalOut myled(LED1); -volatile int step = 0; +volatile int mems_event = 0; volatile int step_count_reset_request = 0; uint32_t previous_tick = 0; uint32_t current_tick = 0; uint16_t step_count = 0; -void pressed(); -void step_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(&step_cb); + acc_gyro->AttachINT1IRQ(&INT1_cb); /* Enable LSM6DSL accelerometer */ acc_gyro->Enable_X(); @@ -75,8 +75,8 @@ printf("\r\n--- Starting new run ---\r\n"); while(1) { - if (step) { - step = 0; + if (mems_event) { + mems_event = 0; LSM6DSL_Event_Status_t status; acc_gyro->Get_Event_Status(&status); if (status.StepStatus) { @@ -106,10 +106,10 @@ } } -void pressed() { +void pressed_cb() { step_count_reset_request = 1; } -void step_cb() { - step = 1; +void INT1_cb() { + mems_event = 1; }