![](/media/cache/profiles/Cristian_Castro_-_Foto.jpg.50x50_q85.jpg)
Control de velocidad y dirección de giro de un motor PAP con la tarjeta F407. Se incluyen las librerías con la clase Motor.
Motor.cpp@0:3ca0289b7f8a, 2021-09-03 (annotated)
- Committer:
- CCastrop1012
- Date:
- Fri Sep 03 04:58:03 2021 +0000
- Revision:
- 0:3ca0289b7f8a
Control de velocidad y direccion de giro de un motor PAP con la tarjeta F407. Se incluyen las librerias con la clase Motor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CCastrop1012 | 0:3ca0289b7f8a | 1 | #include "mbed.h" |
CCastrop1012 | 0:3ca0289b7f8a | 2 | #include "Motor.h" |
CCastrop1012 | 0:3ca0289b7f8a | 3 | |
CCastrop1012 | 0:3ca0289b7f8a | 4 | |
CCastrop1012 | 0:3ca0289b7f8a | 5 | MotorContinuo::MotorContinuo(PinName L1, PinName L2, PinName speedPin) : |
CCastrop1012 | 0:3ca0289b7f8a | 6 | _L1(L1), _L2(L2), _speedPin(speedPin) |
CCastrop1012 | 0:3ca0289b7f8a | 7 | { |
CCastrop1012 | 0:3ca0289b7f8a | 8 | _speedPin.period_ms(5); |
CCastrop1012 | 0:3ca0289b7f8a | 9 | _speedPin.write(0); |
CCastrop1012 | 0:3ca0289b7f8a | 10 | }; |
CCastrop1012 | 0:3ca0289b7f8a | 11 | |
CCastrop1012 | 0:3ca0289b7f8a | 12 | |
CCastrop1012 | 0:3ca0289b7f8a | 13 | void MotorContinuo::Forward() { _L1=1; _L2=0;} |
CCastrop1012 | 0:3ca0289b7f8a | 14 | void MotorContinuo::Back() { _L1=0; _L2=1;} |
CCastrop1012 | 0:3ca0289b7f8a | 15 | void MotorContinuo::Stop() { _L1=0; _L2=0;} |
CCastrop1012 | 0:3ca0289b7f8a | 16 | void MotorContinuo::StopT() { _L1=1; _L2=1;} |
CCastrop1012 | 0:3ca0289b7f8a | 17 | void MotorContinuo::SpeedDuty(int v) { _speedPin.write(float(v/100.0));} |
CCastrop1012 | 0:3ca0289b7f8a | 18 | void SpinLength_ms(float t) { t++;}// Duración del giro en ms |
CCastrop1012 | 0:3ca0289b7f8a | 19 | void SpinLength(float t) { t++;} |
CCastrop1012 | 0:3ca0289b7f8a | 20 | |
CCastrop1012 | 0:3ca0289b7f8a | 21 | /* |
CCastrop1012 | 0:3ca0289b7f8a | 22 | void scolor_TCS3200::SetMode(uint8_t mode) { |
CCastrop1012 | 0:3ca0289b7f8a | 23 | switch (mode){ |
CCastrop1012 | 0:3ca0289b7f8a | 24 | case SCALE_100: _s0= 1; _s1=1; break; |
CCastrop1012 | 0:3ca0289b7f8a | 25 | case SCALE_20: _s0=1 ; _s1=0; break; |
CCastrop1012 | 0:3ca0289b7f8a | 26 | case SCALE_2: _s0=0 ; _s1=1; break; |
CCastrop1012 | 0:3ca0289b7f8a | 27 | case POWER_DOWN: _s0=0 ; _s1=0; break; |
CCastrop1012 | 0:3ca0289b7f8a | 28 | } |
CCastrop1012 | 0:3ca0289b7f8a | 29 | }; |
CCastrop1012 | 0:3ca0289b7f8a | 30 | |
CCastrop1012 | 0:3ca0289b7f8a | 31 | |
CCastrop1012 | 0:3ca0289b7f8a | 32 | long scolor_TCS3200::pulsewidth() { |
CCastrop1012 | 0:3ca0289b7f8a | 33 | while(!_s_in); |
CCastrop1012 | 0:3ca0289b7f8a | 34 | timer.start(); |
CCastrop1012 | 0:3ca0289b7f8a | 35 | while(_s_in); |
CCastrop1012 | 0:3ca0289b7f8a | 36 | timer.stop(); |
CCastrop1012 | 0:3ca0289b7f8a | 37 | float pulsewidth_v = timer.read_us(); |
CCastrop1012 | 0:3ca0289b7f8a | 38 | timer.reset(); |
CCastrop1012 | 0:3ca0289b7f8a | 39 | return pulsewidth_v; |
CCastrop1012 | 0:3ca0289b7f8a | 40 | }; |
CCastrop1012 | 0:3ca0289b7f8a | 41 | */ |
CCastrop1012 | 0:3ca0289b7f8a | 42 |