Fully integrated working system

Dependencies:   Speaker mbed mbed-rtos 4DGL-uLCD-SE hcsr04

Files at this revision

API Documentation at this revision

Comitter:
fiachra
Date:
Sat Dec 19 19:04:00 2020 +0000
Parent:
13:a3cdbad9daf4
Commit message:
friday updated ver;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
diff -r a3cdbad9daf4 -r 0bbfa2c1de62 main.cpp
--- a/main.cpp	Thu Dec 17 16:04:27 2020 +0000
+++ b/main.cpp	Sat Dec 19 19:04:00 2020 +0000
@@ -11,12 +11,15 @@
 //general
 Serial pc(USBTX, USBRX);
 uLCD_4DGL uLCD(p9,p10,p11);
-
+//autolights
+AnalogIn photodiode(p20);
+PwmOut myled(p21);
 //distance
 unsigned int dist;
 float averageDistance();
 void beeping();
-float i = 1000;
+float i;
+float x = 0;
 //temp
 void Temperature();
 void TempConstraints();
@@ -31,7 +34,8 @@
 float Temp;
 float a;
 float b;
-    
+//autolights
+void LED();
 
 int main()
 {
@@ -54,16 +58,10 @@
         uLCD.locate(10, 15);
         uLCD.color(WHITE);
         uLCD.printf("cm:%1d\n",dist );
-        
-        //temperature NEED TO FIX THIS
-        if (i > 10)
-        {
-            uLCD.filled_rectangle(0, 0, 126, 80, 0x000000);
-            Temperature();
-            
-            i = 0;
-        }
-        
+        //temperature
+        Temperature();
+        //autolights
+        LED();
     }
 }
 float averageDistance()
@@ -86,39 +84,46 @@
 {
     int distance = averageDistance();
     //sensor defaults to 2k+ when dist<~3cm 
-    if (distance > 2000) i=0.05; 
-    if (distance < 150) i=0.6;
-    if (distance < 100) i=0.55;
-    if (distance < 90) i=0.5;
+    if (distance > 2000) i=1.5; 
+    if (distance < 150) i=0.3;
+    if (distance < 100) i=0.35;
+    if (distance < 90) i=0.4;
     if (distance < 80) i=0.45;
-    if (distance < 70) i=0.4;
-    if (distance < 60) i=0.35;
-    if (distance < 50) i=0.3;
-    if (distance < 40) i=0.25;
-    if (distance < 30) i=0.2;
-    if (distance < 20) i=0.15;
-    if (distance < 10) i=0.1;
-    if (distance < 5) i=0.05;
-    mySpeaker.PlayNote(600, i, 5.0);  
+    if (distance < 70) i=0.5;
+    if (distance < 60) i=0.55;
+    if (distance < 50) i=0.6;
+    if (distance < 40) i=0.65;
+    if (distance < 30) i=0.7;
+    if (distance < 20) i=0.8;
+    if (distance < 10) i=1;
+    if (distance < 5) i=1.2;
+    mySpeaker.PlayNote(700*i, 0.2, 2*i);  
 }
 void Temperature(){
- 
+    
     a = avgTemp();
     b = avgTemp2();
     TempConstraints();
-    Temp = (a + b)/2;
+    Temp = ((a + b)/2)-7;
     uLCD.text_width(1);
     uLCD.text_height(1);
     uLCD.locate(1,1);
     uLCD.printf("%3.1f deg C\n\r", Temp);
+    
 }
  
 void TempConstraints() {
  
     if(degrees_c <= 4){
+        uLCD.text_width(1);
+        uLCD.text_height(1);
+        uLCD.locate(1,1);
         pc.printf("WARNING\nCOLD TEMPERATURES\nICE MAY BE PRESENT");
     }
     if(abs(a-b) > 4){
+        uLCD.text_width(1);
+        uLCD.text_height(1);
+        uLCD.locate(1,1);
         uLCD.printf("WARNING\nTEMPERATURE SENSOR\nFAULT\n");
     }
 }  
@@ -191,4 +196,17 @@
     avgT = (a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t)/20;
     
     return avgT;
+}
+void LED(){
+    
+    if (photodiode*100 <= 27){
+        myled = 1; 
+        uLCD.printf("\nautolights ON ");  
+    } else {
+        myled = 0;
+                uLCD.printf("\nautolights OFF");  
+
+    }
+    
+    
 }
\ No newline at end of file
diff -r a3cdbad9daf4 -r 0bbfa2c1de62 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sat Dec 19 19:04:00 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed-rtos/#5713cbbdb706