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.
Dependencies: MbedJSONValue SX127x sx12xx_hal
Diff: main.cpp
- Revision:
- 7:803a185d7021
- Parent:
- 6:83bedc32acaf
- Child:
- 8:738ab96d41da
diff -r 83bedc32acaf -r 803a185d7021 main.cpp
--- a/main.cpp Tue Sep 24 21:13:28 2019 +0000
+++ b/main.cpp Tue Sep 24 23:09:39 2019 +0000
@@ -27,9 +27,11 @@
/******************** Setup radio transmitter ****************************/
-// Configure A1 as Analog Input
-AnalogIn sensor(A1);
-float light_val;
+// Analog Sensor setup
+AnalogIn sensor_light(A1);
+AnalogIn sensor_temp(A3);
+double light_val_analog;
+double temperature_analog;
// Configure the User button as an interrupt
InterruptIn button(USER_BUTTON, PullUp);
@@ -41,6 +43,10 @@
MbedJSONValue message;
Timer t;
+// Forward declaration
+float convert_analog_light_resistance(double analog_val);
+float convert_analog_temperature(double analog_val);
+
// Transmit Done Callback Handler
void txDoneCB()
{
@@ -84,7 +90,9 @@
//fill the object
message["btn_count"] = seq;
message["btn_timer"] = t.read();
- message["light_val"] = light_val;
+ message["light_val"] = light_val_analog;
+ message["light_resistance"] = convert_analog_light_resistance(light_val_analog);
+ message["temperature"] = convert_analog_temperature(temperature_analog);
message["my_str"] = "Hello World!";
message["my_boolean"] = false;
@@ -118,6 +126,21 @@
Radio::LoRaPacketConfig(8, false, true, false);
}
+float convert_analog_light_resistance(double analog_val)
+{
+ float Rsensor=(float)(1023-analog_val)*10/analog_val;
+ return Rsensor;
+}
+
+float convert_analog_temperature(double analog_val)
+{
+ double a = analog_val*1023;
+ double resistance=(float)(1023-a)*10000/a;
+ double temperature=1/(log(resistance/10000)/3975+1/298.15)-276.05;
+ double temperature_f = (9.0*temperature)/5.0 + 32.0;
+ return temperature_f;
+}
+
int main()
{
printf("\r\nreset-tx \n");
@@ -134,7 +157,8 @@
while (!txDone)
{
Radio::service();
- light_val = sensor.read();
+ light_val_analog = sensor_light.read();
+ temperature_analog = sensor_temp.read();
}
}
}