Servo Motor demo for PoliMI.
Dependencies: X_NUCLEO_IKS01A1 mbed
Revision 0:7766b7bed319, committed 2016-03-16
- Comitter:
- daz
- Date:
- Wed Mar 16 16:41:53 2016 +0000
- Commit message:
- Servo motor demo. Uses X-NUCLEO-IKS01A1 Expansion Board to drive a Servo Motor with speed control
Changed in this revision
diff -r 000000000000 -r 7766b7bed319 X_NUCLEO_IKS01A1.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_IKS01A1.lib Wed Mar 16 16:41:53 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A1/#a91987e8cf51
diff -r 000000000000 -r 7766b7bed319 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 16 16:41:53 2016 +0000 @@ -0,0 +1,33 @@ +#include "mbed.h" +#include "x_nucleo_iks01a1.h" + +#define SERVO_IDLE (0.00153) + +static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15); +static MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer(); +PwmOut servo(D3); + +int main(int argc, char** argv) +{ + int32_t axes[3]; + float pwmWidth; + + /* Initialize PWM to 50Hz*/ + servo.period(0.020); + servo.pulsewidth(SERVO_IDLE); + + while(1){ + /* SENSE accelerometer X axis */ + accelerometer->Get_X_Axes(axes); + + /* COMPUTE PWM width */ + pwmWidth = SERVO_IDLE + axes[0] * 1e-7; + + /* ACTUATE Servo Motor according to accelerometer value */ + servo.pulsewidth(pwmWidth); + + /* Wait 50ms */ + wait(0.05); + } +} +
diff -r 000000000000 -r 7766b7bed319 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 16 16:41:53 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file