-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate_example.py
More file actions
69 lines (56 loc) · 1.95 KB
/
template_example.py
File metadata and controls
69 lines (56 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from neotimer import *
from statemachine import *
from machine import Pin
state_machine = StateMachine()
myTimer = Neotimer(1000)
led = Pin(25,Pin.OUT)
#============================================================
# States Logic Functions
#============================================================
def state0_logic():
# Referenced global variables
# ----> Here <----
if state_machine.execute_once:
# ----> Code that executes just once during state <----
# ----> Here <----
print("Machine in State 0")
myTimer.start()
# Code that executes continously during state
# ----> Here <----
led.off()
def state1_logic():
# Referenced global variables
# ----> Here <----
if state_machine.execute_once:
# ----> Code that executes just once during state <----
# ----> Here <----
print("Machine in State 1")
myTimer.start()
# Code that executes continously during state
# ----> Here <----
led.on()
#============================================================
# Add states to machine (Also create state objects)
#============================================================
# Create States
# ----> Here <----
state0 = state_machine.add_state(state0_logic)
state1 = state_machine.add_state(state1_logic)
#============================================================
# State Transitions Functions (optional)
#============================================================
# Create Transition Functions
# ----> Here <----
def delay_transition():
if myTimer.finished():
return True
else:
return False
#============================================================
# Attach transitions to states (optional)
#============================================================
state0.attach_transition(delay_transition, state1)
state1.attach_transition(delay_transition, state0)
# Main Loop: Run the state machine here
while True:
state_machine.run()