Thanks so much! That tutorial is great, I've bookmarked it. I'll implement glue routines in the future.
I think I've fixed it now, but I've run across another error:
In function RC::readreceiverhigh()': undefined reference to
RC::RXTimerPoint1'
I'm not quite sure what I've done wrong, so I'm just going to post my code. I think that my variables, since they're static, should be visible, but it seems like they're not.
/*
RC.cpp - Library for interacting with radio control equipment
Created by Christopher Lansdale, September 4, 2015
Version 1.0 - Last updated September 4, 2015
*/
#include "RC.h"
//Must declare your variables out here to see them in all the functions!!!!!!!
float RXTimerPoint1;
float RXTimerPoint2;
float RXPulseLength;
int ReceiverInterrupt_1;
int ReceiverInterrupt_2;
int RXAllowPin;
int ArduinoAllowPin;
RC::RC(int RXInterrupt_1, int RXInterrupt_2, int RXAllowPinPassIn, int ArduinoAllowPinPassIn)
{
ReceiverInterrupt_1 = RXInterrupt_1;
ReceiverInterrupt_2 = RXInterrupt_2;
RXAllowPin = RXAllowPinPassIn;
ArduinoAllowPin = ArduinoAllowPinPassIn;
attachInterrupt(ReceiverInterrupt_1, &readreceiverhigh, RISING);
attachInterrupt(ReceiverInterrupt_2, &readreceiverlow, FALLING);
pinMode(RXAllowPin, OUTPUT);
pinMode(ArduinoAllowPin, OUTPUT);
}
void RC::readreceiverhigh()
{
RXTimerPoint1 = micros();
}
void RC::readreceiverlow()
{
if(RXTimerPoint1)
{
RXTimerPoint2 = micros();
RXPulseLength = RXTimerPoint2 - RXTimerPoint1;
SetRCOutputSource(ReadReceiver());
}
}
int RC::ReadReceiver()
{
if ((RXPulseLength > 1400)&&(RXPulseLength < 1700))
{
return(1);
}
if ((RXPulseLength < 1300) && (RXPulseLength > 1100))
{
return(0);
}
if ((RXPulseLength<1100)||(RXPulseLength>1700))
{
return(2);
}
}
void RC::SetRCOutputSource (int TXRXorNeither)
{
switch(TXRXorNeither)
{
case 0:
digitalWrite(ArduinoAllowPin, HIGH);
digitalWrite(RXAllowPin, LOW);
break;
case 1:
digitalWrite(ArduinoAllowPin, LOW);
digitalWrite(RXAllowPin, HIGH);
break;
case 2:
digitalWrite(ArduinoAllowPin, LOW);
digitalWrite(RXAllowPin, HIGH);
break;
}
}
/*
RC.h - Library for interacting with radio control equipment
Created by Christopher Lansdale, September 4, 2015
Version 1.0 - Last updated September 4, 2015
*/
#ifndef RC_h
#define RC_h
#include "Arduino.h"
class RC
{
public:
RC(int RXInterrupt_1, int RXInterrupt_2, int RXAllowPinPassIn, int ArduinoAllowPinPassIn);
private:
static void readreceiverhigh();
static void readreceiverlow();
static void SetRCOutputSource(int TXRXorNeither);
static int ReadReceiver();
static float RXTimerPoint1;
static float RXTimerPoint2;
static float RXPulseLength;
static int ReceiverInterrupt_1;
static int ReceiverInterrupt_2;
static int RXAllowPin;
static int ArduinoAllowPin;
};
#endif
I'm going to do more research, but if you see something wrong, please point it out!