library for the motor driver
Dependents: 4180_final_project
Fork of libTCS34725 by
TB6612FNG.cpp@5:822a7407ccb3, 2017-03-22 (annotated)
- Committer:
- mwilkens241
- Date:
- Wed Mar 22 20:56:36 2017 +0000
- Revision:
- 5:822a7407ccb3
- Parent:
- TCA9548.cpp@4:cc00e3842f1b
- Child:
- 7:e1be74ebe7be
basic motor driver (untested)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mwilkens241 | 5:822a7407ccb3 | 1 | #include "TB6612FNG.h" |
mwilkens241 | 0:4796574af790 | 2 | |
mwilkens241 | 5:822a7407ccb3 | 3 | TB6612FNG::TB6612FNG(){ |
mwilkens241 | 5:822a7407ccb3 | 4 | } |
mwilkens241 | 1:06c9bbbdb8b0 | 5 | |
mwilkens241 | 5:822a7407ccb3 | 6 | TB6612FNG::TB6612FNG(PinName idir1, PinName idir2, PinName ipwm, PinName istby){ |
mwilkens241 | 5:822a7407ccb3 | 7 | config(idir1,idir2,ipwm,istby); |
mwilkens241 | 5:822a7407ccb3 | 8 | } |
mwilkens241 | 5:822a7407ccb3 | 9 | |
mwilkens241 | 5:822a7407ccb3 | 10 | void TB6612FNG::config(PinName idir1, PinName idir2, PinName ipwm, PinName istby){ |
mwilkens241 | 5:822a7407ccb3 | 11 | dir1 = new DigitalOut(idir1); |
mwilkens241 | 5:822a7407ccb3 | 12 | dir2 = new DigitalOut(idir2); |
mwilkens241 | 5:822a7407ccb3 | 13 | pwm = new PwmOut(ipwm); |
mwilkens241 | 5:822a7407ccb3 | 14 | stby = new DigitalOut(istby); |
mwilkens241 | 5:822a7407ccb3 | 15 | stop(); |
mwilkens241 | 0:4796574af790 | 16 | } |
mwilkens241 | 0:4796574af790 | 17 | |
mwilkens241 | 5:822a7407ccb3 | 18 | void TB6612FNG::start(){ |
mwilkens241 | 5:822a7407ccb3 | 19 | on = true; |
mwilkens241 | 5:822a7407ccb3 | 20 | *dir1 = 1; |
mwilkens241 | 5:822a7407ccb3 | 21 | *dir2 = 1; |
mwilkens241 | 5:822a7407ccb3 | 22 | *pwm = 0; |
mwilkens241 | 5:822a7407ccb3 | 23 | *stby = 0; |
mwilkens241 | 5:822a7407ccb3 | 24 | } |
mwilkens241 | 5:822a7407ccb3 | 25 | |
mwilkens241 | 5:822a7407ccb3 | 26 | void TB6612FNG::stop(){ |
mwilkens241 | 5:822a7407ccb3 | 27 | on = false; |
mwilkens241 | 5:822a7407ccb3 | 28 | *dir1 = 0; |
mwilkens241 | 5:822a7407ccb3 | 29 | *dir2 = 0; |
mwilkens241 | 5:822a7407ccb3 | 30 | *pwm = 1; |
mwilkens241 | 5:822a7407ccb3 | 31 | *stby = 1; |
mwilkens241 | 0:4796574af790 | 32 | } |
mwilkens241 | 0:4796574af790 | 33 | |
mwilkens241 | 5:822a7407ccb3 | 34 | void TB6612FNG::fwd(float speed){ |
mwilkens241 | 5:822a7407ccb3 | 35 | if(on && speed <= 1){ |
mwilkens241 | 5:822a7407ccb3 | 36 | *dir1 = 1; |
mwilkens241 | 5:822a7407ccb3 | 37 | *dir2 = 0; |
mwilkens241 | 5:822a7407ccb3 | 38 | *pwm = speed; |
mwilkens241 | 5:822a7407ccb3 | 39 | } |
mwilkens241 | 1:06c9bbbdb8b0 | 40 | } |
mwilkens241 | 1:06c9bbbdb8b0 | 41 | |
mwilkens241 | 5:822a7407ccb3 | 42 | void TB6612FNG::rev(float speed){ |
mwilkens241 | 5:822a7407ccb3 | 43 | if(on && speed <= 1){ |
mwilkens241 | 5:822a7407ccb3 | 44 | *dir1 = 0; |
mwilkens241 | 5:822a7407ccb3 | 45 | *dir2 = 1; |
mwilkens241 | 5:822a7407ccb3 | 46 | *pwm = speed; |
mwilkens241 | 5:822a7407ccb3 | 47 | } |
mwilkens241 | 0:4796574af790 | 48 | } |