victor gomez
/
7-Controlador-Motor-DC
ok
main.cpp@0:f9baa136dbc3, 2021-07-01 (annotated)
- Committer:
- thevic16
- Date:
- Thu Jul 01 20:02:37 2021 +0000
- Revision:
- 0:f9baa136dbc3
si
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thevic16 | 0:f9baa136dbc3 | 1 | /* mbed Microcontroller Library |
thevic16 | 0:f9baa136dbc3 | 2 | * Copyright (c) 2019 ARM Limited |
thevic16 | 0:f9baa136dbc3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
thevic16 | 0:f9baa136dbc3 | 4 | */ |
thevic16 | 0:f9baa136dbc3 | 5 | |
thevic16 | 0:f9baa136dbc3 | 6 | #include "mbed.h" |
thevic16 | 0:f9baa136dbc3 | 7 | #include "platform/mbed_thread.h" |
thevic16 | 0:f9baa136dbc3 | 8 | |
thevic16 | 0:f9baa136dbc3 | 9 | |
thevic16 | 0:f9baa136dbc3 | 10 | |
thevic16 | 0:f9baa136dbc3 | 11 | DigitalOut direccion(D2); |
thevic16 | 0:f9baa136dbc3 | 12 | PwmOut PWM_velocidad(D3); |
thevic16 | 0:f9baa136dbc3 | 13 | |
thevic16 | 0:f9baa136dbc3 | 14 | |
thevic16 | 0:f9baa136dbc3 | 15 | //Interfaces para USER_BUTTON |
thevic16 | 0:f9baa136dbc3 | 16 | //DigitalIn userButton(USER_BUTTON); |
thevic16 | 0:f9baa136dbc3 | 17 | //bool buttonDown = false; |
thevic16 | 0:f9baa136dbc3 | 18 | |
thevic16 | 0:f9baa136dbc3 | 19 | int main() |
thevic16 | 0:f9baa136dbc3 | 20 | { |
thevic16 | 0:f9baa136dbc3 | 21 | |
thevic16 | 0:f9baa136dbc3 | 22 | direccion = 0; // En direccion de las manecillas del reloj. |
thevic16 | 0:f9baa136dbc3 | 23 | |
thevic16 | 0:f9baa136dbc3 | 24 | float valor_velocidad = 0; //representa un 0% |
thevic16 | 0:f9baa136dbc3 | 25 | |
thevic16 | 0:f9baa136dbc3 | 26 | PWM_velocidad.period(0.0001f); //Declaramos el periodo |
thevic16 | 0:f9baa136dbc3 | 27 | PWM_velocidad.write(1.0f); |
thevic16 | 0:f9baa136dbc3 | 28 | |
thevic16 | 0:f9baa136dbc3 | 29 | |
thevic16 | 0:f9baa136dbc3 | 30 | thread_sleep_for(5000); |
thevic16 | 0:f9baa136dbc3 | 31 | |
thevic16 | 0:f9baa136dbc3 | 32 | PWM_velocidad.write(0.0f); |
thevic16 | 0:f9baa136dbc3 | 33 | |
thevic16 | 0:f9baa136dbc3 | 34 | |
thevic16 | 0:f9baa136dbc3 | 35 | /* |
thevic16 | 0:f9baa136dbc3 | 36 | if (userButton) { // button is pressed |
thevic16 | 0:f9baa136dbc3 | 37 | if (!buttonDown) { // a new button press |
thevic16 | 0:f9baa136dbc3 | 38 | |
thevic16 | 0:f9baa136dbc3 | 39 | //valor_velocidad = valor_velocidad + 0.004; //Representa un aumento de un 10%. |
thevic16 | 0:f9baa136dbc3 | 40 | //PWM_velocidad.write(valor_velocidad); |
thevic16 | 0:f9baa136dbc3 | 41 | |
thevic16 | 0:f9baa136dbc3 | 42 | buttonDown = true; // record that the button is now down so we don't count one press lots of times |
thevic16 | 0:f9baa136dbc3 | 43 | thread_sleep_for(10); // ignore anything for 10ms, a very basic way to de-bounce the button. |
thevic16 | 0:f9baa136dbc3 | 44 | } |
thevic16 | 0:f9baa136dbc3 | 45 | |
thevic16 | 0:f9baa136dbc3 | 46 | } else { // button isn't pressed |
thevic16 | 0:f9baa136dbc3 | 47 | buttonDown = false; |
thevic16 | 0:f9baa136dbc3 | 48 | } |
thevic16 | 0:f9baa136dbc3 | 49 | */ |
thevic16 | 0:f9baa136dbc3 | 50 | |
thevic16 | 0:f9baa136dbc3 | 51 | } |
thevic16 | 0:f9baa136dbc3 | 52 | |
thevic16 | 0:f9baa136dbc3 | 53 |