From 870256c81b89394412f40ac99055ae2acb36cbb9 Mon Sep 17 00:00:00 2001 From: gzafirov Date: Sun, 10 Mar 2024 15:00:24 +0200 Subject: [PATCH] ShiftRegister Example Bounds check --- Examples/other/shift-register-hc595/source.ino | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Examples/other/shift-register-hc595/source.ino b/Examples/other/shift-register-hc595/source.ino index 80bc4f0..b5cec1f 100644 --- a/Examples/other/shift-register-hc595/source.ino +++ b/Examples/other/shift-register-hc595/source.ino @@ -9,31 +9,30 @@ const uint8_t shreg_pins[] = { void setup() { - for (int i = 0; i < 4; ++i) + for (uint8_t i = 0; i < (sizeof(shreg_pins)/sizeof(shreg_pins[0])); ++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) { + for (uint8_t i = 0; i < 8; ++i) { digitalWrite(shreg_shcp_pin, LOW); - delay(10); - unsigned val = data & (0x80 >> i); + uint8_t 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) { + for (uint8_t i = 0; i < 8; ++i) { shreg_write(1 << i); delay(500); } -- 2.39.5