Project

General

Profile

Revision 0c873a67

ID0c873a678934d3644224359dbebdfcb750af3f9a
Parent c5d6b0e8
Child 453e1532

Added by Matthew Sebek about 10 years ago

Fixed up all the buggy code.

View differences:

arduino/InterruptSingleChannel/InterruptSingleChannel.ino
1
// First Example in a series of posts illustrating reading an RC Receiver with
2
// micro controller interrupts.
3
//
4
// Subsequent posts will provide enhancements required for real world operation
5
// in high speed applications with multiple inputs.
6
//
7
// http://rcarduino.blogspot.com/
8
//
9
// Posts in the series will be titled - How To Read an RC Receiver With A Microcontroller
10

  
11
// See also http://rcarduino.blogspot.co.uk/2012/04/how-to-read-multiple-rc-channels-draft.html
12

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

  
17
Servo myservo;
18
// Center is 90
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;
19 13
int pos = 0;
14

  
20 15
// Note the following mapping is used between pins and interrupt numbers:
21 16
//Board	int.0	int.1	int.2	int.3	int.4	int.5
22 17
//Uno, Ethernet	2	3
......
27 22
void setup()
28 23
{
29 24
  receiver_init();
30
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
25
  steering_servo.attach(9);  // attaches the servo on pin 9 to the servo object
31 26
  Serial.begin(9600);
32 27
}
33 28

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

  
41
  //myservo.write(133+(input-128)/20);
36
  //steering_servo.write(133+(input-128)/20);
42 37
  // I decided 133 is center
43 38
  // Note that 4 is a damping factor.
44 39
  // 43
......
49 44
    out = 129;
50 45
  }
51 46
  Serial.println(out);
52
  myservo.write(out);
47
  steering_servo.write(out);
53 48
}
54

  
55

  

Also available in: Unified diff