Added various bits, main reformatted. Added .get to class Servo to allow waiting for rotation before recording information.

Dependencies:   SLCD mbed

Fork of Lab6_Basic by ECE 111 At Oregon State University

Committer:
ziadeldebri
Date:
Thu Nov 17 23:15:10 2016 +0000
Revision:
4:b3a93554fedf
Parent:
3:b787aa49b900
Child:
6:a64d79286726
Basic Lab6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ziadeldebri 0:61b18b631f94 1 #include "mbed.h"
ziadeldebri 3:b787aa49b900 2 #include "Motor.h"
ziadeldebri 3:b787aa49b900 3 #include "Servo.h"
ziadeldebri 4:b3a93554fedf 4 /************************************* Lab5 Motor to servo **************************/
ziadeldebri 3:b787aa49b900 5 /* */
ziadeldebri 3:b787aa49b900 6 /* File: main.cpp */
ziadeldebri 3:b787aa49b900 7 /* Author: Ziad Eldebri */
ziadeldebri 4:b3a93554fedf 8 /* Date Created: 9/19/2016 */
ziadeldebri 3:b787aa49b900 9 /* Description: */
ziadeldebri 3:b787aa49b900 10 /* */
ziadeldebri 3:b787aa49b900 11 /****************************************************************************************/
ziadeldebri 0:61b18b631f94 12
ziadeldebri 3:b787aa49b900 13 Servo my_servo(PTB3,PTE19,PTE18,PTE31);
ziadeldebri 4:b3a93554fedf 14 AnalogIn Spanel(PTB2);
ziadeldebri 4:b3a93554fedf 15 uint16_t reading_array[3];
ziadeldebri 4:b3a93554fedf 16 int position_array[3]={30,75,120};
ziadeldebri 4:b3a93554fedf 17 uint16_t largest = 0;
ziadeldebri 4:b3a93554fedf 18 int largesti = 0;
ziadeldebri 4:b3a93554fedf 19 int i;
ziadeldebri 3:b787aa49b900 20
ziadeldebri 3:b787aa49b900 21 int main() {
ziadeldebri 3:b787aa49b900 22
ziadeldebri 3:b787aa49b900 23 while (1) {
ziadeldebri 0:61b18b631f94 24
ziadeldebri 4:b3a93554fedf 25 for (i = 0; i < 3; i++){
ziadeldebri 4:b3a93554fedf 26 my_servo.set(position_array[i]);
ziadeldebri 4:b3a93554fedf 27 wait(3);
ziadeldebri 4:b3a93554fedf 28 reading_array[i] = Spanel.read_u16();
ziadeldebri 4:b3a93554fedf 29 }
ziadeldebri 3:b787aa49b900 30
ziadeldebri 4:b3a93554fedf 31
ziadeldebri 4:b3a93554fedf 32
ziadeldebri 4:b3a93554fedf 33
ziadeldebri 3:b787aa49b900 34
ziadeldebri 4:b3a93554fedf 35 for (i = 0; i < 3; i++){
ziadeldebri 4:b3a93554fedf 36 if (reading_array[i] > largest){
ziadeldebri 4:b3a93554fedf 37 largest = reading_array[i];
ziadeldebri 4:b3a93554fedf 38 largesti = i;
ziadeldebri 4:b3a93554fedf 39
ziadeldebri 4:b3a93554fedf 40 }
ziadeldebri 4:b3a93554fedf 41 }
ziadeldebri 4:b3a93554fedf 42 my_servo.set(position_array[largesti]);
ziadeldebri 4:b3a93554fedf 43 wait(15);
ziadeldebri 0:61b18b631f94 44 }
ziadeldebri 3:b787aa49b900 45 }