Check yourself
Try to answer each question before you open its answer.
About the code
How many times does
setup()run?What does
delay(1000)do?Show the answer
It waits one second.
delaycounts in milliseconds, and 1000 milliseconds make one second. 4
About the registers
These are about step 4. If you skipped it, you can skip them too.
Which register bit is pin 13 on an UNO R3?
Show the answer
PORTB bit 5 (PB5). The UNO’s pin map puts digital pin 13 on PB5. 1
What does
DDRB |= (1 << DDB5);do?Show the answer
It makes pin 13 an output, like
pinMode(13, OUTPUT). A 1 in a pin’s DDxn bit makes that pin an output. 2Why does
PORTB &= ~(1 << PORTB5);leave pins 8 to 12 alone?Show the answer
The AND with an inverted mask clears bit 5 only. Every other bit of the mask is 1, so ANDing keeps those bits as they were.
Next is Lesson 2. You’ll read a knob, and see the number it gives.
All sources for Lesson 1
- ArduinoCore-avr, variants/standard/pins_arduino.h: LED_BUILTIN is 13; pin 13 is PB5
- Microchip ATmega328P datasheet DS40002061A: Pin configurations (p12); I/O ports; PORTB and DDRB at p100
- Arduino reference: digitalWrite
- Arduino reference: delay
- Arduino UNO R3 technical specifications: Built-in LED Pin: 13
- Arduino: Port Manipulation (retired page, written for the ATmega8/168): DDRx, PORTx and PINx
- Arduino reference: setup()
- Arduino reference: loop()
- Arduino reference: pinMode
- Arduino: How to upload a sketch with the Arduino IDE 2
- Arduino reference: // single line comment