Code IR sensor counts and controls relay. Erkle grue pizza is good.

Dependencies:   BSP_DISCO_L476VG LCD_DISCO_L476VG

Revision:
3:b6bfb5955a08
Parent:
2:f8e9daaf48b5
Child:
4:742f4fe97790
--- a/main.cpp	Tue Oct 20 00:17:29 2020 +0000
+++ b/main.cpp	Thu Oct 22 21:01:07 2020 +0000
@@ -38,6 +38,7 @@
     int count = 0;
     int person;
     uint8_t DisplayedString[7] = {0};
+    Ctrl = 1;                       //change to 1 for relay
 
    while(1)
    {
@@ -57,7 +58,7 @@
                 count++;
                 Counter(count);
             }
-            else if(person == -1)
+            else if(person == 2)
             {
                 count--;
                 Counter(count);
@@ -69,7 +70,7 @@
             incident = false;
             numDataSamples = 0;
         }
-        ThisThread::sleep_for(5);
+        ThisThread::sleep_for(10);
     }  
 }      
 
@@ -82,7 +83,7 @@
 int PeakLocation()
 {
     int min = sampledData[0];     
-    int saveLow;        
+    int saveLow = 0;        
     for (int i = 1; i < numDataSamples; ++i)       
     {
         if(sampledData[i] < min)         
@@ -91,19 +92,24 @@
             saveLow = i;      
         }   
     }
+//    printf("Min Value: %i of %i \n", saveLow, numDataSamples);
     return saveLow;   
 }
 
 int PersonId()
 {
     int lowest = PeakLocation();
+//    printf("Lowest is %i\n", lowest);
+//    printf("Num data samples is %i\n", numDataSamples);
     
-    if(lowest < (numDataSamples*(1/2)))        // Lowest < midpoint
+    if(lowest < (numDataSamples/2))        // Lowest < midpoint
     {
-        return -1;
+//        printf("This should return 2\n");
+        return 2;
     }
-    else if(lowest > (numDataSamples*(1/2)))  // Lowest > midpoint
+    else if(lowest > (numDataSamples/2))  // Lowest > midpoint
     {
+//        printf("This should return 1\n");
         return 1;
     }
     else