Code for collecting sensor data

Dependencies:   SX1276Lib_inAir mbed

Fork of Sensors by ENEL400

main.cpp

Committer:
Razorfoot
Date:
2016-08-10
Revision:
0:b4b76706c8c3
Child:
1:059293827555

File content as of revision 0:b4b76706c8c3:

#include "mbed.h"
#include "sx1276-inAir.h"

Serial      pc(USBTX, USBRX);  //Create a serial connection to the PC
AnalogIn    ain(PA_0);             //Configure pin PA0 as an analog input for the temperature sensor
//DigitalIn     din(PC_7);         //Configure pin PC2 as a digital input for the reed switch

const float SUPPLY_VOLTAGE = 3.3;
float reading_float;
int reading_int;

//Return the temperature from the sensor, in degrees celsius
float get_temp() {
    float reading = ain.read();
    float output_voltage = reading * SUPPLY_VOLTAGE;
    return (output_voltage - 0.25) / 0.028;
}

/*//Return the state of the reed switch, as either true (ON) or false (OFF)
bool get_reed_state() {
    return din;
}*/

int main() {

    //Configure the serial connection (baud rate = 19200, 8 data bits, 1 stop bit)
    pc.baud(9600);
    pc.format(8, SerialBase::None, 1);

    while(1) {

        reading_float = get_temp();
        reading_int = (int)(reading_float);
        pc.printf("Temperature = %d \r\n\r\n", reading_int);

        wait_ms(500);

        /*if (get_reed_state()) {
            pc.printf("Reed switch is ON\r\n");
        }
        else {
            pc.printf("Reed switch is OFF\r\n");
        }
        wait_ms(500);*/

    }
}