The sketch shape in Arduino
Blink: the hello world of hardware, in two functions.
// Every sketch is two functions: setup runs once, loop forever.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
How it works
setup()runs once at power-on;loop()repeats forever.pinModeclaims the pin;digitalWritedrives it HIGH and LOW.delay(500)holds each state for half a second.
Keywords and builtins used here
HIGHLED_BUILTINLOWOUTPUTdelaydigitalWritelooppinModesetupvoid
The run, in numbers
- Lines
- 11
- Characters to type
- 217
- Tokens
- 44
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 35 seconds.
Step 1 of 3 in The sketch, step 1 of 27 in Language basics.