Shift registers 74HC595 con arduino

Resistencias: 220Ohm
Capacitor: 1uF



Para agregar otro set de 8 leds:


Codigo (knightrider :)

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

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void loop() {
  for (int j=0; j<=7; j++)
  {
    registerWrite(j, HIGH);
    delay(100);
  }
 
  for (int j=6; j>=1; j--)
  {
    registerWrite(j, HIGH);
    delay(100);
  }  
}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState)
{
  // the bits you want to send
  byte bitsToSend = 0;

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

  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend, whichPin, whichState);

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

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



Fuente: http://arduino.cc/en/tutorial/ShiftOut





No hay comentarios:

Publicar un comentario