If you have encoders on your left and right wheels, the difference in values between the two tells you something about the direction your robot is facing. The conversion between encoder counts and robot heading is a function of the wheel circumference and the distance between left and right wheels.
What you will need to do is something like this:
- Continuously compute the robot heading from the encoder values.
- While the buttons aren't pressed, drive normally, but continuously save the current heading + 180 degrees as a target value.
- While the buttons are pressed, turn in whatever direction will make your current heading approach the target.
You'll probably find that the robot overshoots the target and starts oscillating back and forth. That's when you should start learning how to use PID control.