The Drosophila larval cardiac tube is composed of 104 cardiomyocytes that exhibit genetic and functional diversity. The tube is divided into the aorta and the heart proper that encompass the anterior and posterior parts of the tube, respectively. Differentiation into aorta and heart cardiomyocytes takes place during embryogenesis. We have observed living embryos to correlate morphological changes occurring during the late phases of cardiogenesis with the acquisition of organ function, including functional inlets, or ostiae. Cardiac cells diversity originates in response to two types of spatial information such that cells differentiate according to their position, both within a segment and along the anteroposterior axis. Axial patterning is controlled by homeotic genes of the Bithorax Complex (BXC) which are regionally expressed within the cardiac tube in non-overlapping domains. Ultrabithorax (Ubx) is expressed in the aorta whereas abdominal A (abd-A) is expressed in the heart, with the exception of the four most posterior cardiac cells which express Abdominal B (Abd-B). Ubx and abd-A functions are required to confer an aorta or a heart identity on cardiomyocytes, respectively. The anterior limit of the expression domain of Ubx, abd-A and Abd-B is independent of the function of the other genes. In contrast, abd-A represses Ubx expression in the heart and ectopic overexpression of abd-A transforms aorta cells into heart cardiomyocytes. Taken together, these results support the idea that BXC homeotic genes in the cardiac tube conform to the posterior prevalence rule. The cardiac tube is also segmentally patterned and each metamere contains six pairs of cardioblasts that are genetically diverse. We show that the transcription of seven up (svp), which is expressed in the two most posterior pairs of cardioblasts in each segment, is dependent on hedgehog (hh) signaling from the dorsal ectoderm. In combination with the axial information furnished by abd-A, the segmental hh-dependent information leads to the differentiation of the six pairs of svp-expressing cells into functional ostiae.