-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRC_Input_test_6ch.ino
51 lines (43 loc) · 1.15 KB
/
RC_Input_test_6ch.ino
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
// This program is used to receive the input values from the radio-control
// transmitter/receiver and output the values to the Serial connection
// for analysis in how to condition and map these values
//Input channel pin assignment
const int ch[10] = {2, 4, 7, 8, 12, 13};
//Initialize storage for input channel signal value
int input[10] = {0, 0, 0, 0, 0, 0};
void setup() {
//Initialze serial communication at 9600 bits per second
Serial.begin(9600);
//Set RX input pins
pinMode(ch[0], INPUT);
pinMode(ch[1], INPUT);
pinMode(ch[2], INPUT);
pinMode(ch[3], INPUT);
pinMode(ch[4], INPUT);
pinMode(ch[5], INPUT);
}
void loop() {
//Read and output each RX channel individually
for(int i = 0; i<6; i++)
{
//Read in value from RX
readChannel(i);
//Write RX value to Serial connection to PC
serialInputWrite(i);
}
Serial.println();
}
//Read in pulse width values from RX
void readChannel(int in)
{
input[in] = pulseIn(ch[in],HIGH);
}
//Write out signal data to Serial connection
void serialInputWrite(int in)
{
Serial.print("Ch");
Serial.print(in+1);
Serial.print(": ");
Serial.print(input[in]);
Serial.print(" | ");
}