Breadboard
docs
Example project · Microcontrollers

74HC595 binary counter

An MCU bit-bangs a shift register; four LEDs show the low bits counting up ~10×/second. The Code tab holds the same counter as an editable Arduino sketch.

The 74HC595 binary counter circuit as rendered by the simulator

What's on the bench

  • 4× LED
  • 4× Resistor
  • 74HC595
  • Battery
  • MCU

The code

This Arduino C++ sketch lives in the Code tab; sign in and press Compile & upload to build real firmware for the emulated board.

// The same 74HC595 counter as an Arduino sketch. Edit it, then Compile &
// upload (sign-in needed): the server builds real AVR firmware and flashes it.
const int DS = 2;    // serial data
const int SHCP = 3;  // shift clock
const int STCP = 4;  // latch clock

byte count = 0;

void setup() {
  pinMode(DS, OUTPUT);
  pinMode(SHCP, OUTPUT);
  pinMode(STCP, OUTPUT);
}

void loop() {
  digitalWrite(STCP, LOW);
  shiftOut(DS, SHCP, MSBFIRST, count);  // Q0 = bit 0 ... Q7 = bit 7
  digitalWrite(STCP, HIGH);
  count++;
  delay(100);  // ~10 counts per second
}