library for the motor driver
Dependents: 4180_final_project
Fork of libTCS34725 by
TB6612FNG.cpp@7:e1be74ebe7be, 2017-04-18 (annotated)
- Committer:
- mwilkens241
- Date:
- Tue Apr 18 19:53:13 2017 +0000
- Revision:
- 7:e1be74ebe7be
- Parent:
- 5:822a7407ccb3
- Child:
- 8:fe6530d23d58
fixed standby error
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 | 7:e1be74ebe7be | 27 | *dir1 = 0; |
mwilkens241 | 7:e1be74ebe7be | 28 | *dir2 = 0; |
mwilkens241 | 7:e1be74ebe7be | 29 | *pwm = 1; |
mwilkens241 | 7:e1be74ebe7be | 30 | } |
mwilkens241 | 7:e1be74ebe7be | 31 | |
mwilkens241 | 7:e1be74ebe7be | 32 | void TB6612FNG::standby(){ |
mwilkens241 | 5:822a7407ccb3 | 33 | on = false; |
mwilkens241 | 5:822a7407ccb3 | 34 | *dir1 = 0; |
mwilkens241 | 5:822a7407ccb3 | 35 | *dir2 = 0; |
mwilkens241 | 5:822a7407ccb3 | 36 | *pwm = 1; |
mwilkens241 | 5:822a7407ccb3 | 37 | *stby = 1; |
mwilkens241 | 0:4796574af790 | 38 | } |
mwilkens241 | 0:4796574af790 | 39 | |
mwilkens241 | 5:822a7407ccb3 | 40 | void TB6612FNG::fwd(float speed){ |
mwilkens241 | 5:822a7407ccb3 | 41 | if(on && speed <= 1){ |
mwilkens241 | 5:822a7407ccb3 | 42 | *dir1 = 1; |
mwilkens241 | 5:822a7407ccb3 | 43 | *dir2 = 0; |
mwilkens241 | 5:822a7407ccb3 | 44 | *pwm = speed; |
mwilkens241 | 5:822a7407ccb3 | 45 | } |
mwilkens241 | 1:06c9bbbdb8b0 | 46 | } |
mwilkens241 | 1:06c9bbbdb8b0 | 47 | |
mwilkens241 | 5:822a7407ccb3 | 48 | void TB6612FNG::rev(float speed){ |
mwilkens241 | 5:822a7407ccb3 | 49 | if(on && speed <= 1){ |
mwilkens241 | 5:822a7407ccb3 | 50 | *dir1 = 0; |
mwilkens241 | 5:822a7407ccb3 | 51 | *dir2 = 1; |
mwilkens241 | 5:822a7407ccb3 | 52 | *pwm = speed; |
mwilkens241 | 5:822a7407ccb3 | 53 | } |
mwilkens241 | 0:4796574af790 | 54 | } |