From e7ffb6348a07e7326a2b15068be64d22bdcbe3ae Mon Sep 17 00:00:00 2001 From: jonny_ji7 Date: Wed, 17 Aug 2022 07:56:27 +0200 Subject: [PATCH] Calculate distance in cm, Display brightness --- main/main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index 06d1e83..69b04fb 100644 --- a/main/main.c +++ b/main/main.c @@ -31,6 +31,9 @@ #define ENABLE_HALF_STEPS false // Set to true to enable tracking of rotary encoder at half step resolution #define FLIP_DIRECTION false // Set to true to reverse the clockwise/counterclockwise sense +#define MEASURING_ROLL_DIAMETER 44 +#define PI 3.14159265358979323846 + @@ -84,8 +87,13 @@ void task(void *pvParameter) ESP_ERROR_CHECK(max7219_init(&dev)); + //0...15 + ESP_ERROR_CHECK(max7219_set_brightness(&dev, 12)); + + char buf[10]; // 8 digits + decimal point + \0 + int32_t distance_mm = 0; //display startup message max7219_clear(&dev); @@ -110,8 +118,12 @@ void task(void *pvParameter) event.state.direction ? (event.state.direction == ROTARY_ENCODER_DIRECTION_CLOCKWISE ? "CW" : "CCW") : "NOT_SET"); + //--- calculate distalce --- + distance_mm = event.state.position * (MEASURING_ROLL_DIAMETER * PI / 600); //TODO dont calculate constant factor every time //--- show current position on display --- - sprintf(buf, "%08d", event.state.position); + //sprintf(buf, "%08d", event.state.position); + //--- show current distance in cm on display --- + sprintf(buf, "%06.1f cm", (float)distance_mm/10); //printf("float num\n"); max7219_clear(&dev); max7219_draw_text_7seg(&dev, 0, buf);