Hello. I am new to arduino. I got the bot to work (driving forward using encoders, using the bump sensors, etc…) but I cannot get them to work together. I want the following outcome: once I press the button, the bot will drive straight (encoders) and will use the bump sensors. It might just be a simple fix. I tried using some code that the site provided. Here is my current code…
With my current code, the bot starts driving (once the button is pressed) and the encoders are working (if 1 wheel is getting more rotations, it slows it down). I cannot figure out how to make the bump sensors work with the encoders. I have also tried using just the bump sensors, and it also works. I’m just having trouble getting the encoders and bump sensors to both work.
So there are a few things that may need to be fixed in your code:
Why are your drive functions listed inside your loop() function? I would suggest listing them outside of the loop.
The IF loop that tests the bumpers isn’t nested in your while loop (where all your drive commands are). The program will enter the while loop and perform the listed actions until the false condition is met. Then it’ll pop out and enter the if loop if the bumpers trigger the low state.