This class interface the MDSMC (Micro Dual Serial Motor Controller) by Pololu with our mbed module
Embed:
(wiki syntax)
Show/hide line numbers
MDSMC.h
00001 /*THIS CLASS INTERFACE THE MDSMC by pololu (Micro Dual Serial Motor Controller) 00002 WITH OUR MBED MODULE. THE MDSMC MUST BE USED WITH UART MODULE*/ 00003 00004 #ifndef MBED_MDSMC_H 00005 #define MBED_MDSMC_H 00006 00007 #include "mbed.h" 00008 00009 #define Start 0x80 00010 #define ChangeConfig 0x02 00011 #define Setting1 0x7F 00012 #define Setting2 0x13 00013 #define Device 0x00 00014 #define Forward1 0x7F 00015 #define Reverse1 0x7E 00016 #define Forward2 0x27 00017 #define Reverse2 0x26 00018 #define Right 0x21 00019 #define Left 0x05 00020 00021 class MDSMC 00022 { 00023 public: 00024 /* - Declare Mbed connections 00025 ** - Select serial pin with "PinName data" parameter; 00026 ** - select reset pin with "PinName CLR" parameter; 00027 ** - select motor mode with "nM" parameter if you set nM = 1 the MDSMC drive one motor, 00028 ** if you set nM = 2 the MDSMC drive two motors; 00029 ** - select the baud rate with "bps" parameter you can select a bps value between 2000 00030 ** and 19200.*/ 00031 MDSMC(PinName TX, PinName RX, PinName CLR, int bps, int nM); 00032 00033 /* - Give direction and speed*/ 00034 void use(char direction, char speed); 00035 00036 protected: 00037 Serial _serialMDSMC; 00038 DigitalOut _CLR; 00039 void reset(); 00040 }; 00041 typedef unsigned char BYTE; 00042 00043 #endif 00044 00045 /*example used to test the class 00046 00047 #include "mbed.h" 00048 #include "MDSMC.h" 00049 00050 MDSMC(USBTX,USBRX,p5); 00051 00052 int main() 00053 { 00054 MDSMC.init(1,9600); 00055 wait(1); 00056 MDSMC.use(Forward1, 80); 00057 wait(1); 00058 MDSMC.use(Reverse1, 80); 00059 wait(2); 00060 MDSMC.init(2,9600); 00061 wait(1); 00062 MDSMC.use(Forward2, 80); 00063 wait(1); 00064 MDSMC.use(Reverse2, 80); 00065 wait(1); 00066 MDSMC.use(Right, 50); 00067 wait(1); 00068 MDSMC.use(Left, 50); 00069 } 00070 */
Generated on Sun Jul 24 2022 15:55:29 by
1.7.2