Added various bits, main reformatted. Added .get to class Servo to allow waiting for rotation before recording information.
Fork of Lab6_Basic by
main.cpp
- Committer:
- Dogcatfee
- Date:
- 2016-11-19
- Revision:
- 6:a64d79286726
- Parent:
- 4:b3a93554fedf
- Child:
- 7:10554a04a34f
File content as of revision 6:a64d79286726:
#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: */ /* Edit: Matthew Sessions */ /* */ /*********************************************************************************************/ Servo my_servo(PTB3,PTE19,PTE18,PTE31); AnalogIn Spanel(PTB2); //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; //Serial pc(USBTX, USBRX); int main() { for (i=0; i<size;i++) { position_array[i] = i*180/size +20 ; } while (1) { for (i = 0; i < size; i++) { //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) { 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); } }