Code for my droid getting error

so here is the code I am working on… I am trying to run a sabortooth 2/24 motor control in rc mode. to control 2 dc motors… I am getting a error that I cant get resolved

//Droid particle Photon sketch.
#include <blynk.h>
//------------------------------------------------------------------------------------
Servo serv; 
int pos = 0;

//------------------------------------------------------------------------------------
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL)); // selects the u.FL antenna

//------------------------------------------------------------------------------------
//blynk auth token
char auth[] = "b908e54ad8b848c688c2b15133aa8def"; 

//------------------------------------------------------------------------------------
 #define Relayon D3 //connect D3 pin to arduino relay 
 #define Joystick1 D0 // joystick forward
 #define Joystick2 D1 // joystick left right
 #define Headservo D2 //left right head turn
//-----------------------------------------------------------------------------------
void setup()
{
    Serial.begin(9600);
    delay(5000); // Allow board to settl

//-------------------------------------------------------------------------------------
serv.attach(Joystick1);
serv.attach(Joystick2);

     Spark.function("setpos", setPos); 
     Spark.variable("getpos", &pos, INT); 

//-------------------------------------------------------------------------------------
//Turn OFF any power to the pins
    digitalWrite(Relayon,HIGH);
    
    
    Blynk.begin(auth);
    
//-------------------------------------------------------------------------------------
// set all pins as output
     pinMode(Relayon, OUTPUT);
     pinMode(Joystick1, OUTPUT);
     pinMode(Joystick2, OUTPUT);
     pinMode(Headservo, OUTPUT);
    }

//---------------------------------------------------------------------------------------
void loop()
{

//----------------------------------------------------------------------------------------
int setPos(String pstn)
{
     pos = pstn.toInt(); 
     serv.write(pos); 
     return pos; 
 
}
//----------------------------------------------------------------------------------------
    Blynk.run();
}

And we should guess the error I suppose?

Not sure what all the commented dashes are for, since they definitely don't contribute to readability. Furthermore, try making sure you use correct indentation and keep your brackets matched up.
My guess is that your function can't be found, which is not surprising, considering where it's located :wink:

You're also using the outdated 'Spark' rather than the current 'Particle', as well as the old variable notation.

A quick look at the docs would go a long way.

1 Like

yea sorry I was trying to keep everything separate with all the lines and dashes… here is the error code
droid.ino:53:1: a function-definition is not allowed here before ‘{’ token

Keeping things organized isn’t a bad things, but then do try to keep things a bit more consistent. It’s currently randomly thrown around, which makes things harder to read than without.

That said, if you carefully do your indentation, and double check your brackets, you should be able to find the error relatively quickly. Have a look :wink:

1 Like