Skip to content

Commit 65838c3

Browse files
authored
Merge pull request #107 from FoamyGuy/debounce_buttons_gif_example
button debouncing in the gif example
2 parents 41cc29e + 33a9e6b commit 65838c3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

examples/rgb_display_pillow_animated_gif.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def preload(self):
133133
def play(self):
134134
self.preload()
135135

136+
_prev_advance_btn_val = self.advance_button.value
137+
_prev_back_btn_val = self.back_button.value
136138
# Check if we have loaded any files first
137139
if not self._gif_files:
138140
print("There are no Gif Images loaded to Play")
@@ -141,12 +143,17 @@ def play(self):
141143
for frame_object in self._frames:
142144
start_time = time.monotonic()
143145
self.display.image(frame_object.image)
144-
if not self.advance_button.value:
146+
_cur_advance_btn_val = self.advance_button.value
147+
_cur_back_btn_val = self.back_button.value
148+
if not _cur_advance_btn_val and _prev_advance_btn_val:
145149
self.advance()
146150
return False
147-
if not self.back_button.value:
151+
if not _cur_back_btn_val and _prev_back_btn_val:
148152
self.back()
149153
return False
154+
155+
_prev_back_btn_val = _cur_back_btn_val
156+
_prev_advance_btn_val = _cur_advance_btn_val
150157
while time.monotonic() < (start_time + frame_object.duration / 1000):
151158
pass
152159

0 commit comments

Comments
 (0)