Digital Electronics and Microcontroller Basics
What this domain tests
Number systems, logic gates and truth tables, the flip-flop as a memory element, and the block structure and simple programming of a microcontroller.
Rules
- Binary place values are 8 4 2 1. 1011₂ = 11₁₀; 2F₁₆ = 47₁₀.
- AND outputs 1 only when all inputs are 1; OR when any is 1; NOT inverts; NAND and NOR are inverted AND/OR; XOR is 1 when inputs differ.
- A flip-flop stores one bit; a latch is level-sensitive. Registers and counters are built from flip-flops.
- A microcontroller contains a CPU, RAM, non-volatile program memory, timers, I/O ports and often an ADC. It runs a stored program; a microprocessor alone needs external memory and I/O.
- Arduino-style code: setup() runs once, loop() repeats. pinMode sets input or output, digitalWrite drives a pin, digitalRead reads a logic level, analogRead returns a number proportional to voltage.
- Use a transistor or driver for loads above the pin's current limit; never drive a motor directly from an I/O pin.
Worked example
A switch on pin 7 should light an LED on pin 9 only when pressed. Configure pin 7 as INPUT_PULLUP and pin 9 as OUTPUT. In loop(), read pin 7; because of the pull-up, a pressed switch reads LOW. So write: if digitalRead(7) == LOW, digitalWrite(9, HIGH); else digitalWrite(9, LOW). Add a 220 Ω resistor in series with the LED.
Traps
- Confusing bit order or place values.
- Assuming an unconnected input reads 0; it floats.
- Forgetting that a pull-up inverts the logic.
- Driving an LED without a resistor or a motor without a driver.