From 53583e8fbf51d1faa6cfe69c7c3573e4179ceec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=B6llendorf?= Date: Thu, 8 Feb 2024 19:43:47 +0100 Subject: [PATCH] Fix detection of crossings using Makeblock RGB Line-Follower Sensor The logic of this sensor is inverted to the logic of the Mindsensors Line-Leader --- .../me_rgb_line_follower_detect_crossing.ino | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/me_rgb_line_follower_detect_crossing/me_rgb_line_follower_detect_crossing.ino b/examples/me_rgb_line_follower_detect_crossing/me_rgb_line_follower_detect_crossing.ino index 0788a59..dd15f94 100644 --- a/examples/me_rgb_line_follower_detect_crossing/me_rgb_line_follower_detect_crossing.ino +++ b/examples/me_rgb_line_follower_detect_crossing/me_rgb_line_follower_detect_crossing.ino @@ -59,9 +59,9 @@ * Each time the result of the bitwise AND operation is greater 0 the Bit is * counted. In the above example the counted number is 3. * - * A crossing may be detected if the number Bits is significantly greater than + * A crossing may be detected if the number Bits is significantly lesser than * the number of sensors covered by the line. Note, that the number of sensors - * covered by the line is also greater if the Line Leader is at an angle to the + * covered by the line is also lesser if the Line Leader is at an angle to the * line. */ #include @@ -79,6 +79,7 @@ void loop() { linefollower.loop(); + /* 4bit value, each set bit denotes sensor faces background */ position = linefollower.getPositionState(); /* line follower hase 4 sensors to check */ @@ -96,13 +97,14 @@ void loop() { Serial.print("Position state: "); Serial.println(position, BIN); Serial.print("Line width: "); - Serial.println(counter); + Serial.println(4 - counter); /** - * if the line normally covers 1 sensor, a counter of 3 or greater is most + * if the line normally covers 1 sensor, a counter of 1 or less is most * likely indicating a crossing */ - if (counter > 2) { + if (counter < 2) { Serial.println("Looks like a crossing!"); } + delay(200); }