-
Notifications
You must be signed in to change notification settings - Fork 0
Using the Trellis
To use the Trellis, you'll need to first need to import the TrellisState class by adding the following line to the top of your Python file:
from raspi.io_states.trellis_state import TrellisStateThen you'll need to create a TrellisState object in your puzzle's __init__ method, like so:
def __init__(self, update_io_state, register_callback):
# Your old code here
self.trellis_state = TrellisState()The TrellisState has two methods you can call:
-
set_visible(is_visible)- pass inTrueto show the Trellis, orFalseto hide it -
set_led_on(id, is_on)- takes the id (between 0 and 15, starting in the top-left corner) of the light and 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 Trellis. (In our case, that Arduino is simply known as ARDUINO1, because it does many things.) See the examples below for details.
For example, to show the Trellis to the player, you would use the following code:
self.trellis_state.set_visible(True)
self.update_io_state(ARDUINO1, self.trellis_state)Likewise, in order to turn the center light on, you would use the following code:
self.trellis_state.set_led_on(4, True)
self.update_io_state(ARDUINO1, self.trellis_state)You can also do multiple state object updates (like setting the on/off state of multiple LEDs) before sending it out to the Arduino. It is recommended that you minimize the calls to update_io_state because it takes the Arduino some time to process each update message.
Whenever the player presses a button on the Trellis, your event callback function (user_input_event_received, if you didn't rename it) is called. To check if the event was a Trellis button press, simply check event.id. Then look at event.data (a numeric encoding of the key that was pressed) to see which button was pressed.
def user_input_event_received(self, event):
# Some other code here, perhaps
if event.id == EventType.TRELLIS_BUTTON_PRESS:
# Trellis button was pressed, so do something with the value of the key they pressed (how about they win if they pressed the center button? Sure, why not?)
if event.data == 4: # User pressed the center button, so they win!
self.is_solved = True # Mark the puzzle as solved, or something...