declared but not initialized variable values,, adafruit servo shield

In the adafruit servo-shield examples, there is a section that declares

pulse += 1000

pulse value is not declared before this, and the variable is also not declared. I did not see where pulse was declared in the library.

what value do variables carry before they are initialized? does arduino IDE default them to 0, or is it like C++ (I am learning a little now) where variables carry random data which previously occupied the space allocated by the declaration, which will not be overwritten until the variable is initialized somehow (either by the code or by some input within the code). ???

I want to interpret the servo shield examples into an understanding, but when I read them there are a lot of words that are used but not declared until that time, and the first use does not match otherwise described proper variable declaration practice. (although the examples run just fine).

what value do variables carry before they are initialized?

If the variable is global, and is of type int, the initial value will be 0.

If the variable is local, the initial value will be whatever was in the memory location that the variable is assigned to. That is, some random garbage.

The behavior is NOT specific to Arduino. It is common C/C++ behavior.

If compilation is successful, it must be declared somewhere. Post a link to the library.

Here is the github for the library,, alternatively you can google search "adafruit servo shield learn" and there is a zip link in the tutorial.

I dont really have the ability to pull mich information from reading the cpp and header files of libraries yet. The functions of most libraries seem like every word is a function of some other file not in the collection,,, i probably just need more time on it..

Only place I see a variable called pulse is in the example called "servo" here:

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;
  
  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= 60;   // 60 Hz
  Serial.print(pulselength); Serial.println(" us per period"); 
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit"); 
  pulse *= 1000;
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

'pulse' is a variable of type double and it's a parameter of the function 'setServoPulse'.
Or is it an argument? always get those mixed up.

right, so *= doesn’t mean pulse is 1000, it means multiply pulse by 1000, and set pulse to the product. if pulse is 0, that line doesn’t make sense, and if pulse is random data from allocated space, that line doesn’t make sense, so what does that mean??

gfvalvo:
Only place I see a variable called pulse is in the example called “servo” here:

// you can use this function if you'd like to set the pulse length in seconds

// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;
 
  pulselength = 1000000;  // 1,000,000 us per second
  pulselength /= 60;  // 60 Hz
  Serial.print(pulselength); Serial.println(" us per period");
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit");
  pulse *= 1000;
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}



'pulse' is a variable of type double and it's a parameter of the function 'setServoPulse'.
Or is it an argument? always get those mixed up.

It means the value of 'pulse' is passed as an argument to the function 'setServoPulse' when that function is called. You'd have to check where that call takes place to know the actual value.

You can read about functions here:
https://www.arduino.cc/en/Reference/FunctionDeclaration

That function is not used anywhere in the servo example. Normal usage of that function is shown in the comments just before the the function

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!

Assuming n is a pin number (I did not dig through the library and datasheets), below a thumb-suck example.

const byte pwmPin = 3;
void setup()
{
  ...
  ...
}

void loop()
{
  double width = 1.23456789;
  pulse(pwmPin, width);
}