Tidied up and commented
Set index pin to resistive pull-up to avoid random resets