The ball is moved around by mapping the tilting of the screen to a certain range of speeds (in this case from 0 to 3 pixels per loop through the program). In the code the maximum speed is set to the radius of the ball so as to stop the ball from jumping through the walls when it is at top speed.
A maximum speed in any direction is set using a series of if statements which limit the maximum and minimum values which the Arduino will read from the accelerometer.
Stopping the ball from going off the screen is controlled by a series of if statements which limit the maximum and minimum positions of the ball on the screen.
Collision detection is performed by a group of if statements which check four separate subroutines (located under the main program loop).
Each of these subroutines checks a line of pixels running from the outermost pixel of the ball to the center of the ball.
These lines run top-center, bottom-center, right side-center, and left side-center. Every pixel in each line is checked so that even if the ball is moving fast enough that its velocity will carry its outermost pixel into a wall the other pixels in the check line will recognize that the ball is going into the wall and stop it.
Great care was taken so that the size of the ball can be changed by editing a single variable (RAD) and all other attributes of the program will remain the same. The program will work with walls of any thickness.