-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflysky.ino
More file actions
112 lines (83 loc) · 2.31 KB
/
flysky.ino
File metadata and controls
112 lines (83 loc) · 2.31 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
struct Controler {
unsigned long time_to_compute;
signed long right_stick_hor;
signed long right_stick_vert;
signed long left_stick_vert;
signed long left_stick_hor;
bool SWA;
bool SWB;
};
struct Controler_Pinout {
int CH1;
int CH2;
int CH3;
int CH4;
int CH5;
int CH6;
};
signed long time1;
signed long time2;
void initControler (Controler_Pinout pinnout){
pinMode(pinnout.CH1, INPUT);
pinMode(pinnout.CH2, INPUT);
pinMode(pinnout.CH3, INPUT);
pinMode(pinnout.CH4, INPUT);
pinMode(pinnout.CH5, INPUT);
pinMode(pinnout.CH6, INPUT);
}
Controler controler_struct_global;
Controler getControler(Controler_Pinout pinnout){
Controler controler_struct;
time1 = micros();
controler_struct.SWA = pulseIn(pinnout.CH6, HIGH,32768 ) > 1000;
controler_struct.SWB = pulseIn(pinnout.CH5, HIGH,32768 ) > 1000;
controler_struct.left_stick_vert = pulseIn(pinnout.CH2, HIGH,32768 ) - 969;
controler_struct.left_stick_hor = pulseIn(pinnout.CH4, HIGH,32768 ) - 1460;
controler_struct.right_stick_hor = pulseIn(pinnout.CH1, HIGH,32768 ) - 1460;
controler_struct.right_stick_vert = pulseIn(pinnout.CH3, HIGH,32768 ) - 1460;
time2 = micros();
controler_struct.time_to_compute = time2 -time1;
return controler_struct;
}
void printControler(Controler controler_struct){
Serial.print("left_stick_hor:");
Serial.print(controler_struct.left_stick_hor);
Serial.print(",");
Serial.print("Throttle:");
Serial.print(controler_struct.left_stick_vert);
Serial.print(",");
Serial.print("right_stick_hor:");
Serial.print(controler_struct.right_stick_hor);
Serial.print(",");
Serial.print("SWA:");
Serial.print( controler_struct.SWA * 5000);
Serial.print(",");
Serial.print("SWB:");
Serial.print(controler_struct.SWB * 5000);
Serial.print(",");
Serial.print("right_stick_vert:");
Serial.print(controler_struct.right_stick_vert);
Serial.print(",");
Serial.print("Timeing:");
Serial.print(controler_struct.time_to_compute >> 4);
Serial.print("\n");
}
Controler_Pinout pin_out {
.CH1 = 13,
.CH2 = 12,
.CH3 = 11,
.CH4 = 10,
.CH5 = 9,
.CH6 = 8,
};
/*
Useage
void setup() {
Serial.begin(921600);
initControler(pin_out);
}
void loop() {
controler_struct_global = getControler(pin_out);
printControler(controler_struct_global);
}
*/