Hello there

Dependencies:   PM2_Libary

Revision:
19:22e264bd960d
Parent:
18:21de1a131213
Child:
20:c52e148d933f
--- a/main.cpp	Tue Mar 15 10:40:22 2022 +0100
+++ b/main.cpp	Wed Mar 16 10:09:30 2022 +0000
@@ -25,7 +25,7 @@
 
 // Sharp GP2Y0A41SK0F, 4-40 cm IR Sensor
 float ir_distance_mV = 0.0f;    // define variable to store measurement
-// ???    // create AnalogIn object to read in infrared distance sensor, 0...3.3V are mapped to 0...1
+AnalogIn ir_analog_in(PC_2);   // create AnalogIn object to read in infrared distance sensor, 0...3.3V are mapped to 0...1
 
 int main()
 {
@@ -34,7 +34,6 @@
     user_button.rise(&user_button_released_fcn);
 
     // start timers
-    user_button_timer.start();
     main_task_timer.start();
 
     // set pullup mode: add resistor between pin and 3.3 V, so that there is a defined potential
@@ -47,7 +46,7 @@
         if (do_execute_main_task) {
 
             // read analog input
-            // ???
+            ir_distance_mV = 1.0e3f * ir_analog_in.read() * 3.3f;
 
             // if the mechanical button is pressed the extra led is blinking
             if (mechanical_button) {
@@ -77,6 +76,7 @@
 
 void user_button_pressed_fcn()
 {
+    user_button_timer.start();
     user_button_timer.reset();
 }