Orefatoi / Mbed 2 deprecated afero_poc15_171201

Dependencies:   mbed vt100

sensors/PSE530.cpp

Committer:
Rhyme
Date:
2017-12-11
Revision:
10:88e5b8157167
Parent:
0:f0de320e23ac
Child:
11:99eb6741ada4

File content as of revision 10:88e5b8157167:

#include "mbed.h"
#include "PSE530.h"

/**
 * SMC PSE530 pressure sensor
 * analog output 1.0V - 5.0V
 * 1.0V : 0
 * 5.0V : 1MPa
 * (at 0.6V : -0.1MPa)
 * Our sensor I/F converts 0-5V to 0-3V
 * So we suppose V = Analog Float Value : Pressure
 * 0.6V = 0.2 : 0
 * 3.0V = 1.0 : 1MPa
 */
 
 /**
  * conversion from Pa to kgf/cm2
  * 98,066.5 Pa = 1 kgf/cm2
  * 1 Pa = 1 / 98066.6 kgf/cm2
  */

PSE530::PSE530(AnalogIn *ain)
{
    _ain = ain ;
}

PSE530::~PSE530(void) 
{
    if (_ain) {
        delete _ain ;
    }
}

float PSE530::getPressure(void)
{
    float av = 0.0 ;
    float value = 0.0 ;
    av = _ain->read() ;
    printf("Pressure ADC = %.4f\n", av) ;
    value = 1000000 * (1.25 * (av - 0.2)) ; /* 1MPa at 1.0 */
    value = value / 98066.5 ; /* Pa -> kgf/cm2 */
    return( value ) ;
}