Hi,
I'm trying to make a RC controller with an Arduino Uno using examples i found on the internet and tutorials but I've this problem i can't seem to solve. Namely: when I try to add a fourth channel the compiler gives a few errors (I'll post them below). So I was wondering if you guys could help me out a bit with these errors and maybe other things I've done wrong.
Here's my code
#include <PinChangeInt.h>
#define THROTTLE_IN_PIN 8
#define YAW_IN_PIN 9
#define ROLL_IN_PIN 10
#define PITCH_IN_PIN 11
#define THROTTLE_FLAG 1
#define YAW_FLAG 2
#define ROLL_FLAG 4
#define PITCH_FLAG 5
volatile uint16_t bUpdateFlagsShared;
volatile uint16_t unThrottleInShared;
volatile uint16_t unYawInShared;
volatile uint16_t unRollInShared;
volatile uint16_t unPitchInShared;
uint32_t ulThrottleStart;
uint32_t ulYawStart;
uint32_t ulRollStart;
uint32_t ulPitchStart;
void setup()
{
Serial.begin(9600);
Serial.println("RC controller");
PCintPort::attachInterrupt(THROTTLE_IN_PIN, calcThrottle,CHANGE);
PCintPort::attachInterrupt(YAW_IN_PIN, calcYaw,CHANGE);
PCintPort::attachInterrupt(ROLL_IN_PIN, calcRoll,CHANGE);
PCintPort::attachInterrupt(PITCH_IN_PIN, calcPitch,CHANGE);
}
void loop()
{
static uint16_t unThrottleIn;
static uint16_t unYawIn;
static uint16_t unRollIn;
static uint16_t unPitchIn;
static uint16_t bUpdateFlags;
if(bUpdateFlagsShared)
{
noInterrupts();
bUpdateFlags = bUpdateFlagsShared;
if(bUpdateFlags & THROTTLE_FLAG)
{
unThrottleIn = unThrottleInShared;
}
if(bUpdateFlags & YAW_FLAG)
{
unYawIn = unYawInShared;
}
if(bUpdateFlags & ROLL_FLAG)
{
unRollIn = unRollInShared;
}
if(bUpdateFlags & PITCH_FLAG)
{
unPitchIn = unPitchShared;
}
bUpdateFlagsShared = 0;
interrupts();
}
Serial.println(unThrottleIn);
bUpdateFlags = 0;
}
void calcThrottle()
{
if(digitalRead(THROTTLE_IN_PIN) == HIGH)
{
ulThrottleStart = micros();
}
else
{
unThrottleInShared = (uint16_t)(micros() - ulThrottleStart);
bUpdateFlagsShared |= THROTTLE_FLAG;
}
}
void calcYaw()
{
if(digitalRead(YAW_IN_PIN) == HIGH)
{
ulYawStart = micros();
}
else
{
unYawInShared = (uint16_t)(micros() - ulYawStart);
bUpdateFlagsShared |= YAW_FLAG;
}
}
void calcRoll()
{
if(digitalRead(ROLL_IN_PIN) == HIGH)
{
ulRollStart = micros();
}
else
{
unRollInShared = (uint16_t)(micros() - ulRollStart);
bUpdateFlagsShared |= ROLL_FLAG;
}
}
void calcPitch()
if(digitalRead(PITCH_IN_PIN) == HIGH)
{
ulPitchStart = micros();
}
else
{
unPitchInShared = (uint16_t)(micros() - ulPitchStart);
bUpdateFlagsShared |= PITCH_FLAG;
}
}
And here are the errors:
sketch_sep12a.ino: In function 'void setup()':
sketch_sep12a:42: error: 'calcPitch' was not declared in this scope
sketch_sep12a.ino: In function 'void loop()':
sketch_sep12a:86: error: 'unPitchShared' was not declared in this scope
sketch_sep12a.ino: At global scope:
sketch_sep12a:164: error: expected initializer before 'if'
sketch_sep12a:168: error: expected unqualified-id before 'else'
sketch_sep12a:173: error: expected declaration before '}' token
My apologies if i'm asking something stupid
Greetings,