Memorize

What I would do first is to make a class that can deal with buttons.

Don't forget that PS3 controller buttons are analogue pressure sensors and don't just give a pressed/not-pressed response.