True true!
I had uncommented "setRegisterPin (index, value)" because I did not see the change to 0. I put delay (500) to see it and yes, it changes to 0.
Well, well ... IT WORKS !!!!
To finish, I had to take into account that the 74SN595 are numbered from 1, while the 74HC165 are numbered from 0. This has forced me to modify the line "registers [index] = value" to "registers [index + 1] = value; " and with this it has already worked as I wanted.
There is not a very fast answer because, of course, it is constantly doing loops, but ... something is something !!!
At least I know how it works !!!
In a next modification, I will use an intermediate matrix between the input and the output that can match an input with another or other outputs. But for today, I'm satisfied!
Again, a thousand thanks!
To correspond minimally with your help, here I leave the code for those who want to use it, and below I leave the graphics of the connections made, so that they do not have to be searched online.
And if someone reads and comes up with some better solution, which surely will be, please, tell us.
//____________________________________________
//74HC595=====================================
/* A continuación te pongo cómo tienes que conectar el primer chip
* al Arduino. Ten en cuenta que los pines se numeran del 1 al 16
* desde el inferior izquierdo (1), en el sentido contrario al movi-
* miento de las agujas del reloj, viendo la muesca del chip a la
* izquierda, terminando así en el 16, en la esquina superior iz-
* quierda, que es Vcc.
*/
int SER_Pin = 6; //pin 14 on the 75HC595
int RCLK_Pin = 7; //pin 12 on the 75HC595
int SRCLK_Pin = 8; //pin 11 on the 75HC595
//How many of the shift registers - change this
#define number_of_74hc595s 20
//do not touch
#define numOfRegisterPins number_of_74hc595s *8
boolean registers[numOfRegisterPins];
//____________________________________________
//74HC165=====================================
/* A continuación te pongo cómo tienes que conectar el primer chip
* al Arduino. Ten en cuenta que los pines se numeran del 1 al 16
* desde el inferior izquierdo (1), en el sentido contrario al movi-
* miento de las agujas del reloj, viendo la muesca del chip a la
* izquierda, terminando así en el 16, en la esquina superior iz-
* quierda, que es Vcc.
* El pin 15 lo he puesto a 9 y rula, así que así queda.
*/
const uint8_t pin_PL = 10; // to all pins 1
const uint8_t pin_CP = 11; // to all pins 2
const uint8_t pin_Q7 = 12; // to pin 9 of the 1ast chip.
//pin 10 of each chip to pin 9 of next chip
int index;
int value;
//____________________________________________
//Pantalla20x4·I2C============================
/*Conecta los cables SDA a SDA y SCL a SCL, calamar.*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,20,4);
//Aquí originalmente ponía 0x24. Pues no. Hay que poner 0x3f y rula.
//////////////////////////////////////////////
//////////////////////////////////////////////
void setup(){
//____________________________________________
//74HC595=====================================
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
//reset all register pins
clearRegisters();
writeRegisters();
//____________________________________________
//74HC165=====================================
Serial.begin(115200);
pinMode(pin_PL, OUTPUT);
pinMode(pin_CP, OUTPUT);
pinMode(pin_Q7, INPUT);
digitalWrite(pin_PL, HIGH);
digitalWrite(pin_CP, HIGH);
//____________________________________________
//Pantalla20x4·I2C============================
//Iniciamos el fondo retroiluminado
lcd.backlight();
//lcd.noBacklight();
//Iniciamos la pantalla
lcd.init();
//LCD.
lcd.setCursor(0,0);
lcd.print(" Universidad de ");//Escribir en la LCD
lcd.setCursor(0,1);
lcd.print(" Salamanca ");//Escribir en la LCD
lcd.setCursor(0,2);
lcd.print(" EPS de Zamora ");//Escribir en la LCD
lcd.setCursor(0,3);
lcd.print(" Laboratorio TIT ");//Escribir en la LCD
//delay(1000);
}
//____________________________________________
//74HC595=====================================
void clearRegisters()
{
//set all register pins to LOW
for(int i = numOfRegisterPins - 1; i >= 0; i--)
{
registers[i] = LOW;
}
}
void writeRegisters()
{
//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins; i >= 1; i--)
{
digitalWrite(SRCLK_Pin, LOW);
int val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}
void setRegisterPin(int index, int value)
{
registers[index+1] = value;
writeRegisters();
}
//////////////////////////////////////////////
//////////////////////////////////////////////
void loop(){
//____________________________________________
//74HC595=====================================
//writeRegisters();
//MUST BE CALLED TO DISPLAY CHANGES
//Only call once after the values are set how you need.
//____________________________________________
//74HC165=====================================
// Latch data from input pins into shift registers
digitalWrite(pin_PL, LOW);
digitalWrite(pin_PL, HIGH);
/* Aquí tienes también que intervenir. En el bucle tienes que
* cambiar el parámetro "n" en "i < n". Tienes que poner el
* número total de pines que quieres que se lean. Este número
* será igual al número de chips x 8 (esto ya es para logsianos).
*/
// Read all bits from all shift registers one by one
for (int i = 0; i < 80; i++)
{
if (digitalRead(pin_Q7) == HIGH)
{
//Serial.print("1");
index = i;
value = HIGH;
setRegisterPin(index, value);
}
else
{
index = i;
value = LOW;
setRegisterPin(index, value);
}
// Clock pulse to shift to the next bit
digitalWrite(pin_CP, LOW);
digitalWrite(pin_CP, HIGH);
}
//Serial.println();
//Serial.println();
//____________________________________________
//Pantalla20x4·I2C============================
// lcd.clear();//Limpiamos la LCD
// lcd.print("Primera linea");//Escribimos en la primera linea
// lcd.setCursor(0,1);//Saltamos a la segunda linea
// lcd.print("Segunda linea");//Escribimos en la segunda linea
// lcd.setCursor(0,2);//Saltamos a la tercera linea
// lcd.print("Tercera linea");//Escribimos en la tercera linea
// lcd.setCursor(0,3);//Saltamos a la cuarta linea
// lcd.print("Cuarta linea");//Escribimos en la cuarta linea
//Tiempo de espera para que reinicie el ciclo
//delay(500);
}
SN74HC165 (Inputs):
SN74HC595 (Outputs):

