Added various bits, main reformatted. Added .get to class Servo to allow waiting for rotation before recording information.
Fork of Lab6_Basic by
Diff: main.cpp
- Revision:
- 4:b3a93554fedf
- Parent:
- 3:b787aa49b900
- Child:
- 6:a64d79286726
diff -r b787aa49b900 -r b3a93554fedf main.cpp --- a/main.cpp Mon Sep 19 17:06:45 2016 +0000 +++ b/main.cpp Thu Nov 17 23:15:10 2016 +0000 @@ -1,35 +1,45 @@ #include "mbed.h" #include "Motor.h" #include "Servo.h" -/************************************* Lab5 Motor to servo ***************************/ +/************************************* Lab5 Motor to servo **************************/ /* */ /* File: main.cpp */ /* Author: Ziad Eldebri */ -/* Date Created: 8/19/2016 */ +/* Date Created: 9/19/2016 */ /* Description: */ /* */ /****************************************************************************************/ Servo my_servo(PTB3,PTE19,PTE18,PTE31); +AnalogIn Spanel(PTB2); +uint16_t reading_array[3]; +int position_array[3]={30,75,120}; +uint16_t largest = 0; +int largesti = 0; +int i; int main() { while (1) { +for (i = 0; i < 3; i++){ +my_servo.set(position_array[i]); +wait(3); +reading_array[i] = Spanel.read_u16(); +} -my_servo.set(45); -wait(4); + + + -my_servo.set(65); -wait(4); -my_servo.set(90); -wait(4); - -my_servo.set(135); -wait(4); - -my_servo.set(180); -wait(4); - +for (i = 0; i < 3; i++){ + if (reading_array[i] > largest){ + largest = reading_array[i]; + largesti = i; + + } + } +my_servo.set(position_array[largesti]); +wait(15); } }