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

Dependencies:   BSP_DISCO_L476VG LCD_DISCO_L476VG

Revision:
2:f8e9daaf48b5
Parent:
1:28d1cf3f31f7
Child:
3:b6bfb5955a08
--- a/main.cpp	Mon Oct 19 21:05:49 2020 +0000
+++ b/main.cpp	Tue Oct 20 00:17:29 2020 +0000
@@ -2,7 +2,7 @@
 Description: Base functionality for lighting controller.
 
 Author: Alex Mueller and Marissa Gore
-Date: 10/18/2020
+Date: 10/19/2020
 
 */
 
@@ -14,7 +14,6 @@
 
 
 DigitalOut Ctrl(PA_2);              //Controls relay
-DigitalIn button(PA_0);             //Push button changes display mode
 AnalogIn ain(PA_1);                 //Sensor
 
 LCD_DISCO_L476VG lcd;
@@ -22,7 +21,6 @@
 //Global variables
 float sampledData[10000];
 int numDataSamples = 0;
-//int StateEx = 1;
 
 //Initalize functions
 void SensorValues(float value);
@@ -31,21 +29,18 @@
 int PeakLocation();
 void Counter(int count);
 void Status();
-//void DisplayHandler(int count);
 
 int main()
 {
     float value;
     bool incident = false; 
-    float baseline = 65;             //75cm
+    float baseline = 65;             //65cm
     int count = 0;
     int person;
     uint8_t DisplayedString[7] = {0};
 
    while(1)
    {
-//       printf("%i\n", count*50);
-//       DisplayHandler(count);
        value = 30 * pow(ain.read(), -1.173);
        printf("%f \n", value);
        if(value < baseline)
@@ -58,7 +53,7 @@
             person = PersonId();
             if(person == 1)
             {
-                Ctrl = 1;           //change to set low to turn on relay
+                Ctrl = 0;           //set low to turn on relay
                 count++;
                 Counter(count);
             }
@@ -68,7 +63,7 @@
                 Counter(count);
                 if(count == 0)
                 {
-                    Ctrl = 0;       //change to set high to turn off relay
+                    Ctrl = 1;       //set high to turn off relay
                 }
             }
             incident = false;
@@ -84,11 +79,6 @@
    numDataSamples++;
 }   
 
-////void Timer()
-////{
-////    pizza
-////}
-
 int PeakLocation()
 {
     int min = sampledData[0];     
@@ -108,11 +98,11 @@
 {
     int lowest = PeakLocation();
     
-    if(lowest < (numDataSamples*(1/2)))        // Lowest < midpoint - 10%
+    if(lowest < (numDataSamples*(1/2)))        // Lowest < midpoint
     {
         return -1;
     }
-    else if(lowest > (numDataSamples*(1/2)))  // Lowest > midpoint + 10%
+    else if(lowest > (numDataSamples*(1/2)))  // Lowest > midpoint
     {
         return 1;
     }
@@ -128,40 +118,4 @@
     uint8_t DisplayedString[7] = {0};
     sprintf((char *)DisplayedString, "%d\n", count);
     lcd.DisplayString(DisplayedString);
-    
-//    if(button == 1)
-//    {
-//    StateEx =2;
-//    }
-}
-
-//void Status()
-//{
-//    lcd.Clear();
-//    if(Ctrl == 1)
-//    {
-//         lcd.DisplayString((uint8_t *)"OFF");
-//    }
-//    if(Ctrl == 0)
-//    {
-//         lcd.DisplayString((uint8_t *)"ON");  
-//    }
-//    if(button == 1)
-//    {
-//    StateEx =1;
-//    }
-//}
-
-//void DisplayHandler(int count)
-//{
-//        switch(StateEx)
-//        {
-//            case PersonCount: Counter(count);
-//                            break;
-//            case LEDstatus: Status(); 
-//                            break;
-//            case ErrorState: printf("Error the cookie monster is going to eat you"); 
-//                            break;
-//        }
-//        wait(0.1);
-//}
\ No newline at end of file
+}
\ No newline at end of file