#include <TinyDebug.h>
const int clock = 2; /* SRCLK */
const int latch = 1; /* RCLK */
const int data = 0; /* SER */
void setup() {
Debug.begin();
Debug.println(F("Hello, TinyDebug!"));
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
}
void loop() {
// Generate a random 16-bit number
uint16_t pattern = random(65536);
Debug.println("\n");
String binaryString = String(pattern, BIN);
// Pad the string with leading zeros
while (binaryString.length() < 16) {
binaryString = "0" + binaryString;
}
Debug.println(binaryString);
binaryString[1] = '1';
// Swap 15th bit with 10th bit and 14th bit with 11th bit
binaryString[14] = binaryString[9];
binaryString[13] = binaryString[10];
Debug.println(binaryString);
pattern = strtoul(binaryString.c_str(), NULL, 2);
// Send the bits to the shift registers
for (int i = 0; i < 16; i++) {
digitalWrite(data, (pattern & (1 << i)) ? HIGH : LOW);
digitalWrite(clock, HIGH);
digitalWrite(clock, LOW);
}
// Latch the data into the outputs of the shift registers
digitalWrite(latch, HIGH);
digitalWrite(latch, LOW);
// Wait for a while before the next pattern
delay(random(100,500));
}