Optical pulsations from a transitional millisecond pulsar