Sometimes, the code works as it’s supposed to be, It (the bot)stops when it reaches the end of the line. Sometimes it keeps going indefinitely, and sometimes and it doesn’t move. This makes no sense to me. I’ve been pulling my hair out as to why it keeps doing this. Any help would be appreciated.
Have you checked the calibration on the photoreceptor? We’ve found them to be quite finicky, especially when you move to a new surface (i.e. some carpets are more reflective than others, and the sensors need retuning).
Try getting the robot up on blocks and letting it run, blocking and unblocking the sensors with your hand.
I don’t see anything particularly wrong with your program itself - the error is probably coming from other sources.
So I’ve noticed that the switch glows green, orange, or no color at all, depending on the surface. How should it be calibrated?
edit: yes, it was a calibration issue. The light has to glow green in order for the switch to be closed. I thought it was supposed to glow between nothing and orange.
No colour at all? That’s a new one to me.
Green means that the light is not being reflected.
Yellow (the light in the middle) means that the light is being reflected.
Orange means that the receptor is being overloaded with light. It shouldn’t be a problem, but it’s not too healthy for the sensor.
With the sensor at the desired distance from the floor, twist the dial on the front (with a screwdriver) until it turns yellow, then turn it back just enough to be green. If you move it over the tape at the same distance away, it should turn yellow. If you move it back onto the non-reflective surface and it is still yellow, it needs to be dialed back just a bit.