0Pricing
Arduino & IoT Academy · Lezione

Perché delay() blocca tutto

Scopra come una pausa impedisce alla scheda di reagire.

Perché delay() blocca tutto è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

The Easy Pause

The delay function pauses your sketch for a set number of milliseconds. It is the simplest way to slow things down and make a blink visible.

delay(1000);

What 1000 Means

delay(1000) waits one full second, since the value is in milliseconds. So delay(500) is half a second and delay(2000) is two seconds.

It Freezes the Board

The catch: delay freezes everything. While it waits, your board does nothing else at all, like a person holding their breath. 😮

Missed Button Presses

During a delay your board cannot notice a button press. Tap it mid-pause and the press is simply ignored, which feels broken to a user.

See the Problem

Here a one-second delay sits between the checks, so any press in that whole second is lost before the next read happens.

digitalRead(buttonPin);
delay(1000);

Only One Task at a Time

Because delay blocks, you cannot blink an LED and watch a sensor at the same time. The whole sketch waits as one task.

Stacked Delays Add Up

Two delay calls in a row simply add together. Spread several around and your board spends most of its life frozen and unresponsive.

Fine for Simple Sketches

delay is not evil. For a single blinking LED with nothing else going on, it is perfectly clear and totally fine to use.

The Real Goal

The real goal is a non-blocking sketch that keeps reacting while it also times events. That means never freezing the loop with a long pause.

Think About Time Instead

Instead of pausing, you can ask how much time has passed and act only when enough has gone by. The loop keeps spinning meanwhile.

A Better Tool Is Coming

Soon you will meet millis, a clock that lets you measure elapsed time without freezing. It is how real projects stay responsive.

Quick Check

What is the main drawback of using delay in a sketch?

Recap

You saw that delay is simple but freezes the board, missing inputs and blocking other tasks. Next you will time events without stopping the loop. ✨

Domande Frequenti

La lezione «Perché delay() blocca tutto» è gratuita?

Sì — il testo completo di «Perché delay() blocca tutto» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.

Cosa imparerò in «Perché delay() blocca tutto»?

Scopra come una pausa impedisce alla scheda di reagire. Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Arduino & IoT Academy?

Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.

Quanto tempo richiede la lezione «Perché delay() blocca tutto»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?

Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. int, float, bool su Arduino
  2. Perché delay() blocca tutto
  3. Far lampeggiare un LED senza delay usando millis
  4. Eseguire due attività contemporaneamente
← Torna a Arduino & IoT Academy