Repository for verBOT robot project, hopefully featuring two branches: Dev/Test and Prod.
Dependencies: PM2_Libary Eigen
Diff: main.cpp
- Revision:
- 46:e9d929bae82d
- Parent:
- 45:efab79252438
--- a/main.cpp Wed May 18 06:53:47 2022 +0000 +++ b/main.cpp Tue May 24 09:19:20 2022 +0200 @@ -6,6 +6,7 @@ # define M_PI 3.14159265358979323846 // number pi // adding the first comment of the semester +// adding a testing comment // logical variable main task bool do_execute_main_task = false; // this variable will be toggled via the user button (blue button) to or not to execute the main task @@ -28,6 +29,10 @@ // led on nucleo board DigitalOut user_led(LED1); // create DigitalOut object to command user led + AnalogIn ir_analog_in(PC_2); // create AnalogIn for IR sensor calibration + float ir_distance_mV = 0.0f; + float ir_distance_cm = 0.0f; + // attach button fall and rise functions to user button object user_button.fall(&user_button_pressed_fcn); user_button.rise(&user_button_released_fcn); @@ -39,7 +44,10 @@ main_task_timer.reset(); - + // reads IR sensor's raw value, AnalogIn/Out normalized to 1 (read between 0-3.3 V) + ir_distance_mV = ir_analog_in.read() * 3.3f * 1.0e3f; + + if (do_execute_main_task) { } else { @@ -52,6 +60,8 @@ } main_task_cntr++; + printf("IR Sensor (mV): %f\r\n", ir_distance_mV); + // do only output via serial what's really necessary (this makes your code slow) /* printf("IR sensor (mV): %3.3f, IR sensor (cm): %3.3f, SensorBar angle (rad): %3.3f, Speed M1 (rps) %3.3f, Position M2 (rot): %3.3f\r\n",