From 40111a970ae8dd59640afeb99608521b67b80375 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 3 Apr 2015 12:50:09 -0700 Subject: [PATCH] Fix a dumb logic bug in debouncing code --- debouncing.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/debouncing.cpp b/debouncing.cpp index 14e73564..de659e21 100644 --- a/debouncing.cpp +++ b/debouncing.cpp @@ -6,35 +6,41 @@ boolean key_was_pressed (byte keyState) { - if ( byte((keyState >> 7)) ^ B00000001 ) { - return false; - } else { - return true; - } + return (! key_was_not_pressed(keyState)); + + + } boolean key_was_not_pressed (byte keyState) { + if ( keyState & B00001000 || keyState & B00000100) { + return false; + } else { + return true; + } + + + - return !key_was_pressed(keyState); - + } boolean key_is_pressed (byte keyState) { - if ( byte((keyState << 7)) ^ B10000000 ) { - return false; - } else { + if ( keyState & B00000001 && keyState & B00000010 ){ + return true; + } else { + return false; } } boolean key_is_not_pressed (byte keyState) { - return(!key_is_pressed(keyState)); - +return !key_is_pressed(keyState); } boolean key_toggled_on(byte keyState)