Mechanical device provided with a first and a second mutually movable mechanical member, a track (1) formed by several optical sections (2) being obtained on the second member. The sections (2) are of two types with different
optical contrast, distributed according to a predetermined bit number pseudo-random code. The mechanical device is provided with a sensor (3) comprising several
optical transducers (5), spaced with a resolution (R) equal to or less than half the width (L) of a section (2) and arranged for framing a measurement window (6) on the track (1) extended for a number of sections (2) equal to the predetermined bit number and for each generating a measurement
signal. Furthermore, the mechanical device comprises an
electronic unit, configured for associating, with each section (2) in the measurement window (6), a corresponding group (G) formed by a first and a second optical
transducer (5', 5") and by at least a third optical
transducer (5"') interposed therebetween. The
electronic unit is configured for associating, with the measurement signals of the first, second and third
optical transducers (5', 5", 5"') at least a first, a second and a third comparison parameter, respectively. The
electronic unit is configured for comparing these parameters in order to identify the coinciding ones and, if most of them are coinciding, to obtain, as a function of their measurement signals, a position binary number having a number of bits equal to the predetermined bit number, in which each bit corresponds to a group (G). Furthermore, the electronic unit is configured for associating the position binary number with a position of the second member.