-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (40 loc) · 1.54 KB
/
Copy pathmain.py
File metadata and controls
57 lines (40 loc) · 1.54 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
import EmbeddedSimLib as EmbeddedSim
import time
esp = EmbeddedSim.ESP32()
led1 = EmbeddedSim.LED()
switch1 = EmbeddedSim.Switch()
led2 = EmbeddedSim.LED()
reader = EmbeddedSim.PWMReader()
motor = EmbeddedSim.Motor()
def setup_simulation():
led1.set_connected_port(esp, 10)
switch1.set_connected_port(esp, 1, 2)
led2.set_connected_port(esp, 8)
esp.set_port(1, EmbeddedSim.PortState.High)
reader.set_connected_port(esp, 5)
motor.set_connected_port(esp, 6)
def run_loop():
setup_simulation()
state = False
print("Starting Embedded Simulation Logic...")
try:
while True:
print(f"LED1 Active: {led1.get_internal_port_state() == EmbeddedSim.PortState.High}")
print(f"Switch Pushed: {switch1.get_internal_port_state() == EmbeddedSim.PortState.High}")
print(f"Pin 2 State: {esp.get_port(2)}")
print(f"PWM Duty Cycle: {reader.get_pwm_cycle():.2f}")
print(f"Motor Speed: {motor.speed:.2f}")
print(f"Loop Delta: {esp.get_delta_time_ns()} ns")
print("")
state = not state
esp.set_port(10, EmbeddedSim.PortState.High if state else EmbeddedSim.PortState.Low)
if state:
switch1.swap_switch()
esp.set_port(8, esp.get_port(2))
esp.set_port_pwm(5, 90)
esp.set_port_pwm(6, 90)
time.sleep(1)
except KeyboardInterrupt:
print("Simulation terminated.")
if __name__ == "__main__":
run_loop()