Built-in project · no microcontroller

Switch shifter

A 74HC165 loads an 8-way DIP switch at the press of a button and clocks the byte out one bit a second onto an LED. There is no microcontroller in it: the simulator solves the 8 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.

IntermediateRuns in your browser. Free, and no account needed.

Switch shifterlive0.000 s 0.00x
Hold the button
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

How it works

There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.

sketch.ino
// A 74HC165 reading eight switches, slowly enough to watch.
//
// The DIP switch is a byte: switch 1 is bit 0, switch 8 is bit 7, and a
// switch that is on (lever up) is a 1. It starts at 1011 0010.
//
// Press and hold LOAD: PL goes low and the 165 copies all eight switches into
// its register at once. Q7 shows bit 7 right away, so the LED lights for a
// 1 and stays dark for a 0.
//
// Let go, and every rising edge of the 1 Hz clock shifts the register one place
// towards Q7: bit 6, bit 5 ... bit 0 come out on the LED one second at a time,
// most significant first. Then zeros, because DS (the serial input at the far
// end) is tied to ground. Change a switch and press LOAD again.
//
// A microcontroller does exactly this, only fast: pulse PL low, then
// shiftIn(Q7, CP, MSBFIRST) reads the byte with eight clocks. Three pins for
// eight switches, and a second 165 chained off Q7 would make it sixteen.

Parts list

10 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

15 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • 5 V: Resistor, 10k Ω pin 1; 8-way DIP switch pin 8B; 8-way DIP switch pin 7B; 8-way DIP switch pin 6B; 8-way DIP switch pin 5B; 8-way DIP switch pin 4B; 8-way DIP switch pin 3B; 8-way DIP switch pin 2B; 8-way DIP switch pin 1B; 74HC165 input shift register pin VCC
  • Ground: Pushbutton pin 2a; 8-resistor network pin C; 74HC165 input shift register pin GND; 74HC165 input shift register pin DS; 74HC165 input shift register pin CE; LED, green pin C
  • Clock pin OUT; 74HC165 input shift register pin CP
  • Pushbutton pin 1a; Resistor, 10k Ω pin 2
  • Pushbutton pin 1b; 74HC165 input shift register pin PL
  • 8-way DIP switch pin 1A; 8-resistor network pin 8; 74HC165 input shift register pin D0
  • 8-way DIP switch pin 2A; 8-resistor network pin 7; 74HC165 input shift register pin D1
  • 8-way DIP switch pin 3A; 8-resistor network pin 6; 74HC165 input shift register pin D2
  • 8-way DIP switch pin 4A; 8-resistor network pin 5; 74HC165 input shift register pin D3
  • 8-way DIP switch pin 5A; 8-resistor network pin 4; 74HC165 input shift register pin D4
  • 8-way DIP switch pin 6A; 8-resistor network pin 3; 74HC165 input shift register pin D5
  • 8-way DIP switch pin 7A; 8-resistor network pin 2; 74HC165 input shift register pin D6
  • 8-way DIP switch pin 8A; 8-resistor network pin 1; 74HC165 input shift register pin D7
  • 74HC165 input shift register pin Q7; Resistor, 330 Ω pin 1
  • Resistor, 330 Ω pin 2; LED, green pin A

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.