--- /dev/null
+const uint8_t shreg_shcp_pin = 6;
+const uint8_t shreg_input_pin = 5;
+const uint8_t shreg_stcp_pin = 4;
+const uint8_t shreg_pins[] = {
+ shreg_input_pin,
+ shreg_stcp_pin,
+ shreg_shcp_pin
+};
+
+void setup()
+{
+ for (int i = 0; i < 4; ++i)
+ pinMode(shreg_pins[i], OUTPUT);
+ digitalWrite(shreg_stcp_pin, LOW);
+ digitalWrite(shreg_shcp_pin, LOW);
+}
+
+void shreg_write(uint8_t data) {
+ for (int i = 0; i < 8; ++i) {
+ digitalWrite(shreg_shcp_pin, LOW);
+ delay(10);
+ unsigned val = data & (0x80 >> i);
+ digitalWrite(shreg_input_pin, val > 0);
+ digitalWrite(shreg_shcp_pin, HIGH);
+ delay(10);
+ }
+ digitalWrite(shreg_shcp_pin, LOW);
+
+ digitalWrite(shreg_stcp_pin, HIGH);
+ delay(10);
+ digitalWrite(shreg_stcp_pin, LOW);
+}
+
+void loop()
+{
+ for (int i = 0; i < 8; ++i) {
+ shreg_write(1 << i);
+ delay(500);
+ }
+}