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_IKS01A1 mbed
main.cpp
00001 #include "mbed.h" 00002 #include "x_nucleo_iks01a1.h" 00003 00004 #define SERVO_IDLE (0.00153) 00005 00006 static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15); 00007 static MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer(); 00008 PwmOut servo(D3); 00009 00010 int main(int argc, char** argv) 00011 { 00012 int32_t axes[3]; 00013 float pwmWidth; 00014 00015 /* Initialize PWM to 50Hz*/ 00016 servo.period(0.020); 00017 servo.pulsewidth(SERVO_IDLE); 00018 00019 while(1){ 00020 /* SENSE accelerometer X axis */ 00021 accelerometer->Get_X_Axes(axes); 00022 00023 /* COMPUTE PWM width */ 00024 pwmWidth = SERVO_IDLE + axes[0] * 1e-7; 00025 00026 /* ACTUATE Servo Motor according to accelerometer value */ 00027 servo.pulsewidth(pwmWidth); 00028 00029 /* Wait 50ms */ 00030 wait(0.05); 00031 } 00032 } 00033
Generated on Thu Jul 14 2022 08:43:41 by
1.7.2