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
input_functions.cpp
- Committer:
- Maricius
- Date:
- 2018-06-18
- Revision:
- 1:1f4543ea364d
- Parent:
- 0:45610c4af223
File content as of revision 1:1f4543ea364d:
#include "mbed.h" #include "rtos.h" #include "sMotor.h" AnalogIn heart_rate2(A0); AnalogIn adc_temp(A3); AnalogIn adc_sound(A1); //AnalogIn hymid(A2); DigitalOut myled2(D4); DigitalOut buzzer(D3); //AnalogIn Proximity_measure(A2); void heartrate(); void sound(); void temp(); 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(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){ 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 = 100000; //char temp[10]; 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; //Calculate the temperature from the voltage //temperature = ((a*1000)-500)/10; //sprintf(temp, "%f", a); //resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor; //temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ; //delay(100); } void sound() { float b = adc_sound.read(); char temp_sound[10]; float noiselevel; noiselevel = b; if (noiselevel != 0) { //do something with noiselevel!! } wait(0.1); } /*void proximity(){ double prox_read; while(1){ prox_read = Proximity_measure.read(); wait(0.5); buzzer.write(0); wait(3); } }*/