Victor Karthik / Mbed 2 deprecated STM32Disco_Melexis

Dependencies:   mbed

Committer:
vctkarthik
Date:
Tue Feb 04 20:57:04 2020 +0000
Revision:
0:7a2e98bb27f5
Child:
1:0624feb5a279
button toggle analog reading is working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vctkarthik 0:7a2e98bb27f5 1 #include "mbed.h"
vctkarthik 0:7a2e98bb27f5 2
vctkarthik 0:7a2e98bb27f5 3 /* for the button press device should start reading, then it should stop the loop for button press */
vctkarthik 0:7a2e98bb27f5 4
vctkarthik 0:7a2e98bb27f5 5 AnalogIn analog_value(A0);
vctkarthik 0:7a2e98bb27f5 6 InterruptIn button(PA_0);
vctkarthik 0:7a2e98bb27f5 7 DigitalOut myled(LED1);
vctkarthik 0:7a2e98bb27f5 8 bool workState= false;
vctkarthik 0:7a2e98bb27f5 9
vctkarthik 0:7a2e98bb27f5 10
vctkarthik 0:7a2e98bb27f5 11 void read_ecg(bool work)
vctkarthik 0:7a2e98bb27f5 12 {
vctkarthik 0:7a2e98bb27f5 13 float meas_r;
vctkarthik 0:7a2e98bb27f5 14 float meas_v;
vctkarthik 0:7a2e98bb27f5 15
vctkarthik 0:7a2e98bb27f5 16 if(work){
vctkarthik 0:7a2e98bb27f5 17 meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
vctkarthik 0:7a2e98bb27f5 18 meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
vctkarthik 0:7a2e98bb27f5 19
vctkarthik 0:7a2e98bb27f5 20 // Display values
vctkarthik 0:7a2e98bb27f5 21 printf("measure = %f = %.0f mV\n", meas_r, meas_v);
vctkarthik 0:7a2e98bb27f5 22 }
vctkarthik 0:7a2e98bb27f5 23
vctkarthik 0:7a2e98bb27f5 24
vctkarthik 0:7a2e98bb27f5 25
vctkarthik 0:7a2e98bb27f5 26
vctkarthik 0:7a2e98bb27f5 27 }
vctkarthik 0:7a2e98bb27f5 28
vctkarthik 0:7a2e98bb27f5 29 void toggle()
vctkarthik 0:7a2e98bb27f5 30 {
vctkarthik 0:7a2e98bb27f5 31 myled = !myled;
vctkarthik 0:7a2e98bb27f5 32 workState = !workState;
vctkarthik 0:7a2e98bb27f5 33
vctkarthik 0:7a2e98bb27f5 34
vctkarthik 0:7a2e98bb27f5 35
vctkarthik 0:7a2e98bb27f5 36
vctkarthik 0:7a2e98bb27f5 37 }
vctkarthik 0:7a2e98bb27f5 38
vctkarthik 0:7a2e98bb27f5 39
vctkarthik 0:7a2e98bb27f5 40
vctkarthik 0:7a2e98bb27f5 41 int main() {
vctkarthik 0:7a2e98bb27f5 42
vctkarthik 0:7a2e98bb27f5 43 button.rise(&toggle) ;
vctkarthik 0:7a2e98bb27f5 44 while(1)
vctkarthik 0:7a2e98bb27f5 45 {
vctkarthik 0:7a2e98bb27f5 46
vctkarthik 0:7a2e98bb27f5 47 button.rise(&toggle) ;
vctkarthik 0:7a2e98bb27f5 48 read_ecg(workState);
vctkarthik 0:7a2e98bb27f5 49
vctkarthik 0:7a2e98bb27f5 50 wait(1);
vctkarthik 0:7a2e98bb27f5 51 }
vctkarthik 0:7a2e98bb27f5 52
vctkarthik 0:7a2e98bb27f5 53
vctkarthik 0:7a2e98bb27f5 54
vctkarthik 0:7a2e98bb27f5 55 }