Project

General

Profile

Statistics
| Branch: | Revision:

robobuggy / arduino / InterruptSingleChannel / InterruptSingleChannel.ino @ 0c873a67

History | View | Annotate | Download (1.04 KB)

1
/**
2
 * @file InterruptSingleChannel.ino
3
 * @brief Read in RC, then write value to servo.
4
 */
5
#include <Servo.h>
6
#include "receiver.h"
7

    
8
#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
int pos = 0;
14

    
15
// 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
  steering_servo.attach(9);  // attaches the servo on pin 9 to the servo object
26
  Serial.begin(9600);
27
}
28

    
29
void loop()
30
{
31
  static int input = 128;
32
  if(rc_available[THR_INDEX]) {
33
    input = receiver_get_angle(THR_INDEX);
34
  }
35

    
36
  //steering_servo.write(133+(input-128)/20);
37
  // 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
  steering_servo.write(out);
48
}