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: mbed Nucleo_Sensor_Shield
Revision 2:28f8cd15fca4, committed 2018-04-10
- Comitter:
- selvakumararm
- Date:
- Tue Apr 10 02:48:03 2018 +0000
- Parent:
- 1:be2eea2ae8e7
- Child:
- 3:53d2d440a695
- Commit message:
- Exam Basic Code
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 08 08:11:12 2018 +0000
+++ b/main.cpp Tue Apr 10 02:48:03 2018 +0000
@@ -1,27 +1,12 @@
-/*----------------------------------------------------------------------------
-LAB EXERCISE - Environmental sensors measurments
- ----------------------------------------
- In this exercise we will read the environmental sensors on the Nucleo sensors shield (X-NUCLEO-IKS01A1)
- with the help of the ST Nucleo Sensor Shield library which is compatible with the MBED API.
- Then we will send the measurements via USB to our PC using serial communication.
- We can then display the results using a terminal emulation program (e.g. Termite).
-
- At the same time the program blinks the on board LED to show alivness.
-
- GOOD LUCK!
- *----------------------------------------------------------------------------*/
#include "mbed.h"
#include "x_cube_mems.h"
-// Create a DigitalOut objects for the LED
DigitalOut led(LED1);
-// Create a Serial objects to communicate via USB
Serial pc(USBTX, USBRX);
-// Create 2 Ticker objects for a recurring interrupts. One for blink a LED and the other one to update the sensor lectures periodicly.
Ticker blinky;
Ticker update;
@@ -43,10 +28,10 @@
int main() {
- /* Create a sensor shield object */
+
static X_CUBE_MEMS *Sensors = X_CUBE_MEMS::Instance();
- /* Attach a function to be called by the Ticker objects at a specific interval in seconds*/
+
blinky.attach(&blinky_handler, 0.5);
update.attach(&sensors_handler, 3);
@@ -54,15 +39,13 @@
if(measurements_update == true){
/* Read the environmental sensors */
- Sensors->hts221.GetTemperature((float *)&TEMPERATURE_C);
- Sensors->hts221.GetHumidity((float *)&HUMIDITY);
- Sensors->lps25h.GetPressure((float *)&PRESSURE);
- TEMPERATURE_F = (TEMPERATURE_C * 1.8f) + 32.0f; //Convert the temperature from Celsius to Fahrenheit
- TEMPERATURE_K = (TEMPERATURE_C + 273.15f); //Convert the temperature from Celsius to Kelvin
+ <your code should be here>
+
+
pc.printf("Temperature:\t %.2f C / %.2f F / %.2f K\r\n", TEMPERATURE_C, TEMPERATURE_F, TEMPERATURE_K);
pc.printf("Humidity:\t %.2f%%\r\n", HUMIDITY);
- pc.printf("Pressure:\t %.2f hPa\r\n", PRESSURE);
+
pc.printf("\r\n");