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: mbed
TestPWM.cpp
- Committer:
- pinofal
- Date:
- 2019-10-30
- Revision:
- 0:aaeeba6e02f5
- Child:
- 1:762bbfe2fc71
File content as of revision 0:aaeeba6e02f5:
// Test motore CC, pilotato in PWM
// testato su F070RB
#include "mbed.h"
#include<stdlib.h>
// Definizione periferica USB seriale del PC
Serial pc(USBTX, USBRX, 921600); // seriale di comunicazione con il PC. Associati a PA_11 e PA_12
// Definizione periferica seriale del Modulo BLE ELETT114A
Serial myBLE(PA_9, PA_10, 9600); //Tx, Rx, bps
// User Button, LED
DigitalIn myButton(USER_BUTTON); // pulsante Blu sulla scheda. Associato a PC_13
DigitalOut myLed(LED2); // LED verde sulla scheda. Associato a PA_5
// Output per pilotaggio di un motore PWM
PwmOut OutPWM (PB_8);
/**********/
/* MAIN */
/**********/
int main()
{
// messaggio di benvenuto
pc.printf("************ Hallo ************** \r\n");
pc.printf("*********** Test PWM *************\r\n");
// inizializza il PWM
OutPWM.period_ms(50); // periodo del PWM
OutPWM.write(0.0); // inizializza duty cycle del PWM
// Ciclo principale
while(true)
{
// accende il motore se è premuto lo User Button (BLU)
if(myButton == 0)
{
// accendi LED su scheda
myLed = 1;
// regola velocità del motore modificando duty cycle del PWM
OutPWM.write(0.4); // velocità massima = 1.0
}
else
{
// spegni LED su scheda
myLed = 0;
// ferma il PWM
OutPWM.write(0.0); // motore fermo = 0.0
} // if(myButton==0)
} // while(true) Principale
}