TTL Triggered State Change#

Digital input channels generate events whenever their logic level changes — for example, TTLIn1_High when a TTL pulse arrives on TTL input 1, and TTLIn1_Low when the line returns to low. These events can drive state transitions just like any other event, allowing external hardware to control the state machine.

In this example, Port1Light waits for a TTL pulse on TTL input 1. The TTLIn1_High event then advances the state machine to Port2Light, which exits after one second.

../../_images/ttl_triggered_state_change__light.svg ../../_images/ttl_triggered_state_change__dark.svg
 1from bpod_core.fsm import StateMachine
 2
 3fsm = StateMachine()
 4
 5fsm.add_state(
 6    name='Port1Light',
 7    transitions={'TTLIn1_High': 'Port2Light'},
 8    actions={'PWM1': 255},
 9)
10fsm.add_state(
11    name='Port2Light',
12    timer=1,
13    transitions={'Tup': '>exit'},
14    actions={'PWM2': 255},
15)
 1{
 2  "states": {
 3    "Port1Light": {
 4      "transitions": {
 5        "TTLIn1_High": "Port2Light"
 6      },
 7      "actions": {
 8        "PWM1": 255
 9      }
10    },
11    "Port2Light": {
12      "timer": 1.0,
13      "transitions": {
14        "Tup": ">exit"
15      },
16      "actions": {
17        "PWM2": 255
18      }
19    }
20  }
21}
 1states:
 2  Port1Light:
 3    transitions:
 4      TTLIn1_High: Port2Light
 5    actions:
 6      PWM1: 255
 7  Port2Light:
 8    timer: 1.0
 9    transitions:
10      Tup: '>exit'
11    actions:
12      PWM2: 255