-
Notifications
You must be signed in to change notification settings - Fork 0
Using the Start Button
If you want to control the light on the start button, you'll need to first need to import the StartButtonState class by adding the following line to the top of your Python file:
from raspi.io_states.start_button_state import StartButtonStateThen you'll need to create a StartButtonState object in your puzzle's __init__ method, like so:
def __init__(self, old_state_json=None):
# Your old code here
self.start_button_state = StartButtonState()Once you've created the state object, it has one method you can call:
-
set_led_on(is_on)- whether it should be on (pass inTrue) or off (pass inFalse)
After you've updated the state object, you need to tell the BOCS to send the new state to the Arduino that is responsible for the start button. (In our case, that Arduino is simply known as ARDUINO1, because it does many things.)
To turn the light on, you would use the following code:
self.start_button_state.set_led_on(True)
self.update_io_state(ARDUINO1, self.start_button_state)In order to respond to start button presses, it is not necessary to do any of the above. Whenever the player presses the start button, your event callback function (user_input_event_received, if you didn't rename it) is called. To check if the event was a start button press, simply check event.id:
def user_input_event_received(self, event):
# Some other code here, perhaps
if event.id == EventType.START_BUTTON_PRESS:
# Do something here