Challenge - 5 Problems
Pin Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this pin configuration code?
Consider a microcontroller where setting a bit in the DDR (Data Direction Register) configures the pin as output (1) or input (0). What will be the value of DDRB after running this code?
Embedded C
DDRB = 0x00; DDRB |= (1 << 3); // Set pin 3 as output DDRB &= ~(1 << 1); // Set pin 1 as input
Attempts:
2 left
💡 Hint
Remember that (1 << 3) sets bit 3 and (1 << 1) sets bit 1. |= sets bits, &=~ clears bits.
✗ Incorrect
Initially DDRB is 0x00 (all pins input). Setting bit 3 (pin 3) to 1 makes it output. Clearing bit 1 keeps it input. So only bit 3 is set, which is 0x08 in hex.
🧠 Conceptual
intermediate1:30remaining
Which statement correctly configures pin 5 as input?
Given a DDR register controlling pin directions, which code snippet correctly sets pin 5 as input without changing other pins?
Attempts:
2 left
💡 Hint
Input pins have DDR bit cleared (0). Use bitwise AND with NOT to clear a bit.
✗ Incorrect
To set pin 5 as input, clear bit 5 in DDR. DDR &= ~(1 << 5) clears bit 5 and keeps others unchanged.
🔧 Debug
advanced2:30remaining
Why does this code fail to configure pin 2 as output?
This code is intended to set pin 2 as output by setting bit 2 in DDR. Why does it not work as expected?
DDRB = 0;
DDRB & (1 << 2);
Attempts:
2 left
💡 Hint
Check the operator used to set bits.
✗ Incorrect
Using & does not set bits; it performs bitwise AND. To set a bit, use |= operator.
📝 Syntax
advanced1:30remaining
Which option contains a syntax error in configuring pin 0 as output?
Identify the code snippet that will cause a syntax error when trying to set pin 0 as output.
Attempts:
2 left
💡 Hint
Look for missing parentheses or incomplete expressions.
✗ Incorrect
Option D is missing a closing parenthesis, causing a syntax error.
🚀 Application
expert3:00remaining
How many pins are configured as output after this code runs?
Given DDRC initially 0x00, what is the number of pins configured as output after running this code?
DDRC |= (1 << 0);
DDRC |= (1 << 2);
DDRC &= ~(1 << 0);
DDRC |= (1 << 7);
Attempts:
2 left
💡 Hint
Count bits set to 1 in DDRC after all operations.
✗ Incorrect
Pin 0 is first set then cleared (input). Pins 2 and 7 are set as output. So total 2 pins output.