Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Lab6_Basic by
main.cpp
- Committer:
- Dogcatfee
- Date:
- 2016-11-19
- Revision:
- 7:10554a04a34f
- Parent:
- 6:a64d79286726
- Child:
- 9:4bd820ca8300
File content as of revision 7:10554a04a34f:
#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*120/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); } }