Andrew Holden / Mbed 2 deprecated Servo_ScaleFD

Dependencies:   mbed Servo

Files at this revision

API Documentation at this revision

Comitter:
andrewh2104
Date:
Thu Mar 04 18:55:27 2021 +0000
Parent:
0:54315b1ea3ff
Commit message:
v1.1

Changed in this revision

Servo.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 54315b1ea3ff -r 41e66334a2bb Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Thu Mar 04 18:55:27 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/jasonberry/code/Servo/#0ff49e165c90
diff -r 54315b1ea3ff -r 41e66334a2bb main.cpp
--- a/main.cpp	Tue Mar 02 14:05:08 2021 +0000
+++ b/main.cpp	Thu Mar 04 18:55:27 2021 +0000
@@ -1,13 +1,14 @@
-//------------Face Detection-------------//
-//Scale and X-axis to corresponding LED's//
-//--------Incl. Bluetooth Serial---------//
-//--------Andrew Holden - 11/2/21--------//
-//------For 640x480 resolution only------//
+//------------Face Detection--------------//
+//Scale and X-axis to corresponding Servos//
+//--------Incl. Bluetooth Serial----------//
+//--------Andrew Holden - 04/3/21---------//
+//----------For all resolutions-----------//
 
 #include "mbed.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "iostream"
+#include "Servo.h"
 
 using namespace std;
 
@@ -17,15 +18,13 @@
 Serial blue(p9, p10);          // TX, RX           
 #endif
 
-PwmOut led1(LED1);
-PwmOut led2(LED2);
-PwmOut led3(LED3);
-PwmOut led4(LED4);
+Servo myservo1(p21);
+Servo myservo2(p22);
 
-float brightness = 0.0;
-float blevel;               //brightness between 0-1
-int area;                   //number between 0-640 
-float round(float blevel)   //round to 2 dec. places
+float servo = 0.0;
+float svscale;               //face scale between 0-1
+float svpos;                 //x-axis pos. between 0-1 
+float round(float svscale)   //round to 2 dec. places
 
 { 
     // EXAMPLE:
@@ -33,7 +32,7 @@
     // 3766.66 + .5 =3767.16    for rounding off value 
     // then type cast to int so value is 3767 
     // then divided by 100 so the value converted into 37.67 
-    float value = (int)(blevel * 100 + .5); 
+    float value = (int)(svscale * 100 + .5); 
     return (float)value / 100; 
 } 
 
@@ -43,46 +42,30 @@
     {
         //blue.baud(115200);
         //pc.baud(115200);
-        //cout <<"Set Brightness to: " << "Area:";
        
-        if(cin >> blevel >> area)
+        if(cin >> svscale >> svpos)
         {
-            brightness = blevel;
+            servo = svscale;
             
-            if(0 <= area && area < 160)
+            if(0.00 <= svscale && svscale < 1.00)
             {
-                led1 = brightness;
+                myservo2 = servo;
             }
             else 
             {
-                led1 = 0;
+                myservo2 = 0.5;     //home position
             }
             
-            if(160 <= area && area < 320)
-            {
-                led2 = brightness;
-            }
-            else
+            servo = svpos;
+            
+            if(0.00 <= svpos && svpos < 1.00)
             {
-                led2 = 0;
-            }
-            if(320 <= area && area < 480)
-            {
-                led3 = brightness;
+                myservo1 = servo;
             }
-            else
-            {
-                led3 = 0;
-            }
-            if(480 <= area && area < 640)
+            else 
             {
-                led4 = brightness;
-            }
-            else
-            {
-                led4 = 0;
+                myservo1 = 0.5;     //home position
             }
         }
-        //cout << "Brightness set: \n\r" << round(blevel) << endl;
     }
 }
\ No newline at end of file