/*  1821 - 8 LEDs controlled by one 595 shift register
 * 
 * This sketch shows you how to drive 8 outputs (connected to LEDs) using a three digital
 * pins on the Arduino. This is done with the help of a 595 shift register.
 * 
 * The sketch causes the LEDs to light up randomly.
 * 
 * This sketch was written by Peter Dalmaris for Arduino Step by Step.
 * 
 * Components
 * ----------
 *  - Arduino Uno
 *  - 8 x 330 Ohm resistor for the LEDs
 *  - 1 x 74HC595 shift register
 *  - Breadboard
 *  - Jumper wires
 *  
 *  Libraries
 *  ---------
 *  - None
 *
 * Connections
 * -----------
*  Arduino Uno and 74HC959:
 *  
 *  Arduino Uno   |     74HC959
 *  ------------------------------
 *        5V      |       16
 *        GND     |       8
 *        8       |       14 
 *        9       |       12
 *        10      |       11
 *        
 *        
 *  74HC959 and LEDs:
 *  
 *  Connect 595 pins 1 to 7 and 15 to the LEDS via their current limiting resistors.
 *     
 *  
 *  
 *  Created on May 13 2017 by Peter Dalmaris
 * 
 */

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 9;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 10;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 8;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  randomSeed(analogRead(0));

}

void loop() {
  byte randNumber1 = random(255);
  writeLeds(randNumber1);
  delay(100);  
}

void writeLeds(byte pattern)
{
  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);

  // shift the bits out:
  shiftOut(dataPin, clockPin, MSBFIRST, pattern);

    // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
  }

$abcdeabcde151015202530fghijfghij
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
74HC595
sr1:Q1
sr1:Q2
sr1:Q3
sr1:Q4
sr1:Q5
sr1:Q6
sr1:Q7
sr1:GND
sr1:Q7S
sr1:MR
sr1:SHCP
sr1:STCP
sr1:OE
sr1:DS
sr1:Q0
sr1:VCC
led1:A
led1:C
r1:1
r1:2
led2:A
led2:C
r2:1
r2:2
led3:A
led3:C
r3:1
r3:2
led4:A
led4:C
r4:1
r4:2
led5:A
led5:C
r5:1
r5:2
led6:A
led6:C
r6:1
r6:2
led7:A
led7:C
r7:1
r7:2
led8:A
led8:C
r8:1
r8:2
D0D1D2D3D4D5D6D7GNDLOGIC
logic1:D0
logic1:D1
logic1:D2
logic1:D3
logic1:D4
logic1:D5
logic1:D6
logic1:D7
logic1:GND