robobuggy / arduino / InterruptSingleChannel / InterruptSingleChannel.ino @ 5ea63f0d
History | View | Annotate | Download (1.04 KB)
1 | 0c873a67 | msebek | /** |
---|---|---|---|
2 | * @file InterruptSingleChannel.ino |
||
3 | * @brief Read in RC, then write value to servo. |
||
4 | */ |
||
5 | c5d6b0e8 | msebek | #include <Servo.h> |
6 | #include "receiver.h" |
||
7 | |||
8 | 0c873a67 | msebek | #define STEER_CENTER 129 |
9 | |||
10 | // 1/RC_STEER_DAMPER times RC_VALUE (0-180) |
||
11 | #define RC_STEER_DAMPER 4 |
||
12 | Servo steering_servo; |
||
13 | c5d6b0e8 | msebek | int pos = 0; |
14 | 0c873a67 | msebek | |
15 | c5d6b0e8 | msebek | // Note the following mapping is used between pins and interrupt numbers: |
16 | //Board int.0 int.1 int.2 int.3 int.4 int.5 |
||
17 | //Uno, Ethernet 2 3 |
||
18 | //Mega2560 2 3 21 20 19 18 |
||
19 | //Leonardo 3 2 0 1 7 |
||
20 | //Due (see below) |
||
21 | |||
22 | void setup() |
||
23 | { |
||
24 | receiver_init(); |
||
25 | 0c873a67 | msebek | steering_servo.attach(9); // attaches the servo on pin 9 to the servo object |
26 | c5d6b0e8 | msebek | Serial.begin(9600); |
27 | } |
||
28 | |||
29 | void loop() |
||
30 | { |
||
31 | static int input = 128; |
||
32 | 0c873a67 | msebek | if(rc_available[THR_INDEX]) { |
33 | input = receiver_get_angle(THR_INDEX); |
||
34 | c5d6b0e8 | msebek | } |
35 | |||
36 | 0c873a67 | msebek | //steering_servo.write(133+(input-128)/20); |
37 | c5d6b0e8 | msebek | // I decided 133 is center |
38 | // Note that 4 is a damping factor. |
||
39 | // 43 |
||
40 | int out = (input/4)+(90*3/4)+39; |
||
41 | if(out < 105 || out > 160) { |
||
42 | Serial.println("FAKFAKFAK SERVO OUT OF RANGE"); |
||
43 | Serial.println(out); |
||
44 | out = 129; |
||
45 | } |
||
46 | Serial.println(out); |
||
47 | 0c873a67 | msebek | steering_servo.write(out); |
48 | c5d6b0e8 | msebek | } |