0Pricing
Arduino & IoT Academy · Lezione

setup() viene eseguita una volta

Il blocco di avvio in cui preparare pin e seriale

setup() viene eseguita una volta è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 1 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.

Two Blocks, Every Sketch

Every Arduino program is built from two functions. The first one is setup(), and getting it right makes everything else click. 🙂

Runs Exactly Once

The big idea: setup() runs a single time, right after your board powers on or resets. It never repeats on its own.

What setup() Looks Like

It is a function with empty parentheses and curly braces. Everything you write between those braces is your startup code.

void setup() {
  // startup code goes here
}

Why void?

The word void means setup returns no value. You are just running commands, not handing a result back to anyone.

Prepare Your Pins

setup is where you announce how each pin behaves. Use pinMode() once here so the board knows a pin sends or receives signals.

void setup() {
  pinMode(13, OUTPUT);
}

Open the Serial Channel

Talking to your computer also starts here. Serial.begin() opens the USB link once, ready for messages later.

void setup() {
  Serial.begin(9600);
}

One-Time Jobs Only

Put things here that should happen a single time: setting pin modes, starting Serial, or initializing a sensor. Setup is your launch checklist.

It Runs First, Always

No matter what else is in your sketch, setup() always runs before any repeating logic. It is the very first thing the board does.

Reset Triggers It Again

Press the board's reset button or cut and restore power, and setup() fires once more. A fresh start means a fresh setup.

Combine Several Lines

You can stack many one-time tasks inside setup. The board runs them top to bottom, then moves on for good.

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

Empty Is Still Valid

A sketch can have an empty setup() if nothing needs preparing. The braces must still be there, even with nothing inside.

void setup() {
}

Quick Check

Let's test how setup() behaves.

Recap: setup()

You learned that setup() runs once at startup, returns void, and is where you prepare pins and Serial. It is your board's launch checklist. 🎉

Domande Frequenti

La lezione «setup() viene eseguita una volta» è gratuita?

Sì — il testo completo di «setup() viene eseguita una volta» è 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 «setup() viene eseguita una volta»?

Il blocco di avvio in cui preparare pin e seriale 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 1 di 4.

Quanto tempo richiede la lezione «setup() viene eseguita una volta»?

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. setup() viene eseguita una volta
  2. loop() viene eseguita per sempre
  3. Commenti e sketch ordinati
  4. Errori di compilazione e come leggerli
← Torna a Arduino & IoT Academy