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:
- 4:b3a93554fedf
- Parent:
- 3:b787aa49b900
- Child:
- 6:a64d79286726
diff -r b787aa49b900 -r b3a93554fedf Servo.cpp --- a/Servo.cpp Mon Sep 19 17:06:45 2016 +0000 +++ b/Servo.cpp Thu Nov 17 23:15:10 2016 +0000 @@ -3,6 +3,7 @@ // gloabl varevlbe used only inseide the class int value_current; int value_target; +int sum; float value_target_raw; Ticker tick; SLCD slcd; @@ -12,6 +13,7 @@ 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 @@ -68,8 +70,14 @@ void Servo::check() { - value_current = (int)((int)(_feedback*1000)*0.30769230769); - n = sprintf (buffer, "%d", value_current); + + for (int j = 0; j < 100; j++){ + sum += _feedback.read_u16(); + } + value_current = sum / 100; + sum = 0; + + n = sprintf (buffer, "%x", value_current); slcd.clear(); slcd.Home(); slcd.printf(buffer);