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:
- 6:a64d79286726
- Parent:
- 4:b3a93554fedf
- Child:
- 7:10554a04a34f
--- a/main.cpp Fri Nov 18 03:59:01 2016 +0000 +++ b/main.cpp Sat Nov 19 08:32:04 2016 +0000 @@ -1,45 +1,92 @@ #include "mbed.h" #include "Motor.h" #include "Servo.h" -/************************************* Lab5 Motor to servo **************************/ -/* */ -/* File: main.cpp */ -/* Author: Ziad Eldebri */ -/* Date Created: 9/19/2016 */ -/* Description: */ -/* */ -/****************************************************************************************/ +/************************************* Lab5 Motor to servo **********************************/ +/* */ +/* File: main.cpp */ +/* Author: Ziad Eldebri */ +/* Date Created: 9/19/2016 */ +/* Description: */ +/* Edit: Matthew Sessions */ +/* */ +/*********************************************************************************************/ 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; +//uint16_t reading_array[3]; +const int size=20; +unsigned int reading_array[size]; +int position_array[size]; +//uint16_t largest = 0; +unsigned int largest = 0; int largesti = 0; int i; -int main() { +//Serial pc(USBTX, USBRX); + +int main() +{ + + for (i=0; i<size;i++) + { -while (1) { + position_array[i] = i*180/size +20 ; + + } + + while (1) + { + for (i = 0; i < size; i++) + { -for (i = 0; i < 3; i++){ -my_servo.set(position_array[i]); -wait(3); -reading_array[i] = Spanel.read_u16(); -} + //set position + my_servo.set(position_array[i]); + + //pc.printf(" Reading array %d %ld\n ", i , reading_array[i]); + + //check position + + while(1) + { + //one but not both, XOR + if((my_servo.get()-position_array[i] > -25 ) ^ (my_servo.get() - position_array[i] <25)) + { + break; + } + + else + { + my_servo.set(position_array[i]); + wait(.2); + } + + + } + + //write analog values (integers) to array + reading_array[i] = Spanel.read()*10000; + } + for (i = 0; i < size; i++) + { + if (reading_array[i] > largest) + { -for (i = 0; i < 3; i++){ - if (reading_array[i] > largest){ - largest = reading_array[i]; - largesti = i; - + largest = reading_array[i]; + largesti = i; + + } + } + + //pc.printf(" servo pos %d %ld\n ", 0 , my_servo.get()); + //pc.printf(" Largest degree %d %ld\n ", position_array[largesti], reading_array[largesti]); + my_servo.set(position_array[largesti]); + + wait(8); + } -my_servo.set(position_array[largesti]); -wait(15); - } -} +} \ No newline at end of file