Added various bits, main reformatted. Added .get to class Servo to allow waiting for rotation before recording information.
Fork of Lab6_Basic by
Diff: Servo.cpp
- Revision:
- 8:c2f0e524696b
- Parent:
- 6:a64d79286726
--- a/Servo.cpp Sat Nov 19 09:06:16 2016 +0000 +++ b/Servo.cpp Sat Nov 19 09:10:23 2016 +0000 @@ -1,10 +1,8 @@ #include "mbed.h" #include "Servo.h" - //added .get() to approximate position // gloabl varevlbe used only inseide the class int value_current; int value_target; -int sum; float value_target_raw; Ticker tick; SLCD slcd; @@ -14,7 +12,6 @@ Servo::Servo(PinName analog_input,PinName Positive, PinName Negative,PinName Speed): _feedback(analog_input),_motor(Positive,Negative,Speed) { - sum=0; } /* input is angle intger from 0 - 180 @@ -63,22 +60,22 @@ slcd.printf(buffer); } + } - + unsigned int Servo::get() + { + value_current = (int)((int)(_feedback*1000)*0.30769230769); + // n = sprintf (buffer, "%d", value_current); + return value_current; + } void Servo::check() { - - for (int j = 0; j < 100; j++){ - sum += _feedback.read_u16(); - } - value_current = sum / 100; - sum = 0; - - n = sprintf (buffer, "%x", value_current); + value_current = (int)((int)(_feedback*1000)*0.30769230769); + n = sprintf (buffer, "%d", value_current); slcd.clear(); slcd.Home(); slcd.printf(buffer);