cansat_B 2019 / Mbed 2 deprecated tougou-no3

Dependencies:   mbed

Committer:
saeichi
Date:
Mon Dec 02 10:24:31 2019 +0000
Revision:
7:a47fdb7f9bc8
Parent:
3:f70ecf1e21d5
tougou;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KINU 3:f70ecf1e21d5 1 /**
KINU 3:f70ecf1e21d5 2 * Motor Driver TB6612 Control Library
KINU 3:f70ecf1e21d5 3 *
KINU 3:f70ecf1e21d5 4 * -- TB6612 is a device of the TOSHIBA.
KINU 3:f70ecf1e21d5 5 *
KINU 3:f70ecf1e21d5 6 * Copyright (C) 2012 Junichi Katsu (JKSOFT)
KINU 3:f70ecf1e21d5 7 */
KINU 3:f70ecf1e21d5 8
KINU 3:f70ecf1e21d5 9
KINU 3:f70ecf1e21d5 10 #include "TB6612.h"
KINU 3:f70ecf1e21d5 11
KINU 3:f70ecf1e21d5 12 // TB6612 Class Constructor
KINU 3:f70ecf1e21d5 13 TB6612::TB6612(PinName pwm, PinName fwd, PinName rev):
KINU 3:f70ecf1e21d5 14 _pwm(pwm), _fwd(fwd), _rev(rev) {
KINU 3:f70ecf1e21d5 15
KINU 3:f70ecf1e21d5 16 _fwd = 0;
KINU 3:f70ecf1e21d5 17 _rev = 0;
KINU 3:f70ecf1e21d5 18 _pwm = 0.0;
KINU 3:f70ecf1e21d5 19 _pwm.period(0.001);
KINU 3:f70ecf1e21d5 20 }
KINU 3:f70ecf1e21d5 21
KINU 3:f70ecf1e21d5 22 // Speed Control
KINU 3:f70ecf1e21d5 23 // arg
KINU 3:f70ecf1e21d5 24 // int speed -100 -- 0 -- 100
KINU 3:f70ecf1e21d5 25 void TB6612::speed(int speed) {
KINU 3:f70ecf1e21d5 26
KINU 3:f70ecf1e21d5 27 if( speed > 0 )
KINU 3:f70ecf1e21d5 28 {
KINU 3:f70ecf1e21d5 29 _pwm = ((float)speed) / 100.0;
KINU 3:f70ecf1e21d5 30 _fwd = 1;
KINU 3:f70ecf1e21d5 31 _rev = 0;
KINU 3:f70ecf1e21d5 32 }
KINU 3:f70ecf1e21d5 33 else if( speed < 0 )
KINU 3:f70ecf1e21d5 34 {
KINU 3:f70ecf1e21d5 35 _pwm = -((float)speed) / 100.0;
KINU 3:f70ecf1e21d5 36 _fwd = 0;
KINU 3:f70ecf1e21d5 37 _rev = 1;
KINU 3:f70ecf1e21d5 38 }
KINU 3:f70ecf1e21d5 39 else
KINU 3:f70ecf1e21d5 40 {
KINU 3:f70ecf1e21d5 41 _fwd = 1;
KINU 3:f70ecf1e21d5 42 _rev = 1;
KINU 3:f70ecf1e21d5 43 }
KINU 3:f70ecf1e21d5 44 }
KINU 3:f70ecf1e21d5 45
KINU 3:f70ecf1e21d5 46
KINU 3:f70ecf1e21d5 47 // Speed Control with time-out
KINU 3:f70ecf1e21d5 48 // arg
KINU 3:f70ecf1e21d5 49 // int speed -100 -- 0 -- 100
KINU 3:f70ecf1e21d5 50 // int time 0
KINU 3:f70ecf1e21d5 51 void TB6612::move(int sspeed , int time)
KINU 3:f70ecf1e21d5 52 {
KINU 3:f70ecf1e21d5 53 speed(sspeed);
KINU 3:f70ecf1e21d5 54 wait_ms(time);
KINU 3:f70ecf1e21d5 55 }
KINU 3:f70ecf1e21d5 56
KINU 3:f70ecf1e21d5 57