Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions assignments/03-game-controller-discover/code_solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ has_children: false

```python
while True:
if current_state is state_wait:
if button.value == True:
keyboard.press(key) # Send our defined key as a command...
print("button is pressed") #Print a confirmation in the serial monitor
current_state = state_button_is_pressed # Update our state
if current_state is state_wait:
if button.value == True:
keyboard.press(key) # Send our defined key as a command...
print("button is pressed") #Print a confirmation in the serial monitor
current_state = state_button_is_pressed # Update our state

if current_state is state_button_is_pressed:
if button.value == False:
keyboard.release_all() # and release all keys again
print("button is released") # Print a confirmation in the serial monitor
current_state = state_wait # Reset the state
# Sleep briefly so keypress events occur at a human timescale.
# Skilled users can manage ~7 button presses per second, so we
# sample at roughly twice that rate to satisfy the Nyquist criterion.
if current_state is state_button_is_pressed:
if button.value == False:
keyboard.release_all() # and release all keys again
print("button is released") # Print a confirmation in the serial monitor
current_state = state_wait # Reset the state

# Sleep briefly so keypress events occur at a human timescale.
# Skilled users can manage ~7 button presses per second, so we
# sample at roughly twice that rate to satisfy the Nyquist criterion.

time.sleep(0.07)
```