-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwm_signal_test.ino
65 lines (49 loc) · 1.45 KB
/
pwm_signal_test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#define rcPin1 6 // Pin 8 Connected to CH1 of Transmitter;
#define rcPin2 7 // Pin 9 Connected to CH2
#define rcPin3 8
#include <DualVNH5019MotorShield.h>
int ch1 = 0; // Receiver Channel 1 PPM value
int ch2 = 0; // Receiver Channel 2 PPM value
int ch3 = 0;
//const int deadzone =1450-1480
void setup() {
pinMode(rcPin1, INPUT);
pinMode(rcPin2, INPUT);
pinMode(rcPin3, INPUT);
Serial.begin(9600);
}
void loop() {
// Read in the length of the signal in microseconds
ch1 = pulseIn(rcPin1, HIGH, 20000); // (Pin, State, Timeout)
ch2 = pulseIn(rcPin2, HIGH, 20000);
ch3 = pulseIn(rcPin3, HIGH, 20000);
/*int up = map(ch1,1000,1450,0,255);
int down = map(ch1,1500,2000,0,-255); */
int updown = map(ch2,1500,1900,0,255);
int leftright = map(ch1,1000,2000,0,255);
int weapon = map(ch1,1000,2000,0,255);
Serial.print("Channel #1: ");
Serial.println(ch2);
Serial.print("Channel #2: ");
Serial.println(ch1);
Serial.print("Channel #3: ");
Serial.println(ch3);
Serial.println("------------");
Serial.print("Map #1: ");
Serial.println(updown);
Serial.print("Map #2: ");
Serial.println(leftright);
Serial.print("Map #3: ");
Serial.println(weapon);
Serial.println("------------");
delay(1000);
/*if (ch1<1000 && ch1>=1450) {
digitalWrite (3,HIGH);
digitalWrite (4,LOW);
analogWrite(5,up);
}else{
digitalWrite (3,LOW);
digitalWrite (4,HIGH);
analogWrite(6,down);
} */
}