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
main.cpp@2:5a81778c8f8b, 2015-11-02 (annotated)
- Committer:
- perlatecnica
- Date:
- Mon Nov 02 14:02:13 2015 +0000
- Revision:
- 2:5a81778c8f8b
- Parent:
- 0:4860a91fb495
- Child:
- 3:aecdaed3e772
v1.0
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| perlatecnica | 2:5a81778c8f8b | 1 | /**************************************************** |
| perlatecnica | 2:5a81778c8f8b | 2 | * FAST PROTOTYPING WITH NUCLEO * |
| perlatecnica | 2:5a81778c8f8b | 3 | * Example Code 09: DC motor control * |
| perlatecnica | 2:5a81778c8f8b | 4 | * Author: Mauro D'Angelo * |
| perlatecnica | 2:5a81778c8f8b | 5 | * Organization: Perlatecnica no-profit organization * |
| perlatecnica | 2:5a81778c8f8b | 6 | *****************************************************/ |
| bcostm | 0:4860a91fb495 | 7 | #include "mbed.h" |
| bcostm | 0:4860a91fb495 | 8 | |
| perlatecnica | 2:5a81778c8f8b | 9 | #define PWMB PA_7 |
| perlatecnica | 2:5a81778c8f8b | 10 | #define DIRB PA_5 |
| perlatecnica | 2:5a81778c8f8b | 11 | |
| perlatecnica | 2:5a81778c8f8b | 12 | #define PWMA PB_3 |
| perlatecnica | 2:5a81778c8f8b | 13 | #define DIRA PA_6 |
| bcostm | 0:4860a91fb495 | 14 | |
| perlatecnica | 2:5a81778c8f8b | 15 | // Instanzia un oggetto di tipo PwmOut e gli da il nome mypwm |
| perlatecnica | 2:5a81778c8f8b | 16 | PwmOut mypwm(PWMB); |
| perlatecnica | 2:5a81778c8f8b | 17 | // Definisce il pin che indica la direzione |
| perlatecnica | 2:5a81778c8f8b | 18 | DigitalOut motordir(DIRB); |
| perlatecnica | 2:5a81778c8f8b | 19 | |
| perlatecnica | 2:5a81778c8f8b | 20 | // Instanzia un oggetto di tipo DigitalOut sul pin LED1 e gli da il nome myled |
| bcostm | 0:4860a91fb495 | 21 | DigitalOut myled(LED1); |
| bcostm | 0:4860a91fb495 | 22 | |
| perlatecnica | 2:5a81778c8f8b | 23 | // Instanzia un oggetto di tipo Serial sui pin Tx e Rx della porta USB e gli da il nome pc (trattandosi della porta USB connessa al PC) |
| perlatecnica | 2:5a81778c8f8b | 24 | Serial pc(USBTX, USBRX); |
| perlatecnica | 2:5a81778c8f8b | 25 | |
| perlatecnica | 2:5a81778c8f8b | 26 | // Entry point |
| bcostm | 0:4860a91fb495 | 27 | int main() { |
| perlatecnica | 2:5a81778c8f8b | 28 | motordir = 1; |
| bcostm | 0:4860a91fb495 | 29 | |
| perlatecnica | 2:5a81778c8f8b | 30 | //Set pwm signal period: The period needed to control the motor in the servo datasheet |
| perlatecnica | 2:5a81778c8f8b | 31 | mypwm.period_ms(10); |
| perlatecnica | 2:5a81778c8f8b | 32 | //mypwm.pulsewidth(0.01); // 100% |
| perlatecnica | 2:5a81778c8f8b | 33 | //mypwm.pulsewidth(0.005); // 50% |
| perlatecnica | 2:5a81778c8f8b | 34 | mypwm.pulsewidth(0.002); // 20% |
| bcostm | 0:4860a91fb495 | 35 | |
| perlatecnica | 2:5a81778c8f8b | 36 | while(1) {;} |
| perlatecnica | 2:5a81778c8f8b | 37 | } |