EIGHT LED WITH 74HC595 AND ARDUINO


 


In this lesson, you will learn how to use eight large red LEDs with an Arduino without needing to give up 8 output pins!


Arduino  Code



int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
byte leds = 0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
leds = 0;
updateShiftRegister();
delay(100);
for (int i = 0; i < 8; i++)
{
bitSet(leds, i);
updateShiftRegister();
delay(100);
}
leds = 0;
updateShiftRegister();
delay(100);
for (int i = 7; i >= 0; i–)
{
bitSet(leds, i);
updateShiftRegister();
delay(100);
}
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}




Comments

Popular posts from this blog

HUMAN BLOOD

KEYPAD ARDUINO PROJECT