arduino coding question

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
jasonp
Posts: 2
Joined: Fri Sep 09, 2011 11:16 pm

arduino coding question

Post by jasonp »

I'm new to Arduino coding, so forgive me if this is a dumb question:
I'm looking at the V1.0 code and I think I see a few instances of referencing non-declared variables. I mean they've been initiated but no value is assigned to them. Are they assigned a value of 0 by default? For example:
static uint32_t rcTime;
static uint8_t armed = 0;
float error;
float dTerm;
float timeFactor;
float windUp = 1000.0;
float tmp;
static float errorI[3];
static float lastGyro[3];
static float delta1[3];
static float delta2[3];
uint16_t maxMotor;
static uint8_t rcDelayCommand; // this indicates the number of time (multiple of RC measurement at 50Hz) the sticks must be maintained to run or cut the motors
static uint32_t LEDTime;
static uint8_t statusLED = 1;

if (currentTime > (rcTime + 20000) ) { // 50Hz
computeRC();


here, rcTime has been intialized, but no value has been assigned to it. So I'm confused how this statement (currentTime > (rcTime + 20000) ) is true or false unless there is a defult value for non-declared variables. Thanks for the time guys!

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: arduino coding question

Post by timecop »

static vars are initialized to zero. non-static are not.

jasonp
Posts: 2
Joined: Fri Sep 09, 2011 11:16 pm

Re: arduino coding question

Post by jasonp »

great! thank you so much for your help. The code wasn't making too much sense before that clarification.

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: arduino coding question

Post by timecop »

If you notice rcTime is actually assigned right inside that if() statement.
Of course, its initial value is 0 due to it being static, so when currentTIme reaches > 20000 rcTime gets set to that.

Post Reply