Added boundary checks on all accesses to the pin modes/values arrays.