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.
Revision 0:3ca0289b7f8a, committed 2021-09-03
- Comitter:
- CCastrop1012
- Date:
- Fri Sep 03 04:58:03 2021 +0000
- Commit message:
- Control de velocidad y direccion de giro de un motor PAP con la tarjeta F407. Se incluyen las librerias con la clase Motor.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp Fri Sep 03 04:58:03 2021 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#include "Motor.h"
+
+
+MotorContinuo::MotorContinuo(PinName L1, PinName L2, PinName speedPin) :
+_L1(L1), _L2(L2), _speedPin(speedPin)
+{
+ _speedPin.period_ms(5);
+ _speedPin.write(0);
+};
+
+
+void MotorContinuo::Forward() { _L1=1; _L2=0;}
+void MotorContinuo::Back() { _L1=0; _L2=1;}
+void MotorContinuo::Stop() { _L1=0; _L2=0;}
+void MotorContinuo::StopT() { _L1=1; _L2=1;}
+void MotorContinuo::SpeedDuty(int v) { _speedPin.write(float(v/100.0));}
+void SpinLength_ms(float t) { t++;}// Duración del giro en ms
+void SpinLength(float t) { t++;}
+
+ /*
+void scolor_TCS3200::SetMode(uint8_t mode) {
+ switch (mode){
+ case SCALE_100: _s0= 1; _s1=1; break;
+ case SCALE_20: _s0=1 ; _s1=0; break;
+ case SCALE_2: _s0=0 ; _s1=1; break;
+ case POWER_DOWN: _s0=0 ; _s1=0; break;
+ }
+};
+
+
+long scolor_TCS3200::pulsewidth() {
+ while(!_s_in);
+ timer.start();
+ while(_s_in);
+ timer.stop();
+ float pulsewidth_v = timer.read_us();
+ timer.reset();
+ return pulsewidth_v;
+};
+*/
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.h Fri Sep 03 04:58:03 2021 +0000
@@ -0,0 +1,78 @@
+#ifndef Motor_H
+#define Motor_H
+#include "mbed.h"
+ /* **************************************************************************
+
+@CCastrop
+cristiank.castrop@ecci.edu.co
+
+
+ datasheet https://www.mouser.com/catalog/specsheets/TCS3200-E11.pdf
+
+
+ S0 Frequency scaling
+ S1 Frequency scaling
+ S2 Photo diode selection
+ S3 Photo diode selection
+ OutFreq Frequency
+
+ -----------------------------------
+ | ____________ ____________ |
+----> | | | | | | ___ ___
+Light | | Photodiode | | Current |--|---OUTPUT_FREQ | |___| |___
+----> | | Array |---| to | |
+ | | | | Frequency | |
+ | |____________| |____________| |
+ | ^ ^ ^ ^ |
+ -------|--|-------------|--|-------
+ | | | |
+ S2 S3 S0 S1
+
+SO | S1 | OUTPUT FREQUENCY SCALING | | S2 | S3 | PHOTODIODE TYPE |
+ 0 | 0 | power down | | 0 | 0 | Red |
+ 0 | 1 | 2% | | 0 | 1 | Blue |
+ 1 | 0 | 20% | | 1 | 0 | Clear (no filter) |
+ 1 | 1 | 100% | | 1 | 1 | Green |
+
+******************************************************************************/
+
+
+
+class MotorContinuo {
+ public:
+
+ MotorContinuo(PinName L1, PinName L2, PinName speedPin); // declaracion del Objeto
+
+ void Forward(); // Da un sentido de giro al motor
+ void Back(); // Genera un sentido de giro contrario al de Forward
+ void Stop(); // Detiene el motor dejando el movimiento libre
+ void StopT(); // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
+ void SpeedDuty(int v); // Varia la velocidad de giro del motor de 0 a 100%
+ void SpinLength_ms(float t); // Duración del giro en ms
+ void SpinLength(float t); // Duración del giro
+
+ float GetSpeed(); // Return Duty Cycle of PWM in % de 0 a 100
+
+ private:
+ DigitalOut _L1;
+ DigitalOut _L2;
+ PwmOut _speedPin;
+
+
+};
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mainpwm.cpp Fri Sep 03 04:58:03 2021 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+
+DigitalOut IzqDireccion(PD_13);
+DigitalOut LED(PD_14);
+DigitalOut DerDireccion(PD_11);
+
+
+PwmOut Speed(PB_15);
+
+int main() {
+
+ Speed.period_ms(5);
+
+ while(1)
+ {
+
+ /// direccion 1
+ LED = 1;
+ IzqDireccion = 1;
+ DerDireccion = !IzqDireccion;
+ wait_ms(100);
+
+ /// Speed setting
+ for(int i = 0; i < 100; i ++)
+ {
+ Speed.write(float(i/100.0));
+ wait(1);
+
+ }
+
+ /// Set a 0
+ IzqDireccion = 0;
+ DerDireccion = 0;
+ wait_ms(100);
+
+ /// Direccion 2
+ LED = 0;
+ IzqDireccion = 0;
+ DerDireccion = !IzqDireccion;
+ wait_ms(100);
+
+ // Speed Setting
+ for(int i = 0; i < 10; i ++)
+ {
+ Speed.write(float(i/100.0));
+ wait(1);
+
+ }
+
+ /// Set to 0
+ IzqDireccion = 0;
+ DerDireccion = 0;
+ wait_ms(100);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Sep 03 04:58:03 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file