#include <Arduino.h>
#include <LiquidCrystal.h>
const uint8_t DATA_PIN = 15;   /* DS */ 
const uint8_t LATCH_PIN = 2;  /* SHCP */
const uint8_t CLOCK_PIN = 4;  /* STCP */
const uint8_t numRows = 4;   /* Row number of the LCD */
const uint8_t numCols = 20;  /* Colum number of the LCD */
LiquidCrystal lcd(12, 14, 27, 26, 25, 33); //LCD pins



// How many of the shift registers
#define NUM_SHIFT_REGS 2
bool toggle = true; //stated of the GPIO at start
const uint8_t numOfRegisterPins = NUM_SHIFT_REGS * 8; // number of GPIOs
bool registers[numOfRegisterPins]; //An array to holdd the state of each GPIOs

//A function to match each element of the array to a specific GPIO
void setRegisterPin(int index, int value) {
  // Set an individual pin HIGH or LOW
  registers[index] = value;
}

//This function set all GPIO LOW
void clearRegisters() {
  // Reset all register pins
  for (int i = numOfRegisterPins - 1; i >= 0; i--) {
    registers[i] = LOW;
  }
}

//This function set all GPIO HIGH
void writeRegisters() {
  // Set and display registers
  digitalWrite(LATCH_PIN, LOW);

  for (int i = numOfRegisterPins - 1; i >= 0; i--) {
    digitalWrite(CLOCK_PIN, LOW);
    digitalWrite(DATA_PIN, registers[i]);
    digitalWrite(CLOCK_PIN, HIGH);
  }

  digitalWrite(LATCH_PIN, HIGH);
}

//Setup
void setup() {
  pinMode(DATA_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  lcd.begin(numCols, numRows);
  clearRegisters();
  writeRegisters();
  lcd.begin(numCols, numRows);
  
}

void loop() {
  
  lcd.setCursor(3, 0);
  lcd.print("WOKWI-74H595");
  lcd.setCursor(2, 2);
  lcd.print("PIN - LED: ");
  lcd.setCursor(2, 3);
  lcd.print("By Nicolas");
  for (uint8_t i = 0; i < 16; i++) {
    setRegisterPin(i, toggle);
    writeRegisters();
    lcd.setCursor(16, 2);
    lcd.print(i);
    delay(200); // For me to check that are Okay

  toggle = !toggle;
  lcd.clear();
  }

}





74HC595
74HC595