Why is array name used as variables?

Thread Starter

tyro01

Joined May 20, 2021
64
Hi,
I'm seeing VarSpeedServo library for Arduino. This may be a silly question.
In the following code, the array name, sequenceIn is called. What number is assigned to this variable?
C++:
uint8_t VarSpeedServo::sequencePlay(servoSequencePoint sequenceIn[], uint8_t numPositions, bool loop, uint8_t startPos) {
  uint8_t oldSeqPosition = this->curSeqPosition;

  if( this->curSequence != sequenceIn) {
    //Serial.println("newSeq");
    this->curSequence = sequenceIn;
    this->curSeqPosition = startPos;
    oldSeqPosition = 255;
  }

  if (read() == sequenceIn[this->curSeqPosition].position && this->curSeqPosition != CURRENT_SEQUENCE_STOP) {
    this->curSeqPosition++;

    if (this->curSeqPosition >= numPositions) { // at the end of the loop
      if (loop) { // reset to the beginning of the loop
        this->curSeqPosition = 0;
      } else { // stop the loop
        this->curSeqPosition = CURRENT_SEQUENCE_STOP;
      }
    }
  }

  if (this->curSeqPosition != oldSeqPosition && this->curSeqPosition != CURRENT_SEQUENCE_STOP) {
    // CURRENT_SEQUENCE_STOP position means the animation has ended, and should no longer be played
    // otherwise move to the next position
    write(sequenceIn[this->curSeqPosition].position, sequenceIn[this->curSeqPosition].speed);
    //Serial.println(this->seqCurPosition);
  }

  return this->curSeqPosition;
}
C++:
typedef struct {
  uint8_t position;
  uint8_t speed;
} servoSequencePoint;
C++:
servoSequencePoint slow[] = {{100,20},{20,20},{60,50}};
 

WBahn

Joined Mar 31, 2012
27,893
Not sure what you mean by it being called. You mean called as if it were a function? I don't see that happening anywhere.

The name of an array is a reference to the memory where the array is stored. For most purposes, it's value is the address of the first byte of that memory block.
 

Thread Starter

tyro01

Joined May 20, 2021
64
Thanks WBahn, I see.
I have only worked with data stored in arrays. In essence this means cursor. In the header file, the following pointer was defined.
Code:
servoSequencePoint * curSequence; // for sequences
I understand what this code means.
 
Top