Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of Pedometer_IKS01A2 by
main.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file main.cpp 00004 * @author CLab 00005 * @version V1.0.0 00006 * @date 2-December-2016 00007 * @brief Simple Example application for using the X_NUCLEO_IKS01A2 00008 * MEMS Inertial & Environmental Sensor Nucleo expansion board. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Includes */ 00040 #include "mbed.h" 00041 #include "XNucleoIKS01A2.h" 00042 00043 /* Instantiate the expansion board */ 00044 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); 00045 00046 /* Retrieve the composing elements of the expansion board */ 00047 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; 00048 00049 InterruptIn mybutton(USER_BUTTON); 00050 DigitalOut myled(LED1); 00051 00052 volatile int mems_event = 0; 00053 volatile int step_count_reset_request = 0; 00054 uint32_t previous_tick = 0; 00055 uint32_t current_tick = 0; 00056 uint16_t step_count = 0; 00057 00058 /* User button callback. */ 00059 void pressed_cb() { 00060 step_count_reset_request = 1; 00061 } 00062 00063 /* Interrupt 1 callback. */ 00064 void int1_cb() { 00065 mems_event = 1; 00066 } 00067 00068 /* Simple main function */ 00069 int main() { 00070 /* Attach callback to User button press */ 00071 mybutton.fall(&pressed_cb); 00072 /* Attach callback to LSM6DSL INT1 */ 00073 acc_gyro->attach_int1_irq(&int1_cb); 00074 00075 /* Enable LSM6DSL accelerometer */ 00076 acc_gyro->enable_x(); 00077 /* Enable Pedometer. */ 00078 acc_gyro->enable_pedometer(); 00079 00080 previous_tick = clock(); 00081 00082 printf("\r\n--- Starting new run ---\r\n"); 00083 00084 while(1) { 00085 if (mems_event) { 00086 mems_event = 0; 00087 LSM6DSL_Event_Status_t status; 00088 acc_gyro->get_event_status(&status); 00089 if (status.StepStatus) { 00090 /* New step detected, so print the step counter */ 00091 acc_gyro->get_step_counter(&step_count); 00092 printf("Step counter: %d\r\n", step_count); 00093 00094 /* Led blinking. */ 00095 myled = 1; 00096 wait(0.1); 00097 myled = 0; 00098 } 00099 } 00100 00101 if(step_count_reset_request) { 00102 step_count_reset_request = 0; 00103 acc_gyro->reset_step_counter(); 00104 } 00105 00106 /* Print the step counter in any case every 3s */ 00107 current_tick = clock(); 00108 if(((current_tick - previous_tick)/CLOCKS_PER_SEC) >= 3) { 00109 acc_gyro->get_step_counter(&step_count); 00110 printf("Step counter: %d\r\n", step_count); 00111 previous_tick = clock(); 00112 } 00113 } 00114 }
Generated on Wed Jul 13 2022 20:21:18 by
1.7.2
