cleaned up motor class with separate header and .cpp files

Dependencies:   mbed

Dependents:   TerraBot_Drive_2D TerraBot_Drive_2D TerraBot_Drive_2D_FINAL DUMP_TRUCK_Test ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motor.cpp Source File

Motor.cpp

00001 #include "Motor.h"
00002 
00003 Motor::Motor(PinName pwm, PinName dir) : pwmPin(pwm), dirPin(dir)
00004     {
00005     }
00006 
00007 void Motor::write(float Val)
00008 {
00009       if (Val >= 0) {
00010         dirPin = 1;
00011         pwmPin = Val;
00012         }else {
00013             dirPin = 0;
00014             pwmPin = -1 * Val;
00015     }
00016     lastVal = Val;
00017 }
00018    
00019 float Motor::read()
00020 {
00021         return lastVal;
00022 }