From: Kristiyan Stoimenov Date: Tue, 16 Jan 2024 20:23:18 +0000 (+0200) Subject: Examples: Add shift register example with hc595 X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=52ae4ad4ed8dc36ed5075c1b7bb05e1c090bd502;p=vmks.git Examples: Add shift register example with hc595 Signed-off-by: Kristiyan Stoimenov --- diff --git a/Examples/other/shift-register-hc595/schematic.png b/Examples/other/shift-register-hc595/schematic.png new file mode 100644 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 index 0000000..80bc4f0 --- /dev/null +++ b/Examples/other/shift-register-hc595/source.ino @@ -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 index 0000000..e0e0f9b --- /dev/null +++ b/Examples/other/shift-register-hc595/tinkercad-link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/60lipMmr8jy-copy-of-dazzling-juttuli?sharecode=bAmruv08WdweZSLWislQwYYyA3k45BDzeyeXujYHIFw