Signori, questo è il codice di doukietown...... divertitevi
Dependencies: HCSR04 TCS3200 X_NUCLEO_IHM12A1 mbed
Fork of HelloWorld_IHM12A1 by
Revision 5:7517162fb2b9, committed 2017-03-24
- Comitter:
- davide.aliprandi@st.com
- Date:
- Fri Mar 24 11:01:02 2017 +0100
- Parent:
- 4:d6077c2bfddd
- Child:
- 6:bd2fa888c101
- Commit message:
- Aligning to ARM mbed coding style.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 23 09:19:34 2016 +0000
+++ b/main.cpp Fri Mar 24 11:01:02 2017 +0100
@@ -42,12 +42,12 @@
#include "mbed.h"
/* Component specific header files. */
-#include "stspin240_250_class.h"
+#include "STSpin240_250.h"
/* Variables -----------------------------------------------------------------*/
/* Initialization parameters of the motor connected to the expansion board. */
- Stspin240_250_Init_t initDeviceParameters =
+ Stspin240_250_init_t init =
{
20000, /* Frequency of PWM of Input Bridge A in Hz up to 100000Hz */
20000, /* Frequency of PWM of Input Bridge B in Hz up to 100000Hz */
@@ -66,16 +66,15 @@
* @param[in] error Number of the error
* @retval None
* @note If needed, implement it, and then attach it:
- * + motor->AttachErrorHandler(&myErrorHandler);
+ * + motor->attach_error_handler(&my_error_handler);
*/
-void myErrorHandler(uint16_t error)
+void my_error_handler(uint16_t error)
{
/* Printing to the console. */
printf("Error %d detected\r\n\n", error);
/* Infinite loop */
- while(1)
- {
+ while (true) {
}
}
@@ -84,12 +83,12 @@
* @param None
* @retval None
* @note If needed, implement it, and then attach and enable it:
- * + motor->AttachFlagIRQ(&myFlagIRQHandler);
- * + motor->EnableFlagIRQ();
+ * + motor->attach_flag_irq(&my_flag_irq_handler);
+ * + motor->enable_flag_irq();
* To disable it:
* + motor->DisbleFlagIRQ();
*/
-void myFlagIRQHandler(void)
+void my_flag_irq_handler(void)
{
/* Code to be customised */
/************************/
@@ -97,15 +96,13 @@
printf(" WARNING: \"FLAG\" interrupt triggered.\r\n");
/* Get the state of bridge A */
- uint16_t bridgeState = motor->GetBridgeStatus(0);
+ uint16_t bridgeState = motor->get_bridge_status(0);
- if (bridgeState == 0)
- {
- if (motor->GetDeviceState(0) != INACTIVE)
- {
+ if (bridgeState == 0) {
+ if (motor->get_device_state(0) != INACTIVE) {
/* Bridges were disabled due to overcurrent or over temperature */
/* When motor was running */
- myErrorHandler(0XBAD0);
+ my_error_handler(0XBAD0);
}
}
}
@@ -129,133 +126,144 @@
#else
motor = new STSPIN240_250(D2, D9, D6, D7, D5, D4, A0);
#endif
- if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE);
+ if (motor->init(&init) != COMPONENT_OK) exit(EXIT_FAILURE);
/* Set dual bridge enabled as two motors are used*/
- motor->SetDualFullBridgeConfig(1);
+ motor->set_dual_full_bridge_config(1);
/* Attaching and enabling an interrupt handler. */
- motor->AttachFlagIRQ(&myFlagIRQHandler);
- motor->EnableFlagIRQ();
+ motor->attach_flag_irq(&my_flag_irq_handler);
+ motor->enable_flag_irq();
/* Attaching an error handler */
- motor->AttachErrorHandler(&myErrorHandler);
+ motor->attach_error_handler(&my_error_handler);
/* Printing to the console. */
printf("Motor Control Application Example for 2 brush DC motors\r\n");
/* Set PWM Frequency of Ref to 15000 Hz */
- motor->SetRefPwmFreq(0, 15000);
+ motor->set_ref_pwm_freq(0, 15000);
/* Set PWM duty cycle of Ref to 60% */
- motor->SetRefPwmDc(0, 60);
+ motor->set_ref_pwm_dc(0, 60);
/* Set PWM Frequency of bridge A inputs to 10000 Hz */
- motor->SetBridgeInputPwmFreq(0,10000);
+ motor->set_bridge_input_pwm_freq(0,10000);
/* Set PWM Frequency of bridge B inputs to 10000 Hz */
- motor->SetBridgeInputPwmFreq(1,10000);
+ motor->set_bridge_input_pwm_freq(1,10000);
/* Infinite Loop. */
printf("--> Infinite Loop...\r\n");
- while (1)
- {
- switch (demoStep)
- {
- case 0:
+ while (true) {
+ switch (demoStep) {
+ case 0: {
printf("STEP 0: Motor(0) FWD Speed=100%% - Motor(1) Inactive\r\n");
/* Set speed of motor 0 to 100 % */
- motor->SetSpeed(0,100);
+ motor->set_speed(0,100);
/* start motor 0 to run forward*/
/* if chip is in standby mode */
/* it is automatically awakened */
- motor->Run(0, BDCMotor::FWD);
+ motor->run(0, BDCMotor::FWD);
break;
- case 1:
+ }
+ case 1: {
printf("STEP 1: Motor(0) FWD Speed=75%% - Motor(1) BWD Speed=100%%\r\n");
/* Set speed of motor 0 to 75 % */
- motor->SetSpeed(0,75);
+ motor->set_speed(0,75);
/* Set speed of motor 1 to 100 % */
- motor->SetSpeed(1,100);
+ motor->set_speed(1,100);
/* start motor 1 to run backward */
- motor->Run(1, BDCMotor::BWD);
+ motor->run(1, BDCMotor::BWD);
break;
- case 2:
+ }
+ case 2: {
printf("STEP 2: Motor(0) FWD Speed=50%% - Motor(1) BWD Speed=75%%\r\n");
/* Set speed of motor 0 to 50 % */
- motor->SetSpeed(0,50);
+ motor->set_speed(0,50);
/* Set speed of motor 1 to 75% */
- motor->SetSpeed(1,75);
- break;
- case 3:
+ motor->set_speed(1,75);
+ break;
+ }
+ case 3: {
printf("STEP 3: Motor(0) FWD Speed=25%% - Motor(1) BWD Speed=50%%\r\n");
/* Set speed of motor 0 to 25 % */
- motor->SetSpeed(0,25);
+ motor->set_speed(0,25);
/* Set speed of motor 1 to 50% */
- motor->SetSpeed(1,50);
- break;
- case 4:
+ motor->set_speed(1,50);
+ break;
+ }
+ case 4: {
printf("STEP 4: Motor(0) Stopped - Motor(1) BWD Speed=25%%\r\n");
/* Stop Motor 0 */
- motor->HardStop(0);
+ motor->hard_stop(0);
/* Set speed of motor 1 to 25% */
- motor->SetSpeed(1,25);
- break;
- case 5:
+ motor->set_speed(1,25);
+ break;
+ }
+ case 5: {
printf("STEP 5: Motor(0) BWD Speed=25%% - Motor(1) Stopped\r\n");
/* Set speed of motor 0 to 25 % */
- motor->SetSpeed(0,25);
+ motor->set_speed(0,25);
/* start motor 0 to run backward */
- motor->Run(0, BDCMotor::BWD);
+ motor->run(0, BDCMotor::BWD);
/* Stop Motor 1 */
- motor->HardStop(1);
+ motor->hard_stop(1);
break;
- case 6:
+ }
+ case 6: {
printf("STEP 6: Motor(0) BWD Speed=50%% - Motor(1) FWD Speed=25%%\r\n");
/* Set speed of motor 0 to 50 % */
- motor->SetSpeed(0,50);
+ motor->set_speed(0,50);
/* Set speed of motor 1 to 25 % */
- motor->SetSpeed(1,25);
+ motor->set_speed(1,25);
/* start motor 1 to run backward */
- motor->Run(1, BDCMotor::FWD);
+ motor->run(1, BDCMotor::FWD);
break;
- case 7:
+ }
+ case 7: {
printf("STEP 7: Motor(0) BWD Speed=75%% - Motor(1) FWD Speed=50%%\r\n");
/* Set speed of motor 0 to 75 % */
- motor->SetSpeed(0,75);
+ motor->set_speed(0,75);
/* Set speed of motor 1 to 50 % */
- motor->SetSpeed(1,50);
- break;
- case 8:
+ motor->set_speed(1,50);
+ break;
+ }
+ case 8: {
printf("STEP 8: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=75%%\r\n");
/* Set speed of motor 0 to 100 % */
- motor->SetSpeed(0,100);
+ motor->set_speed(0,100);
/* Set speed of motor 1 to 75 % */
- motor->SetSpeed(1,75);
- break;
- case 9:
+ motor->set_speed(1,75);
+ break;
+ }
+ case 9: {
printf("STEP 9: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n");
/* Set speed of motor 1 to 100 % */
- motor->SetSpeed(1,100);
- break;
- case 10:
+ motor->set_speed(1,100);
+ break;
+ }
+ case 10: {
printf("STEP 10\r\n: Stop both motors and disable bridges\r\n");
/* Stop both motors and disable bridge */
- motor->HardHiZ(0);
- motor->HardHiZ(1);
- break;
- case 11:
+ motor->hard_hiz(0);
+ motor->hard_hiz(1);
+ break;
+ }
+ case 11: {
printf("STEP 11: Motor(0) FWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n");
/* Start both motors to go forward*/
- motor->Run(0,BDCMotor::FWD);
- motor->Run(1,BDCMotor::FWD);
- break;
+ motor->run(0,BDCMotor::FWD);
+ motor->run(1,BDCMotor::FWD);
+ break;
+ }
case 12:
- default:
+ default: {
printf("STEP 12: Stop both motors and enter standby mode\r\n");
/* Stop both motors and put chip in standby mode */
motor->Reset();
- break;
+ break;
+ }
}
/* Wait for 5 seconds */
@@ -263,10 +271,10 @@
/* Increment demostep*/
demoStep++;
- if (demoStep > 12)
- {
+ if (demoStep > 12) {
demoStep = 0;
}
}
}
+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
