From 06269dd94908c35b67ec206339b7cac36eb3352b Mon Sep 17 00:00:00 2001 From: Mikael Falkvidd Date: Sun, 28 Jan 2018 09:31:19 +0100 Subject: [PATCH] Fix cppcheck issues (#1036) Fixes the following cppcheck issues: examples/SecretKnockSensor/SecretKnockSensor.ino 305 variableScope 398 style The scope of the variable 'timeDiff' can be reduced. examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino 127 variableScope 398 style The scope of the variable 'led_state' can be reduced. --- examples/SecretKnockSensor/SecretKnockSensor.ino | 3 +-- examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/SecretKnockSensor/SecretKnockSensor.ino b/examples/SecretKnockSensor/SecretKnockSensor.ino index b473937..2bdf79c 100644 --- a/examples/SecretKnockSensor/SecretKnockSensor.ino +++ b/examples/SecretKnockSensor/SecretKnockSensor.ino @@ -302,8 +302,7 @@ bool validateKnock() less of a pain to use if you're tempo is a little slow or fast. */ int totaltimeDifferences = 0; - int timeDiff = 0; - for (i=0; i < maximumKnocks; i++) { // Normalize the times + for (int timeDiff = 0, i=0; i < maximumKnocks; i++) { // Normalize the times knockReadings[i]= map(knockReadings[i], 0, maxKnockInterval, 0, 100); timeDiff = abs(knockReadings[i] - secretCode[i]); if (timeDiff > diff --git a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino index 1a62255..d0a9637 100644 --- a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino +++ b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino @@ -124,8 +124,8 @@ void preHwInit() for (int i=0; i< num_of_leds; i++) { pinMode(leds[i], OUTPUT); } - uint8_t led_state = 0; if (digitalRead(MY_SWC1)) { + uint8_t led_state = 0; while (!Serial) { digitalWrite(LED_BLUE, led_state); led_state ^= 0x01;