Check yourself

Try to answer each question before you open its answer.

About the code

  1. How many times does setup() run?

    Show the answer

    Once, each time the board starts or is reset. loop() is the part that runs again and again. 7, 8

  2. What does delay(1000) do?

    Show the answer

    It waits one second. delay counts 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.

  1. 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

  2. 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. 2

  3. Why 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

  1. ArduinoCore-⁠avr, variants/standard/pins_arduino.h: LED_BUILTIN is 13; pin 13 is PB5
  2. Microchip ATmega328P datasheet DS40002061A: Pin configurations (p12); I/O ports; PORTB and DDRB at p100
  3. Arduino reference: digitalWrite
  4. Arduino reference: delay
  5. Arduino UNO R3 technical specifications: Built-⁠in LED Pin: 13
  6. Arduino: Port Manipulation (retired page, written for the ATmega8/168): DDRx, PORTx and PINx
  7. Arduino reference: setup()
  8. Arduino reference: loop()
  9. Arduino reference: pinMode
  10. Arduino: How to upload a sketch with the Arduino IDE 2
  11. Arduino reference: // single line comment