software-lösung:

du machst 2 schleifen. vereinfachtes basic:

high-schleife:
if kontkt then goto high-schleife
if nicht kontakt then zähle 1 und goto low-schleife

low-schleife:
if nicht kontakt then goto lowschleife
if kontakt then zähle1 und goto high-schleife



understanding?