From be4a1b04888c3e58f32c301975e1180d8f2fa623 Mon Sep 17 00:00:00 2001 From: DarkSpir Date: Sat, 6 Jan 2018 16:03:51 +0100 Subject: [PATCH] Optimized code - Removed unneccesary variable changes - Redesigned IF clauses to improve binary code size after compile Current binary size: 2092 bytes --- Nerfgun-Controller.ino | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Nerfgun-Controller.ino b/Nerfgun-Controller.ino index 8bbaea6..5505fec 100644 --- a/Nerfgun-Controller.ino +++ b/Nerfgun-Controller.ino @@ -52,12 +52,10 @@ void loop() { case 0: digitalWrite(PINLIGHT, HIGH); effLight = 1; - sleepBool = false; break; case 1: effLight = 2; - sleepBool = false; effStrobo = geninterval(); stroboMillis = millis(); break; @@ -65,8 +63,6 @@ void loop() { case 2: digitalWrite(PINLIGHT, LOW); effLight = 0; - effStrobo = 0; - sleepBool = false; break; } } @@ -79,10 +75,10 @@ void loop() { } } - if((effLight == 0) && (effLaser == 0) && (!sleepBool)) { - sleepBool = true; - sleepMillis = millis(); - } +// if((effLight == 0) && (effLaser == 0) && (!sleepBool)) { +// sleepBool = true; +// sleepMillis = millis(); +// } if(sleepBool) { if(millis() - sleepMillis > 200) { @@ -101,6 +97,11 @@ void loop() { PCMSK = 0; // We disabled PCINT so we don't need to know what kind of PCINT we should listen to sei(); // Cleanup done, enable interrupt handling again. } + } else { + if((effLight == 0) && (effLaser == 0)) { + sleepBool = true; + sleepMillis = millis(); + } } }