-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (50 loc) · 1.34 KB
/
main.cpp
File metadata and controls
74 lines (50 loc) · 1.34 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
70
71
72
73
74
#include "src/EmbeddedSim.h"
#include <thread>
#include <chrono>
#include <cstdio>
using namespace std;
ESP32 esp;
LED led1;
Switch switch1;
LED led2;
PWMReader reader;
Motor motor;
void SetupObjects();
void RunTests();
int main(void) {
SetupObjects();
bool state = 0;
while (true) {
//Testing section
RunTests();
//Testing section end
state = !state;
esp.SetPort(10, state);
if (state) {
switch1.SwapSwitch();
}
esp.SetPort(8, esp.GetPort(2));
esp.SetPortPWM(5, 90);
esp.SetPortPWM(6, 90);
this_thread::sleep_for(chrono::seconds(1));
}
return 0;
}
void RunTests() {
printf("LED1 state: %s\n", led1.GetInternalPortState() == PORT_HIGH ? "ON" : "OFF");
printf("Button Pushed: %s\n", switch1.GetInternalPortState() == PORT_HIGH ? "YES" : "NO");
printf("Port 2 State: %s\n", esp.GetPort(2) == PORT_HIGH ? "HIGH" : "LOW");
printf("LED2 state: %s\n", led2.GetInternalPortState() == PORT_HIGH ? "ON" : "OFF");
printf("PWM cycle: %f\n", reader.GetPWMCycle());
printf("Delta Time: %lld nano seconds\n", esp.GetDeltaTimeNs());
printf("Motor Speed %f\n", motor.GetSpeed());
printf("\n");
}
void SetupObjects() {
led1.SetConnectedPort(&esp, 10);
switch1.SetConnectedPort(&esp, 1, 2);
led2.SetConnectedPort(&esp, 8);
esp.SetPort(1, 1);
reader.SetConnectedPort(&esp, 5);
motor.SetConnectedPort(&esp, 6);
}