ENEL400 / Mbed 2 deprecated Sensors

Dependencies:   SX1276Lib_inAir mbed

Fork of Sensors by ENEL400

Committer:
Razorfoot
Date:
Wed Aug 10 03:22:58 2016 +0000
Revision:
1:059293827555
Parent:
0:b4b76706c8c3
Child:
2:804e04f4f217
tidy up the code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Razorfoot 1:059293827555 1 #include <stdio.h>
Razorfoot 0:b4b76706c8c3 2 #include "mbed.h"
Razorfoot 0:b4b76706c8c3 3 #include "sx1276-inAir.h"
Razorfoot 0:b4b76706c8c3 4
Razorfoot 1:059293827555 5 #define STRING_LENGTH 10
Razorfoot 1:059293827555 6 #define SUPPLY_VOLTAGE 3.3
Razorfoot 1:059293827555 7
Razorfoot 0:b4b76706c8c3 8 Serial pc(USBTX, USBRX); //Create a serial connection to the PC
Razorfoot 0:b4b76706c8c3 9 AnalogIn ain(PA_0); //Configure pin PA0 as an analog input for the temperature sensor
Razorfoot 0:b4b76706c8c3 10 //DigitalIn din(PC_7); //Configure pin PC2 as a digital input for the reed switch
Razorfoot 0:b4b76706c8c3 11
Razorfoot 0:b4b76706c8c3 12 float reading_float;
Razorfoot 0:b4b76706c8c3 13
Razorfoot 0:b4b76706c8c3 14 //Return the temperature from the sensor, in degrees celsius
Razorfoot 0:b4b76706c8c3 15 float get_temp() {
Razorfoot 0:b4b76706c8c3 16 float reading = ain.read();
Razorfoot 0:b4b76706c8c3 17 float output_voltage = reading * SUPPLY_VOLTAGE;
Razorfoot 0:b4b76706c8c3 18 return (output_voltage - 0.25) / 0.028;
Razorfoot 0:b4b76706c8c3 19 }
Razorfoot 0:b4b76706c8c3 20
Razorfoot 0:b4b76706c8c3 21 /*//Return the state of the reed switch, as either true (ON) or false (OFF)
Razorfoot 0:b4b76706c8c3 22 bool get_reed_state() {
Razorfoot 0:b4b76706c8c3 23 return din;
Razorfoot 0:b4b76706c8c3 24 }*/
Razorfoot 0:b4b76706c8c3 25
Razorfoot 0:b4b76706c8c3 26 int main() {
Razorfoot 0:b4b76706c8c3 27
Razorfoot 0:b4b76706c8c3 28 //Configure the serial connection (baud rate = 19200, 8 data bits, 1 stop bit)
Razorfoot 0:b4b76706c8c3 29 pc.baud(9600);
Razorfoot 0:b4b76706c8c3 30 pc.format(8, SerialBase::None, 1);
Razorfoot 0:b4b76706c8c3 31
Razorfoot 0:b4b76706c8c3 32 while(1) {
Razorfoot 0:b4b76706c8c3 33
Razorfoot 1:059293827555 34 char reading_string[10];
Razorfoot 0:b4b76706c8c3 35 reading_float = get_temp();
Razorfoot 1:059293827555 36 sprintf(reading_string, "%.8f\r\n", reading_float);
Razorfoot 1:059293827555 37 pc.printf(reading_string);
Razorfoot 1:059293827555 38 //pc.printf("Temperature = %.2f \r\n\r\n", reading_float);
Razorfoot 0:b4b76706c8c3 39
Razorfoot 0:b4b76706c8c3 40 wait_ms(500);
Razorfoot 0:b4b76706c8c3 41
Razorfoot 0:b4b76706c8c3 42 /*if (get_reed_state()) {
Razorfoot 0:b4b76706c8c3 43 pc.printf("Reed switch is ON\r\n");
Razorfoot 0:b4b76706c8c3 44 }
Razorfoot 0:b4b76706c8c3 45 else {
Razorfoot 0:b4b76706c8c3 46 pc.printf("Reed switch is OFF\r\n");
Razorfoot 0:b4b76706c8c3 47 }
Razorfoot 0:b4b76706c8c3 48 wait_ms(500);*/
Razorfoot 0:b4b76706c8c3 49
Razorfoot 0:b4b76706c8c3 50 }
Razorfoot 0:b4b76706c8c3 51 }