  Our goal in this paper is to derive a carbon-star luminosity function that
will eventually be used to determine distances to galaxies at $50$-$60$ Mpc and
hence yield a value of the Hubble constant. Cool N-type carbon stars exhibit
redder near-infrared colours than oxygen-rich stars. Using Two Micron All Sky
Survey near-infrared photometry and the Gaia Data Release 2, we identify carbon
stars in the Magellanic Clouds (MC) and the Milky Way (MW). Carbon stars in the
MC appear as a distinct horizontal feature in the near-infrared ($(J-K_s)_0$,
$M_J$) colour-magnitude diagram. We build a colour selection ($1.4 < (J-K_s)_0
< 2$) and derive the luminosity function of the colour-selected carbon stars.
We find the median absolute magnitude and the dispersion, in the J band, for
the Large Magellanic Cloud and the Small Magellanic Cloud to be, respectively,
($\bar{M_J} = -6.284 \pm 0.004$, $\sigma = 0.352 \pm 0.005$) and ($\bar{M_J} =
-6.160 \pm 0.015$, $\sigma = 0.365 \pm 0.014$). The difference between the MC
may be explained by the lower metallicity of the Small Magellanic Cloud, but in
any case it provides limits on the type of galaxy whose distance can be
determined with this technique. To account for metallicity effects, we
developed a composite magnitude, named C, for which the error-weighted mean C
magnitude of both the MC are equal. Thanks to the next generation of telescopes
(JWST, ELT, TMT), carbon stars could be detected in MC-type galaxies at
distances out to $50$-$60$ Mpc. The final goal is to eventually try and improve
the measurement of the Hubble constant while exploring the current tensions
related to its value.
