Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG F746_GUI F7_Ethernet LCD_DISCO_F746NG SimpleSocket TMP36 GZ TS_DISCO_F746NG TextLCD WebSocketClient mbed-rtos mbed sMotor
input_functions.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "sMotor.h" 00004 00005 00006 AnalogIn heart_rate2(A0); 00007 AnalogIn adc_temp(A3); 00008 AnalogIn adc_sound(A1); 00009 //AnalogIn hymid(A2); 00010 DigitalOut myled2(D4); 00011 DigitalOut buzzer(D3); 00012 00013 //AnalogIn Proximity_measure(A2); 00014 void heartrate(); 00015 void sound(); 00016 void temp(); 00017 void smotor(); 00018 00019 void smotor(){ 00020 00021 sMotor motor(D8, D9, D10, D11); 00022 int step_speed = 1000 ; // set default motor speed 00023 int numstep = 1024 ; 00024 motor.step(numstep/1,0,step_speed); 00025 } 00026 00027 double h; 00028 double *h_p = (double*)malloc(1*sizeof(double)); 00029 int heart_rate = 0; 00030 int *beats_per_min = (int*)malloc(1*sizeof(int)); 00031 00032 //Heartrate monitor 00033 void heartrate(){ 00034 int number_of_beats = 0; 00035 float j = 0.0; 00036 h_p = &h; 00037 beats_per_min = &heart_rate; 00038 while (1){ 00039 00040 buzzer = 0; 00041 00042 h = heart_rate2.read(); 00043 if(h>=1.0){ 00044 number_of_beats = number_of_beats + 1; 00045 myled2 = 1; 00046 buzzer = 1; 00047 j = j + 0.3; 00048 wait(0.3); 00049 } 00050 else { 00051 myled2 = 0; 00052 j = j + 0.05; 00053 wait(0.05); 00054 } 00055 //Every 10 sec calculate the heartrate 00056 if(j > 10) { 00057 heart_rate = number_of_beats * 6; 00058 j = 0.0; 00059 number_of_beats = 0; 00060 } 00061 else { 00062 00063 } 00064 00065 00066 00067 } 00068 } 00069 double t; 00070 double *t_p = (double*)malloc(1*sizeof(double)); 00071 00072 void temp(){ 00073 00074 t_p = &t; 00075 //------------------------------------------------------------------------// 00076 //This section is using the external temperatur sensor "Grove temperatur sensor v1.2 00077 //float resistance; 00078 const int B = 4275; 00079 const int R0 = 100000; 00080 //char temp[10]; 00081 double R; 00082 double temp_combined; 00083 double a; 00084 a = adc_temp.read(); 00085 R = 1023.0/a-1.0; 00086 R = R0*R; 00087 t = (a - 0.5)*100; 00088 //t = 1.0/(log(R/R0)/B+1/298.15)-273.15; 00089 //reads the voltage from the analog temperatur sensor 00090 for( int i = 1; i <= 5; i = i + 1 ) { 00091 a = adc_temp.read(); 00092 temp_combined = temp_combined + a; 00093 if(i == 5) { 00094 temp_combined = temp_combined / 5; 00095 R = 1023.0/temp_combined-1.0; 00096 t = 1.0/(log(R)/B+1/298.15)-173.15; 00097 temp_combined = 0; 00098 i = 1; 00099 00100 wait(1); 00101 } else { 00102 wait(1); 00103 } 00104 } 00105 00106 00107 00108 //R = R0*R; 00109 00110 //Calculate the temperature from the voltage 00111 00112 //temperature = ((a*1000)-500)/10; 00113 //sprintf(temp, "%f", a); 00114 //resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor; 00115 //temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ; 00116 //delay(100); 00117 00118 } 00119 00120 00121 void sound() { 00122 float b = adc_sound.read(); 00123 char temp_sound[10]; 00124 float noiselevel; 00125 noiselevel = b; 00126 00127 if (noiselevel != 0) { 00128 00129 //do something with noiselevel!! 00130 00131 } 00132 wait(0.1); 00133 } 00134 00135 /*void proximity(){ 00136 double prox_read; 00137 while(1){ 00138 00139 prox_read = Proximity_measure.read(); 00140 00141 00142 wait(0.5); 00143 00144 buzzer.write(0); 00145 wait(3); 00146 } 00147 00148 }*/ 00149
Generated on Tue Jul 12 2022 19:11:47 by
