assignment

Dependencies:   BSP_B-L475E-IOT01 mbed

Files at this revision

API Documentation at this revision

Comitter:
giggiux
Date:
Fri Nov 16 14:46:06 2018 +0000
Parent:
1:dce931d77528
Commit message:
assignment;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r dce931d77528 -r 30de7a526b52 main.cpp
--- a/main.cpp	Fri Nov 09 15:39:17 2018 +0000
+++ b/main.cpp	Fri Nov 16 14:46:06 2018 +0000
@@ -7,8 +7,14 @@
 #include "stm32l475e_iot01_magneto.h"
 #include "stm32l475e_iot01_gyro.h"
 #include "stm32l475e_iot01_accelero.h"
+InterruptIn button(USER_BUTTON);
+DigitalOut led(LED1);
 
-DigitalOut led(LED1);
+volatile uint8_t sensor = 0;
+
+void toggle() {
+    sensor = (sensor + 1) % 6;
+}
 
 int main()
 {
@@ -16,6 +22,7 @@
     int16_t pDataXYZ[3] = {0};
     float pGyroDataXYZ[3] = {0};
 
+    button.rise(&toggle); 
     BSP_TSENSOR_Init();
     BSP_HSENSOR_Init();
     
@@ -28,40 +35,48 @@
     while(1) {
 
         led = 1;
-
-        sensor_value = BSP_TSENSOR_ReadTemp();
-        printf("\nTEMPERATURE = %.2f degC\n", sensor_value);
-
-        sensor_value = BSP_HSENSOR_ReadHumidity();
-        printf("HUMIDITY    = %.2f %%\n", sensor_value);
-
-        sensor_value = BSP_PSENSOR_ReadPressure();
-        printf("PRESSURE is = %.2f mBar\n", sensor_value);
-
+        switch (sensor) {
+            case 0:
+                sensor_value = BSP_TSENSOR_ReadTemp();
+                printf("\nTEMPERATURE = %.2f degC\n", sensor_value);
+                break;
+            case 1:
+                sensor_value = BSP_HSENSOR_ReadHumidity();
+                printf("HUMIDITY    = %.2f %%\n", sensor_value);
+                break;
+            case 2:
+                sensor_value = BSP_PSENSOR_ReadPressure();
+                printf("PRESSURE is = %.2f mBar\n", sensor_value);
+                break;
+            case 3:
+                BSP_MAGNETO_GetXYZ(pDataXYZ);
+                printf("\nMAGNETO_X = %d\n", pDataXYZ[0]);
+                printf("MAGNETO_Y = %d\n", pDataXYZ[1]);
+                printf("MAGNETO_Z = %d\n", pDataXYZ[2]);
+                break;
+            case 4:
+                BSP_GYRO_GetXYZ(pGyroDataXYZ);
+                printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]);
+                printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]);
+                printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]);
+                break;
+            case 5:
+                BSP_ACCELERO_AccGetXYZ(pDataXYZ);
+                printf("\nACCELERO_X = %d\n", pDataXYZ[0]);
+                printf("ACCELERO_Y = %d\n", pDataXYZ[1]);
+                printf("ACCELERO_Z = %d\n", pDataXYZ[2]);
+                break;
+            
+            default:
+            break;
+            
+        }
+        wait(1);
         led = 0;
 
-        wait(1);
-
-        led = 1;
-
-        BSP_MAGNETO_GetXYZ(pDataXYZ);
-        printf("\nMAGNETO_X = %d\n", pDataXYZ[0]);
-        printf("MAGNETO_Y = %d\n", pDataXYZ[1]);
-        printf("MAGNETO_Z = %d\n", pDataXYZ[2]);
+        
 
-        BSP_GYRO_GetXYZ(pGyroDataXYZ);
-        printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]);
-        printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]);
-        printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]);
 
-        BSP_ACCELERO_AccGetXYZ(pDataXYZ);
-        printf("\nACCELERO_X = %d\n", pDataXYZ[0]);
-        printf("ACCELERO_Y = %d\n", pDataXYZ[1]);
-        printf("ACCELERO_Z = %d\n", pDataXYZ[2]);
-
-        led = 0;
-
-        wait(1);
 
     }
 }