I want to send data to my 74HC595 via SPI (in Arduino). But I could not manage to blink my LEDs. My code is in below.
#include <SPI.h>
int clock_pin = 13; // SCLK
int data_pin = 11; // MOSI
int latch_pin = 10; // SS
uint8_t led ;
void setup() {
pinMode(latch_pin, OUTPUT); // enable pin 10 as latch pin
// SPI Setup
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.setBitOrder(LSBFIRST);
digitalWrite(latch_pin, HIGH);
}
void loop() {
led = 0b10101111;
put_Register(led);
delay(500);
led = 0b10101101;
put_Register(led);
delay(5000);
}
void put_Register(byte led) {
digitalWrite(latch_pin, LOW);
SPI.transfer(led);
digitalWrite(latch_pin, HIGH);
}