After advancing at 74HC165, it is time to act at 74HC595.
When I used the library, there was a command that served to know which switch was pressed. Now I do not have that command. In the loop, I know that if I press the switch 8, the character 8 is a 1, but then I did not finish: I did not just make an output in 74HC595 when I pressed a switch in 74HC165.
Can you think of something?
I paste here the complete code:
//____________________________________________
//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 izquiero (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];
////////////////////////
int estado000 = 0;
////////////////////////
//____________________________________________
//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 izquiero (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 1st chip.
// pin 10 of each chip to pin 9 of next chip
//____________________________________________
//Pantalla20x4·I2C============================
/*Conecta los cables SDA a SDA y SCL a SCL, calamar.*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
//////////////////////////////////////////////
//////////////////////////////////////////////
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 - 1; i >= 0; i--){
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){
//set an individual pin HIGH or LOW
registers[index] = value;
}
//////////////////////////////////////////////
//////////////////////////////////////////////
void loop(){
//____________________________________________
//74HC595=====================================
////////////////////////
estado000 = digitalRead(pin_Q7);
////////////////////////
//Serial.println(boton01);
if(estado000 == 9) {
setRegisterPin(9, HIGH);
// digitalWrite(13, HIGH);
}
else {
setRegisterPin(9, LOW);
// digitalWrite(13, LOW);
}
////////////////////////
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");
else
Serial.print("0");
// Clock pulse to shift to the next bit
digitalWrite(pin_CP, LOW);
digitalWrite(pin_CP, HIGH);
}
//Serial.print(digitalRead(pin_Q7));
Serial.println();
//____________________________________________
//Pantalla20x4·I2C============================
// lcd.clear();//Limpiamos la LCD
// lcd.print("Hola");//Escribimos en la primera linea
// lcd.setCursor(0,1);//Saltamos a la segunda linea
// lcd.print("mundo");//Escribimos en la segunda linea
// lcd.setCursor(0,2);//Saltamos a la tercera linea
// lcd.print("USAL");//Escribimos en la tercera linea
// lcd.setCursor(0,3);//Saltamos a la cuarta linea
// lcd.print("----");//Escribimos en la cuarta linea
//Tiempo de espera para que reinicie el ciclo
//delay(500);
}