Example program for library X-NUCLEO-IHM12A1 using two low voltage dual brush DC motors

Dependencies:   X_NUCLEO_IHM12A1 mbed

Fork of HelloWorld_IHM12A1 by ST Expansion SW Team

This application provides a simple example of usage of the X-NUCLEO-IHM12A1 Dual Brush DC Motor Control Expansion Board.

It shows how to use 2 bidirectional brush DC motors connected to the board by executing a 13 steps loop:

  • Step 0) Motor 0 runs in forward at 100% of max speed, Motor 1 is inactive
  • Step 1) Motor 0 runs in forward at 75% of max speed, Motor 1 runs in backward at 100% of max speed
  • Step 2) Motor 0 runs in forward at 50% of max speed, Motor 1 runs in backward at 75% of max speed
  • Step 3) Motor 0 runs in forward at 25% of max speed, Motor 1 runs in backward at 50% of max speed
  • Step 4) Motor 0 is stopped, Motor 1 runs in backward at 25% of max speed
  • Step 5) Motor 0 runs in backward at 25% of max speed, Motor 1 is stopped
  • Step 6) Motor 0 runs in backward at 50% of max speed, Motor 1 runs in forward at 25% of max speed
  • Step 7) Motor 0 runs in backward at 75% of max speed, Motor 1 runs in forward at 50% of max speed
  • Step 8) Motor 0 runs in backward at 100% of max speed, Motor 1 runs in forward at 75% of max speed
  • Step 9) Motor 0 runs in backward at 100% of max speed, Motor 1 runs in forward at 100% of max speed
  • Step 10) Stop both motors and disable bridges
  • Step 11) Motor 0 runs in forward at 100% of max speed, Motor 1 runs in forward at 100% of max speed
  • Step 12) Stop both motors and enter standby mode

For the hardware configuration of the expansion board, please refer to the X_NUCLEO_IHM12A1 library web page.

Committer:
Davidroid
Date:
Thu Aug 09 15:01:16 2018 +0000
Revision:
9:371f9bb009e0
Parent:
8:7dccd03ea2bc
Update with the new version of the motor library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Manu_L 0:773e2a2be16f 1 /**
Manu_L 0:773e2a2be16f 2 ******************************************************************************
Manu_L 0:773e2a2be16f 3 * @file main.cpp
Manu_L 0:773e2a2be16f 4 * @author IPC Rennes
Manu_L 0:773e2a2be16f 5 * @version V1.0.0
Manu_L 0:773e2a2be16f 6 * @date April 25th, 2016
Manu_L 0:773e2a2be16f 7 * @brief mbed simple application for the STMicroelectronics X-NUCLEO-IHM12A1
Manu_L 0:773e2a2be16f 8 * Motor Control Expansion Board: control of 2 Brush DC motors.
Manu_L 0:773e2a2be16f 9 ******************************************************************************
Manu_L 0:773e2a2be16f 10 * @attention
Manu_L 0:773e2a2be16f 11 *
Manu_L 0:773e2a2be16f 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
Manu_L 0:773e2a2be16f 13 *
Manu_L 0:773e2a2be16f 14 * Redistribution and use in source and binary forms, with or without modification,
Manu_L 0:773e2a2be16f 15 * are permitted provided that the following conditions are met:
Manu_L 0:773e2a2be16f 16 * 1. Redistributions of source code must retain the above copyright notice,
Manu_L 0:773e2a2be16f 17 * this list of conditions and the following disclaimer.
Manu_L 0:773e2a2be16f 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Manu_L 0:773e2a2be16f 19 * this list of conditions and the following disclaimer in the documentation
Manu_L 0:773e2a2be16f 20 * and/or other materials provided with the distribution.
Manu_L 0:773e2a2be16f 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Manu_L 0:773e2a2be16f 22 * may be used to endorse or promote products derived from this software
Manu_L 0:773e2a2be16f 23 * without specific prior written permission.
Manu_L 0:773e2a2be16f 24 *
Manu_L 0:773e2a2be16f 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Manu_L 0:773e2a2be16f 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Manu_L 0:773e2a2be16f 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Manu_L 0:773e2a2be16f 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Manu_L 0:773e2a2be16f 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Manu_L 0:773e2a2be16f 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Manu_L 0:773e2a2be16f 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Manu_L 0:773e2a2be16f 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Manu_L 0:773e2a2be16f 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Manu_L 0:773e2a2be16f 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Manu_L 0:773e2a2be16f 35 *
Manu_L 0:773e2a2be16f 36 ******************************************************************************
Manu_L 0:773e2a2be16f 37 */
Manu_L 0:773e2a2be16f 38
Manu_L 0:773e2a2be16f 39 /* Includes ------------------------------------------------------------------*/
Manu_L 0:773e2a2be16f 40
Manu_L 0:773e2a2be16f 41 /* mbed specific header files. */
Manu_L 0:773e2a2be16f 42 #include "mbed.h"
Manu_L 0:773e2a2be16f 43
Manu_L 0:773e2a2be16f 44 /* Component specific header files. */
davide.aliprandi@st.com 5:7517162fb2b9 45 #include "STSpin240_250.h"
Manu_L 0:773e2a2be16f 46
Manu_L 0:773e2a2be16f 47 /* Variables -----------------------------------------------------------------*/
Manu_L 0:773e2a2be16f 48
Manu_L 0:773e2a2be16f 49 /* Initialization parameters of the motor connected to the expansion board. */
Davidroid 6:bd2fa888c101 50 STSpin240_250_init_t init =
Manu_L 0:773e2a2be16f 51 {
Manu_L 0:773e2a2be16f 52 20000, /* Frequency of PWM of Input Bridge A in Hz up to 100000Hz */
Manu_L 0:773e2a2be16f 53 20000, /* Frequency of PWM of Input Bridge B in Hz up to 100000Hz */
Manu_L 0:773e2a2be16f 54 20000, /* Frequency of PWM used for Ref pin in Hz up to 100000Hz */
Manu_L 0:773e2a2be16f 55 50, /* Duty cycle of PWM used for Ref pin (from 0 to 100) */
Manu_L 0:773e2a2be16f 56 TRUE /* Dual Bridge configuration (FALSE for mono, TRUE for dual brush dc) */
Manu_L 0:773e2a2be16f 57 };
Manu_L 0:773e2a2be16f 58
Manu_L 0:773e2a2be16f 59 /* Motor Control Component. */
Davidroid 6:bd2fa888c101 60 STSpin240_250 *motor;
Manu_L 0:773e2a2be16f 61
Manu_L 0:773e2a2be16f 62 /* Functions -----------------------------------------------------------------*/
Manu_L 0:773e2a2be16f 63
Manu_L 0:773e2a2be16f 64 /**
Manu_L 0:773e2a2be16f 65 * @brief This is an example of error handler.
Manu_L 0:773e2a2be16f 66 * @param[in] error Number of the error
Manu_L 0:773e2a2be16f 67 * @retval None
Manu_L 0:773e2a2be16f 68 * @note If needed, implement it, and then attach it:
davide.aliprandi@st.com 5:7517162fb2b9 69 * + motor->attach_error_handler(&my_error_handler);
Manu_L 0:773e2a2be16f 70 */
davide.aliprandi@st.com 5:7517162fb2b9 71 void my_error_handler(uint16_t error)
Manu_L 0:773e2a2be16f 72 {
Manu_L 0:773e2a2be16f 73 /* Printing to the console. */
Manu_L 0:773e2a2be16f 74 printf("Error %d detected\r\n\n", error);
Manu_L 0:773e2a2be16f 75
Manu_L 0:773e2a2be16f 76 /* Infinite loop */
davide.aliprandi@st.com 5:7517162fb2b9 77 while (true) {
Manu_L 0:773e2a2be16f 78 }
Manu_L 0:773e2a2be16f 79 }
Manu_L 0:773e2a2be16f 80
Manu_L 0:773e2a2be16f 81 /**
Manu_L 0:773e2a2be16f 82 * @brief This is an example of user handler for the flag interrupt.
Manu_L 0:773e2a2be16f 83 * @param None
Manu_L 0:773e2a2be16f 84 * @retval None
Manu_L 0:773e2a2be16f 85 * @note If needed, implement it, and then attach and enable it:
davide.aliprandi@st.com 5:7517162fb2b9 86 * + motor->attach_flag_irq(&my_flag_irq_handler);
davide.aliprandi@st.com 5:7517162fb2b9 87 * + motor->enable_flag_irq();
Manu_L 0:773e2a2be16f 88 * To disable it:
Manu_L 0:773e2a2be16f 89 * + motor->DisbleFlagIRQ();
Manu_L 0:773e2a2be16f 90 */
davide.aliprandi@st.com 5:7517162fb2b9 91 void my_flag_irq_handler(void)
Manu_L 0:773e2a2be16f 92 {
Manu_L 0:773e2a2be16f 93 /* Code to be customised */
Manu_L 0:773e2a2be16f 94 /************************/
Manu_L 0:773e2a2be16f 95
Manu_L 0:773e2a2be16f 96 printf(" WARNING: \"FLAG\" interrupt triggered.\r\n");
Manu_L 0:773e2a2be16f 97
Manu_L 0:773e2a2be16f 98 /* Get the state of bridge A */
davide.aliprandi@st.com 5:7517162fb2b9 99 uint16_t bridgeState = motor->get_bridge_status(0);
Manu_L 0:773e2a2be16f 100
davide.aliprandi@st.com 5:7517162fb2b9 101 if (bridgeState == 0) {
davide.aliprandi@st.com 5:7517162fb2b9 102 if (motor->get_device_state(0) != INACTIVE) {
Manu_L 0:773e2a2be16f 103 /* Bridges were disabled due to overcurrent or over temperature */
Manu_L 0:773e2a2be16f 104 /* When motor was running */
davide.aliprandi@st.com 5:7517162fb2b9 105 my_error_handler(0XBAD0);
Manu_L 0:773e2a2be16f 106 }
Manu_L 0:773e2a2be16f 107 }
Manu_L 0:773e2a2be16f 108 }
Manu_L 0:773e2a2be16f 109
Manu_L 0:773e2a2be16f 110 /* Main ----------------------------------------------------------------------*/
Manu_L 0:773e2a2be16f 111
Manu_L 0:773e2a2be16f 112 int main()
Manu_L 0:773e2a2be16f 113 {
Manu_L 0:773e2a2be16f 114 uint8_t demoStep = 0;
Manu_L 0:773e2a2be16f 115
Manu_L 0:773e2a2be16f 116 /* Printing to the console. */
Manu_L 0:773e2a2be16f 117 printf("STARTING MAIN PROGRAM\r\n");
Manu_L 0:773e2a2be16f 118
Manu_L 0:773e2a2be16f 119 //----- Initialization
Manu_L 0:773e2a2be16f 120
Manu_L 0:773e2a2be16f 121 /* Initializing Motor Control Component. */
Manu_L 0:773e2a2be16f 122 #if (defined TARGET_NUCLEO_F030R8)||(defined TARGET_NUCLEO_F334R8)
Davidroid 6:bd2fa888c101 123 motor = new STSpin240_250(D2, D9, D6, D7, D5, D4, A2);
Manu_L 0:773e2a2be16f 124 #elif (defined TARGET_NUCLEO_L152RE)
Davidroid 6:bd2fa888c101 125 motor = new STSpin240_250(D2, D9, D6, D7, D5, D4, A3);
Davidroid 8:7dccd03ea2bc 126 #elif (defined TARGET_NUCLEO_F429ZI)
Davidroid 8:7dccd03ea2bc 127 motor = new STSpin240_250(D2, D9, D6, D7, D5, D3, A0);
Manu_L 0:773e2a2be16f 128 #else
Davidroid 6:bd2fa888c101 129 motor = new STSpin240_250(D2, D9, D6, D7, D5, D4, A0);
Manu_L 0:773e2a2be16f 130 #endif
davide.aliprandi@st.com 5:7517162fb2b9 131 if (motor->init(&init) != COMPONENT_OK) exit(EXIT_FAILURE);
Manu_L 0:773e2a2be16f 132
Manu_L 0:773e2a2be16f 133 /* Set dual bridge enabled as two motors are used*/
davide.aliprandi@st.com 5:7517162fb2b9 134 motor->set_dual_full_bridge_config(1);
Manu_L 0:773e2a2be16f 135
Manu_L 0:773e2a2be16f 136 /* Attaching and enabling an interrupt handler. */
davide.aliprandi@st.com 5:7517162fb2b9 137 motor->attach_flag_irq(&my_flag_irq_handler);
davide.aliprandi@st.com 5:7517162fb2b9 138 motor->enable_flag_irq();
Manu_L 0:773e2a2be16f 139
Manu_L 0:773e2a2be16f 140 /* Attaching an error handler */
davide.aliprandi@st.com 5:7517162fb2b9 141 motor->attach_error_handler(&my_error_handler);
Manu_L 0:773e2a2be16f 142
Manu_L 0:773e2a2be16f 143 /* Printing to the console. */
Manu_L 0:773e2a2be16f 144 printf("Motor Control Application Example for 2 brush DC motors\r\n");
Manu_L 0:773e2a2be16f 145
Manu_L 0:773e2a2be16f 146 /* Set PWM Frequency of Ref to 15000 Hz */
davide.aliprandi@st.com 5:7517162fb2b9 147 motor->set_ref_pwm_freq(0, 15000);
Manu_L 0:773e2a2be16f 148
Manu_L 0:773e2a2be16f 149 /* Set PWM duty cycle of Ref to 60% */
davide.aliprandi@st.com 5:7517162fb2b9 150 motor->set_ref_pwm_dc(0, 60);
Manu_L 0:773e2a2be16f 151
Manu_L 0:773e2a2be16f 152 /* Set PWM Frequency of bridge A inputs to 10000 Hz */
davide.aliprandi@st.com 5:7517162fb2b9 153 motor->set_bridge_input_pwm_freq(0,10000);
Manu_L 0:773e2a2be16f 154
Manu_L 0:773e2a2be16f 155 /* Set PWM Frequency of bridge B inputs to 10000 Hz */
davide.aliprandi@st.com 5:7517162fb2b9 156 motor->set_bridge_input_pwm_freq(1,10000);
Manu_L 0:773e2a2be16f 157
Manu_L 0:773e2a2be16f 158 /* Infinite Loop. */
Manu_L 0:773e2a2be16f 159 printf("--> Infinite Loop...\r\n");
davide.aliprandi@st.com 5:7517162fb2b9 160 while (true) {
davide.aliprandi@st.com 5:7517162fb2b9 161 switch (demoStep) {
davide.aliprandi@st.com 5:7517162fb2b9 162 case 0: {
Manu_L 0:773e2a2be16f 163 printf("STEP 0: Motor(0) FWD Speed=100%% - Motor(1) Inactive\r\n");
Manu_L 0:773e2a2be16f 164 /* Set speed of motor 0 to 100 % */
davide.aliprandi@st.com 5:7517162fb2b9 165 motor->set_speed(0,100);
Manu_L 0:773e2a2be16f 166 /* start motor 0 to run forward*/
Manu_L 0:773e2a2be16f 167 /* if chip is in standby mode */
Manu_L 0:773e2a2be16f 168 /* it is automatically awakened */
davide.aliprandi@st.com 5:7517162fb2b9 169 motor->run(0, BDCMotor::FWD);
Manu_L 0:773e2a2be16f 170 break;
davide.aliprandi@st.com 5:7517162fb2b9 171 }
davide.aliprandi@st.com 5:7517162fb2b9 172 case 1: {
Manu_L 0:773e2a2be16f 173 printf("STEP 1: Motor(0) FWD Speed=75%% - Motor(1) BWD Speed=100%%\r\n");
Manu_L 0:773e2a2be16f 174 /* Set speed of motor 0 to 75 % */
davide.aliprandi@st.com 5:7517162fb2b9 175 motor->set_speed(0,75);
Manu_L 0:773e2a2be16f 176 /* Set speed of motor 1 to 100 % */
davide.aliprandi@st.com 5:7517162fb2b9 177 motor->set_speed(1,100);
Manu_L 0:773e2a2be16f 178 /* start motor 1 to run backward */
davide.aliprandi@st.com 5:7517162fb2b9 179 motor->run(1, BDCMotor::BWD);
Manu_L 0:773e2a2be16f 180 break;
davide.aliprandi@st.com 5:7517162fb2b9 181 }
davide.aliprandi@st.com 5:7517162fb2b9 182 case 2: {
Manu_L 0:773e2a2be16f 183 printf("STEP 2: Motor(0) FWD Speed=50%% - Motor(1) BWD Speed=75%%\r\n");
Manu_L 0:773e2a2be16f 184 /* Set speed of motor 0 to 50 % */
davide.aliprandi@st.com 5:7517162fb2b9 185 motor->set_speed(0,50);
Manu_L 0:773e2a2be16f 186 /* Set speed of motor 1 to 75% */
davide.aliprandi@st.com 5:7517162fb2b9 187 motor->set_speed(1,75);
davide.aliprandi@st.com 5:7517162fb2b9 188 break;
davide.aliprandi@st.com 5:7517162fb2b9 189 }
davide.aliprandi@st.com 5:7517162fb2b9 190 case 3: {
Manu_L 0:773e2a2be16f 191 printf("STEP 3: Motor(0) FWD Speed=25%% - Motor(1) BWD Speed=50%%\r\n");
Manu_L 0:773e2a2be16f 192 /* Set speed of motor 0 to 25 % */
davide.aliprandi@st.com 5:7517162fb2b9 193 motor->set_speed(0,25);
Manu_L 0:773e2a2be16f 194 /* Set speed of motor 1 to 50% */
davide.aliprandi@st.com 5:7517162fb2b9 195 motor->set_speed(1,50);
davide.aliprandi@st.com 5:7517162fb2b9 196 break;
davide.aliprandi@st.com 5:7517162fb2b9 197 }
davide.aliprandi@st.com 5:7517162fb2b9 198 case 4: {
Manu_L 0:773e2a2be16f 199 printf("STEP 4: Motor(0) Stopped - Motor(1) BWD Speed=25%%\r\n");
Manu_L 0:773e2a2be16f 200 /* Stop Motor 0 */
davide.aliprandi@st.com 5:7517162fb2b9 201 motor->hard_stop(0);
Manu_L 0:773e2a2be16f 202 /* Set speed of motor 1 to 25% */
davide.aliprandi@st.com 5:7517162fb2b9 203 motor->set_speed(1,25);
davide.aliprandi@st.com 5:7517162fb2b9 204 break;
davide.aliprandi@st.com 5:7517162fb2b9 205 }
davide.aliprandi@st.com 5:7517162fb2b9 206 case 5: {
Manu_L 0:773e2a2be16f 207 printf("STEP 5: Motor(0) BWD Speed=25%% - Motor(1) Stopped\r\n");
Manu_L 0:773e2a2be16f 208 /* Set speed of motor 0 to 25 % */
davide.aliprandi@st.com 5:7517162fb2b9 209 motor->set_speed(0,25);
Manu_L 0:773e2a2be16f 210 /* start motor 0 to run backward */
davide.aliprandi@st.com 5:7517162fb2b9 211 motor->run(0, BDCMotor::BWD);
Manu_L 0:773e2a2be16f 212 /* Stop Motor 1 */
davide.aliprandi@st.com 5:7517162fb2b9 213 motor->hard_stop(1);
Manu_L 0:773e2a2be16f 214 break;
davide.aliprandi@st.com 5:7517162fb2b9 215 }
davide.aliprandi@st.com 5:7517162fb2b9 216 case 6: {
Manu_L 0:773e2a2be16f 217 printf("STEP 6: Motor(0) BWD Speed=50%% - Motor(1) FWD Speed=25%%\r\n");
Manu_L 0:773e2a2be16f 218 /* Set speed of motor 0 to 50 % */
davide.aliprandi@st.com 5:7517162fb2b9 219 motor->set_speed(0,50);
Manu_L 0:773e2a2be16f 220 /* Set speed of motor 1 to 25 % */
davide.aliprandi@st.com 5:7517162fb2b9 221 motor->set_speed(1,25);
Manu_L 0:773e2a2be16f 222 /* start motor 1 to run backward */
davide.aliprandi@st.com 5:7517162fb2b9 223 motor->run(1, BDCMotor::FWD);
Manu_L 0:773e2a2be16f 224 break;
davide.aliprandi@st.com 5:7517162fb2b9 225 }
davide.aliprandi@st.com 5:7517162fb2b9 226 case 7: {
Manu_L 0:773e2a2be16f 227 printf("STEP 7: Motor(0) BWD Speed=75%% - Motor(1) FWD Speed=50%%\r\n");
Manu_L 0:773e2a2be16f 228 /* Set speed of motor 0 to 75 % */
davide.aliprandi@st.com 5:7517162fb2b9 229 motor->set_speed(0,75);
Manu_L 0:773e2a2be16f 230 /* Set speed of motor 1 to 50 % */
davide.aliprandi@st.com 5:7517162fb2b9 231 motor->set_speed(1,50);
davide.aliprandi@st.com 5:7517162fb2b9 232 break;
davide.aliprandi@st.com 5:7517162fb2b9 233 }
davide.aliprandi@st.com 5:7517162fb2b9 234 case 8: {
Manu_L 0:773e2a2be16f 235 printf("STEP 8: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=75%%\r\n");
Manu_L 0:773e2a2be16f 236 /* Set speed of motor 0 to 100 % */
davide.aliprandi@st.com 5:7517162fb2b9 237 motor->set_speed(0,100);
Manu_L 0:773e2a2be16f 238 /* Set speed of motor 1 to 75 % */
davide.aliprandi@st.com 5:7517162fb2b9 239 motor->set_speed(1,75);
davide.aliprandi@st.com 5:7517162fb2b9 240 break;
davide.aliprandi@st.com 5:7517162fb2b9 241 }
davide.aliprandi@st.com 5:7517162fb2b9 242 case 9: {
Manu_L 0:773e2a2be16f 243 printf("STEP 9: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n");
Manu_L 0:773e2a2be16f 244 /* Set speed of motor 1 to 100 % */
davide.aliprandi@st.com 5:7517162fb2b9 245 motor->set_speed(1,100);
davide.aliprandi@st.com 5:7517162fb2b9 246 break;
davide.aliprandi@st.com 5:7517162fb2b9 247 }
davide.aliprandi@st.com 5:7517162fb2b9 248 case 10: {
Manu_L 0:773e2a2be16f 249 printf("STEP 10\r\n: Stop both motors and disable bridges\r\n");
Manu_L 0:773e2a2be16f 250 /* Stop both motors and disable bridge */
davide.aliprandi@st.com 5:7517162fb2b9 251 motor->hard_hiz(0);
davide.aliprandi@st.com 5:7517162fb2b9 252 motor->hard_hiz(1);
davide.aliprandi@st.com 5:7517162fb2b9 253 break;
davide.aliprandi@st.com 5:7517162fb2b9 254 }
davide.aliprandi@st.com 5:7517162fb2b9 255 case 11: {
Manu_L 0:773e2a2be16f 256 printf("STEP 11: Motor(0) FWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n");
Manu_L 0:773e2a2be16f 257 /* Start both motors to go forward*/
davide.aliprandi@st.com 5:7517162fb2b9 258 motor->run(0,BDCMotor::FWD);
davide.aliprandi@st.com 5:7517162fb2b9 259 motor->run(1,BDCMotor::FWD);
davide.aliprandi@st.com 5:7517162fb2b9 260 break;
davide.aliprandi@st.com 5:7517162fb2b9 261 }
Manu_L 0:773e2a2be16f 262 case 12:
davide.aliprandi@st.com 5:7517162fb2b9 263 default: {
Manu_L 0:773e2a2be16f 264 printf("STEP 12: Stop both motors and enter standby mode\r\n");
Manu_L 0:773e2a2be16f 265 /* Stop both motors and put chip in standby mode */
Davidroid 6:bd2fa888c101 266 motor->reset();
davide.aliprandi@st.com 5:7517162fb2b9 267 break;
davide.aliprandi@st.com 5:7517162fb2b9 268 }
Manu_L 0:773e2a2be16f 269 }
Manu_L 0:773e2a2be16f 270
Manu_L 0:773e2a2be16f 271 /* Wait for 5 seconds */
Manu_L 0:773e2a2be16f 272 wait_ms(5000);
Manu_L 0:773e2a2be16f 273
Manu_L 0:773e2a2be16f 274 /* Increment demostep*/
Manu_L 0:773e2a2be16f 275 demoStep++;
davide.aliprandi@st.com 5:7517162fb2b9 276 if (demoStep > 12) {
Manu_L 0:773e2a2be16f 277 demoStep = 0;
Manu_L 0:773e2a2be16f 278 }
Manu_L 0:773e2a2be16f 279 }
Manu_L 0:773e2a2be16f 280 }
davide.aliprandi@st.com 5:7517162fb2b9 281
Manu_L 0:773e2a2be16f 282 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/