const int DataPin = 23; //Blue
const int ClockPin = 22; //Yellow
const int LatchPin = 21; //Pink
int pattern = 0b1010100110101011;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(DataPin,OUTPUT);
pinMode(ClockPin,OUTPUT);
pinMode(LatchPin,OUTPUT);
}
// https://lastminuteengineers.com/74hc595-shift-register-arduino-tutorial/?utm_content=cmp-true
// In this, the concept is explained as LatchPin change from Low to high will transfer the data
// Clock pin giving the value from low to high will trigger the clock pin
void shiftOutPattern(int dataPin, int clockPin, uint16_t pattern) {
digitalWrite(LatchPin, LOW);
for (int i = 0; i < 16; i++) {
digitalWrite(dataPin, (pattern & (1 << i)) ? HIGH : LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
digitalWrite(LatchPin, HIGH);
}
void loop() {
Serial.println("pattern1");
Serial.println(pattern);
if( pattern & 1){
pattern = 0b1010100110101010;
}
else{
pattern = ~pattern;
}
shiftOutPattern(DataPin, ClockPin, pattern);
delay(1000);
}