// Pin definitions
const int dataPin = 8;    // Connects to DI on CD4094BE
const int clockPin = 9;   // Connects to CP on CD4094BE
const int strobePin = 10; // Connects to STROBE on CD4094BE
const int oePin = 11;

void setup() {
  // Set the pins as outputs
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(strobePin, OUTPUT);
  pinMode(oePin, OUTPUT);
  Serial.begin(115200);
  digitalWrite(oePin, HIGH);

}

void loop() {
  // Count from 0 to 255
  for (int i = 0; i < 256; i++) {
    // Send the binary representation of 'i' to the shift register
    sendTo4094(i);
    Serial.println(i);
    delay(1000); // Wait for half a second
  }
}

// Function to send data to CD4094BE
void sendTo4094(int data) {
  digitalWrite(strobePin, LOW); // Prepare for data input

  for (int i = 0; i < 8; i++) {
    // Send each bit from MSB to LSB
    digitalWrite(dataPin, (data & (1 << (7 - i))) ? HIGH : LOW);
    
    // Toggle clock pin to shift in data
    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
  }

  // Latch the data by toggling the strobe pin
  digitalWrite(strobePin, HIGH);
  digitalWrite(strobePin, LOW);
}
cd4094Breakout