]> kolegite.com Git - vmks.git/commitdiff
Examples: Add shift register example with hc595
authorKristiyan Stoimenov <kristoimenov@gmail.com>
Tue, 16 Jan 2024 20:23:18 +0000 (22:23 +0200)
committerKristiyan Stoimenov <kristoimenov@gmail.com>
Tue, 16 Jan 2024 20:23:18 +0000 (22:23 +0200)
Signed-off-by: Kristiyan Stoimenov <kristoimenov@gmail.com>
Examples/other/shift-register-hc595/schematic.png [new file with mode: 0644]
Examples/other/shift-register-hc595/source.ino [new file with mode: 0644]
Examples/other/shift-register-hc595/tinkercad-link.txt [new file with mode: 0644]

diff --git a/Examples/other/shift-register-hc595/schematic.png b/Examples/other/shift-register-hc595/schematic.png
new file mode 100644 (file)
index 0000000..437ae59
Binary files /dev/null and b/Examples/other/shift-register-hc595/schematic.png differ
diff --git a/Examples/other/shift-register-hc595/source.ino b/Examples/other/shift-register-hc595/source.ino
new file mode 100644 (file)
index 0000000..80bc4f0
--- /dev/null
@@ -0,0 +1,40 @@
+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);
+       }
+}
diff --git a/Examples/other/shift-register-hc595/tinkercad-link.txt b/Examples/other/shift-register-hc595/tinkercad-link.txt
new file mode 100644 (file)
index 0000000..e0e0f9b
--- /dev/null
@@ -0,0 +1 @@
+https://www.tinkercad.com/things/60lipMmr8jy-copy-of-dazzling-juttuli?sharecode=bAmruv08WdweZSLWislQwYYyA3k45BDzeyeXujYHIFw