I've got a simple sketch which I want to branch to different subroutines based on the character received. I'm getting the message:
"In function 'void loop(); error: 'forward_back' was not declared in this scope."
Does it think it's a variable? I thought the parens would tag it as a subroutine.
#include <Servo.h>
int servoPanPin = 9; // Control pin for pan servo motor
int servoTiltPin = 10; // Control pin for tilt servo motor
int pos = 0; // position
int count = 0;
char command;
Servo panServo;
Servo tiltServo;
void setup()
{
Serial.begin(9600);
panServo.attach(servoPanPin);
tiltServo.attach(servoTiltPin);
}
void loop()
{
if ( Serial.available())
{
char ch = Serial.read();
if(ch >= '0' && ch <= '9') { // check to see if its a number
pos = pos * 10 + ch - '0'; // if so, accumulate the value
}
else if (ch == 'T')
{
forward_back(); // go to forward_back subroutine
}
else if (ch == 'P')
{
left_right(); // go to left_right subroutine
}
void forward_back(){
tiltServo.write(pos);
pos = 0;
}
void left_right(){
panServo.write(pos);
pos = 0;
}
}
}
Right now I really don't need to go to a sub, but I've got to some additional processing and I want to keep them in their own block.
Thanks,
Dave