bunch of tesitng for F746NG

Dependencies:   BSP_DISCO_F746NG F746_GUI F7_Ethernet LCD_DISCO_F746NG SimpleSocket TMP36 GZ TS_DISCO_F746NG TextLCD WebSocketClient mbed-rtos mbed sMotor

Revision:
1:1f4543ea364d
Parent:
0:45610c4af223
--- a/input_functions.cpp	Mon Dec 11 09:46:58 2017 +0000
+++ b/input_functions.cpp	Mon Jun 18 13:16:23 2018 +0000
@@ -1,46 +1,114 @@
 #include "mbed.h"
 #include "rtos.h"
+#include "sMotor.h"
 
 
 AnalogIn heart_rate2(A0);
 AnalogIn adc_temp(A3);
 AnalogIn adc_sound(A1);
-//AnalogOut buzzer(D4);
+//AnalogIn hymid(A2);
+DigitalOut myled2(D4);
+DigitalOut buzzer(D3);
+
 //AnalogIn Proximity_measure(A2);
 void heartrate();
 void sound();
 void temp();
-//void write_to_socket();
-//void proximity();
+void smotor();
+
+void smotor(){
+ 
+    sMotor motor(D8, D9, D10, D11);   
+    int step_speed = 1000 ; // set default motor speed
+    int numstep = 1024 ;
+    motor.step(numstep/1,0,step_speed);
+}
 
     double h;
-    double *h_p = (double*)malloc(20*sizeof(double));
+    double *h_p = (double*)malloc(1*sizeof(double));
+    int heart_rate = 0;
+    int *beats_per_min = (int*)malloc(1*sizeof(int));
     
+    //Heartrate monitor
  void heartrate(){
-      
+    int number_of_beats = 0;
+    float j = 0.0;  
     h_p = &h;
+    beats_per_min = &heart_rate;
     while (1){
-    h = heart_rate2.read();
-    wait(0.1);
+    
+    buzzer = 0;
+    
+    h = heart_rate2.read();    
+    if(h>=1.0){
+        number_of_beats = number_of_beats + 1;
+        myled2 = 1;
+        buzzer = 1;
+        j = j + 0.3;
+        wait(0.3);
+        } 
+    else {
+        myled2 = 0;
+        j = j +  0.05;
+        wait(0.05);    
         }
+        //Every 10 sec calculate the heartrate
+    if(j > 10) {
+        heart_rate = number_of_beats * 6;
+        j = 0.0;
+        number_of_beats = 0;
+        }
+    else {
+            
+        }
+            
+        
+        
+    }
 }
+    double t;
+    double *t_p = (double*)malloc(1*sizeof(double));
 
 void temp(){
+    
+    t_p = &t;
     //------------------------------------------------------------------------//
         //This section is using the external temperatur sensor "Grove temperatur sensor v1.2
         //float resistance;
         const int B = 4275;
-        //const int R0 = 10000;
+        const int R0 = 100000;
         //char temp[10];
-        
-        //reads the voltage from the analog temperatur sensor
-        double a = adc_temp.read();
         double R;
+        double temp_combined;
+        double a; 
+        a = adc_temp.read();
         R = 1023.0/a-1.0;
+        R = R0*R;
+        t = (a - 0.5)*100;
+        //t  = 1.0/(log(R/R0)/B+1/298.15)-273.15;
+        //reads the voltage from the analog temperatur sensor
+        for( int i = 1; i <= 5; i = i + 1 ) {
+            a = adc_temp.read();
+            temp_combined = temp_combined + a;
+            if(i == 5) {
+                temp_combined = temp_combined / 5;
+                R = 1023.0/temp_combined-1.0;     
+                t  = 1.0/(log(R)/B+1/298.15)-173.15;
+                temp_combined = 0;
+                i = 1;
+                
+                wait(1);
+            } else {
+                wait(1);
+                }
+        }
+        
+        
+        
         //R = R0*R;
-        double temperature;
+        
         //Calculate the temperature from the voltage
-        temperature  = 1.0/(log(R)/B+1/298.15)-173.15;
+        
         //temperature = ((a*1000)-500)/10;
         //sprintf(temp, "%f", a);
         //resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
@@ -55,22 +123,14 @@
         char temp_sound[10];
         float noiselevel;
         noiselevel = b;
-        //if the sound sensor is detection any noise a LED is switched on and a message with the current sound level is displayed.
+        
         if (noiselevel != 0) {
 
             //do something with noiselevel!!
             
         }
-
-        //external_LCD.DisplayStringAt(0, LINE(1), (uint8_t *)"This is just a test", CENTER_MODE);
         wait(0.1);
     }
-    
-    
-    
-//void write_to_stocket(){
-    
- //   }
 
 /*void proximity(){
     double prox_read;