# Reto 4 Intruso

Estamos hartos que los jabalíes vengan a estropearnos la cosecha, vamos a asustarlos si se acercan

Enunciado

Si se acerca un objeto a menos de 20 cm a nuestra cosecha, que suene la alarma

Solución

Añadimos una variable DISTANCIA y lo ponemos en la función de vissualizar

[![prog-animal.png](https://libros.catedu.es/uploads/images/gallery/2026-09/scaled-1680-/prog-animal.png)](https://libros.catedu.es/uploads/images/gallery/2026-09/prog-animal.png)

y el resto de programa es MUY SENCILLO PUES APROVECHAMOS LA FUNCIÓN ALARMA

[![PROGRAMAANIMAL.png](https://libros.catedu.es/uploads/images/gallery/2026-09/scaled-1680-/programaanimal.png)](https://libros.catedu.es/uploads/images/gallery/2026-09/programaanimal.png)

<p class="callout success">AQUÍ PODEMOS APROVECHAR PARA ENFATIZAR EL VALOR DE REUTILIZAR CÓDIGO</p>

[https://makecode.microbit.org/S51550-75797-73915-29343](https://makecode.microbit.org/S51550-75797-73915-29343)

<div id="bkmrk--2" style="position: relative; height: 0; padding-bottom: 70%; overflow: hidden;"><iframe frameborder="0" sandbox="allow-popups allow-forms allow-scripts allow-same-origin" src="https://makecode.microbit.org/#pub:S51550-75797-73915-29343" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe>

</div><div id="bkmrk--3" style="position: relative; height: 0; padding-bottom: 70%; overflow: hidden;"><iframe allowfullscreen="allowfullscreen" height="314" src="https://www.youtube.com/embed/ONQbYVmu7W4" width="560"></iframe>

</div>