motor i senzor

Dependencies:   TextLCD mbed PinDetect

Committer:
mdraganic
Date:
Sat Nov 09 06:49:43 2013 +0000
Revision:
1:3500bf8487d0
Child:
3:bebfc64cefe4
added pwm motor driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mdraganic 1:3500bf8487d0 1 #include "Motor.h"
mdraganic 1:3500bf8487d0 2
mdraganic 1:3500bf8487d0 3 Motor::Motor() : positiveOut(NC), negativeOut(NC) {
mdraganic 1:3500bf8487d0 4 }
mdraganic 1:3500bf8487d0 5
mdraganic 1:3500bf8487d0 6 Motor::Motor(PinName positivePin, PinName negativePin):
mdraganic 1:3500bf8487d0 7 positiveOut(positivePin), negativeOut(negativePin) {
mdraganic 1:3500bf8487d0 8 }
mdraganic 1:3500bf8487d0 9
mdraganic 1:3500bf8487d0 10 void Motor::movePositive() {
mdraganic 1:3500bf8487d0 11
mdraganic 1:3500bf8487d0 12 direction = 1;
mdraganic 1:3500bf8487d0 13 move();
mdraganic 1:3500bf8487d0 14 }
mdraganic 1:3500bf8487d0 15
mdraganic 1:3500bf8487d0 16 void Motor::moveNegative() {
mdraganic 1:3500bf8487d0 17
mdraganic 1:3500bf8487d0 18 direction = -1;
mdraganic 1:3500bf8487d0 19 move();
mdraganic 1:3500bf8487d0 20 }
mdraganic 1:3500bf8487d0 21
mdraganic 1:3500bf8487d0 22 void Motor::move() {
mdraganic 1:3500bf8487d0 23
mdraganic 1:3500bf8487d0 24 positiveOut = 0;
mdraganic 1:3500bf8487d0 25 negativeOut = 0;
mdraganic 1:3500bf8487d0 26
mdraganic 1:3500bf8487d0 27 switch(direction) {
mdraganic 1:3500bf8487d0 28 case 0:
mdraganic 1:3500bf8487d0 29 return;
mdraganic 1:3500bf8487d0 30 case 1:
mdraganic 1:3500bf8487d0 31 positiveOut = 1;
mdraganic 1:3500bf8487d0 32 break;
mdraganic 1:3500bf8487d0 33 case -1:
mdraganic 1:3500bf8487d0 34 negativeOut = 1;
mdraganic 1:3500bf8487d0 35 break;
mdraganic 1:3500bf8487d0 36 }
mdraganic 1:3500bf8487d0 37
mdraganic 1:3500bf8487d0 38 direction = 0;
mdraganic 1:3500bf8487d0 39 wait_ms(motorDriveTime);
mdraganic 1:3500bf8487d0 40 }
mdraganic 1:3500bf8487d0 41
mdraganic 1:3500bf8487d0 42 void Motor::stop() {
mdraganic 1:3500bf8487d0 43
mdraganic 1:3500bf8487d0 44 positiveOut = 0;
mdraganic 1:3500bf8487d0 45 negativeOut = 0;
mdraganic 1:3500bf8487d0 46 direction = 0;
mdraganic 1:3500bf8487d0 47 }