#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define btndebounce 100
#define led 2
// Define Connections to 74HC165
// Define Connections to 74HC165
#define load 25 // PL pin 1
#define clock 26 // CP pin 2
#define dataIn 27 // Q7 pin 9
// Define Connections to 74HC595
#define latch 32 // PL pin 1
#define dataOut 33 // Q7 pin 9
uint32_t lastSwitchPress = 0;
uint32_t CurrentSwitchPress = 0;
uint32_t outputsUpdate = 0;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
void setup()
{
// Setup Serial Monitor
Serial.begin(115200);
// Setup i2c
Wire.begin();
// Setup LiquidCrystal Display
lcd.init(); // initialize the lcd
// Setup 74HC165 & 74HC595 connections
pinMode(load, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(dataIn, INPUT);
pinMode(latch, OUTPUT);
pinMode(dataOut, OUTPUT);
pinMode(led,OUTPUT);
digitalWrite(led,HIGH);
}
void loop()
{
SN74165Control();
lcd.setCursor(0, 0);
lcd.print(" SHIFT REGISTERS ");
}
void SN74165Control() {
CurrentSwitchPress = millis();
if (CurrentSwitchPress - lastSwitchPress > btndebounce) {
// Write pulse to load pin
digitalWrite(load, LOW);
digitalWrite(load, HIGH);
// Get data from 74HC165
uint16_t incoming = shift16In(dataIn, clock, MSBFIRST);
// Print to serial monitor
if (incoming > 0) {
outputsUpdate = outputsUpdate^incoming;
digitalWrite(latch, LOW);
shift16Out(dataOut, clock, MSBFIRST, outputsUpdate);
digitalWrite(latch, HIGH);
Serial.print("Pin States:\r\n");
Serial.println(outputsUpdate, BIN);
}
lastSwitchPress = CurrentSwitchPress;
}
}
uint16_t shift16In(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
uint16_t value = 0;
uint8_t i;
for(i = 0; i < 16; ++i) {
if(bitOrder == LSBFIRST)
value |= digitalRead(dataPin) << i;
else
value |= digitalRead(dataPin) << (15 - i);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
return value;
}
void shift16Out(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint16_t val) {
uint16_t i;
for(i = 0; i < 16; i++) {
if(bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << (15 - i))));
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
btn4:1.l
btn4:2.l
btn4:1.r
btn4:2.r
btn5:1.l
btn5:2.l
btn5:1.r
btn5:2.r
btn6:1.l
btn6:2.l
btn6:1.r
btn6:2.r
btn7:1.l
btn7:2.l
btn7:1.r
btn7:2.r
btn8:1.l
btn8:2.l
btn8:1.r
btn8:2.r
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
r6:1
r6:2
r7:1
r7:2
r8:1
r8:2
sr1:PL
sr1:CP
sr1:D4
sr1:D5
sr1:D6
sr1:D7
sr1:Q7_N
sr1:GND
sr1:Q7
sr1:DS
sr1:D0
sr1:D1
sr1:D2
sr1:D3
sr1:CE
sr1:VCC
sr2:PL
sr2:CP
sr2:D4
sr2:D5
sr2:D6
sr2:D7
sr2:Q7_N
sr2:GND
sr2:Q7
sr2:DS
sr2:D0
sr2:D1
sr2:D2
sr2:D3
sr2:CE
sr2:VCC
btn9:1.l
btn9:2.l
btn9:1.r
btn9:2.r
btn10:1.l
btn10:2.l
btn10:1.r
btn10:2.r
btn11:1.l
btn11:2.l
btn11:1.r
btn11:2.r
btn12:1.l
btn12:2.l
btn12:1.r
btn12:2.r
btn13:1.l
btn13:2.l
btn13:1.r
btn13:2.r
btn14:1.l
btn14:2.l
btn14:1.r
btn14:2.r
btn15:1.l
btn15:2.l
btn15:1.r
btn15:2.r
btn16:1.l
btn16:2.l
btn16:1.r
btn16:2.r
r9:1
r9:2
r10:1
r10:2
r11:1
r11:2
r12:1
r12:2
r13:1
r13:2
r14:1
r14:2
r15:1
r15:2
r16:1
r16:2
sr3:Q1
sr3:Q2
sr3:Q3
sr3:Q4
sr3:Q5
sr3:Q6
sr3:Q7
sr3:GND
sr3:Q7S
sr3:MR
sr3:SHCP
sr3:STCP
sr3:OE
sr3:DS
sr3:Q0
sr3:VCC
sr4:Q1
sr4:Q2
sr4:Q3
sr4:Q4
sr4:Q5
sr4:Q6
sr4:Q7
sr4:GND
sr4:Q7S
sr4:MR
sr4:SHCP
sr4:STCP
sr4:OE
sr4:DS
sr4:Q0
sr4:VCC
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
led6:A
led6:C
led7:A
led7:C
led8:A
led8:C
led9:A
led9:C
led10:A
led10:C
led11:A
led11:C
led12:A
led12:C
led13:A
led13:C
led14:A
led14:C
led15:A
led15:C
led16:A
led16:C
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL