-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrone_control.ino
47 lines (32 loc) · 1.26 KB
/
drone_control.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
int throttle = 0;
int yaw = 255/2; // 3.3v / 2
int pitch = 255/2; // 3.3v / 2
int roll = 255/2; // 3.3v / 2
int throttlePin = 2; // PWM
int yawPin = 3; // PWM
int pitchPin = 4; // PWM
int rollPin = 5; // PWM
void setup() {
// Begin Serial communication at 115200 baud
Serial.begin( 115200 );
// Set pinModes
pinMode( throttlePin, OUTPUT );
pinMode( yawPin, OUTPUT );
pinMode( pitchPin, OUTPUT );
pinMode( rollPin, OUTPUT );
}
void loop() {
// When there is an Serial connection available, get the values
if ( Serial.available() > 0 ) {
throttle = Serial.parseInt(); // Store first interger value from Serial buffer
yaw = Serial.parseInt(); // Store second interger value from Serial buffer
pitch = Serial.parseInt(); // Store third interger value from Serial buffer
roll = Serial.parseInt(); // Store fourth interger value from Serial buffer
}
// Write values to the drone controller
// Use a low pass filter or DAC (digital to analog converter) to convert PWM to an analog voltage
analogWrite( throttlePin, throttle );
analogWrite( yawPin, yaw );
analogWrite( pitchPin, pitch );
analogWrite( rollPin, roll );
}