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.
main.cpp
- Committer:
- vctkarthik
- Date:
- 2020-02-11
- Revision:
- 1:0624feb5a279
- Parent:
- 0:7a2e98bb27f5
- Child:
- 2:5e957dcc94bc
File content as of revision 1:0624feb5a279:
#include "mbed.h"
/* for the button press device should start reading, then it should stop the loop for button press */
AnalogIn analog_value(A0);
InterruptIn button(PA_0);
DigitalOut myled(LED1);
bool workState= false;
I2C i2c(PB_11,PB_10); //sda,scl
const int dev_add_W = 0xB6 ; // address with write(0) bit at last////Address must be bit shifted left,
const int reg_To_address = 0x27 ;//temperature of the object pointed
void read_ecg(bool work)
{
float meas_r;
float meas_v;
int temp;
float tempC;
int ack=1;
if(work){
meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
char cmd[2];
char reg[1];
reg[0] = 0x27;
// i2c.write(dev_add_W, 1, true);
// i2c.read(ack);
i2c.write(dev_add_W);
i2c.read(ack);
i2c.write(reg_To_address);
i2c.read(ack);
// write (int address, const char *data, int length, bool repeated=false)
i2c.write(dev_add_W,reg,1,true );
i2c.read(ack);
// read (int address, char *data, int length, bool repeated=false)
i2c.read(dev_add_W, cmd,2,false);
temp = (cmd[1]<<8)|cmd[0];
tempC = (0.02*temp) -273.15;
// Display values
printf("measure = %f = %.0f mV\n", meas_r, meas_v);
//temp =15143;
printf("Temperature : %f \r\n",tempC);
}
}
void toggle()
{
myled = !myled;
workState = !workState;
}
int main() {
button.rise(&toggle) ;
while(1)
{
button.rise(&toggle) ;
read_ecg(workState);
wait(1);
}
}