#include <TinyWireM.h>
#include <Tiny4kOLED.h>
// ============================================================================
const int dataPin = 1; /* Q7 */
const int clockPin = 3; /* CP */
const int latchPin = 4; /* PL */
const int numBits = 8;
void setup() {
oled.begin();
oled.setFont(FONT8X16);
pinMode(dataPin, INPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
}
void loop() {
//oled.clear();
oled.setCursor(0, 1);
digitalWrite(latchPin, LOW);
digitalWrite(latchPin, HIGH);
// Step 2: Shift
for (int i = 0; i < numBits; i++) {
int bit = digitalRead(dataPin);
if (bit == HIGH) {
oled.print("1");
} else {
oled.print("0");
}
digitalWrite(clockPin, HIGH); // Shift out the next bit
digitalWrite(clockPin, LOW);
}
oled.on();
delay(1);
}