I keep getting a "AFMS" was not declared in the scope

I’m trying to run a program with a pixycam 2 with an Arduino Uno and Adafruit motor shield 2.3 and I keep getting afms was not declared in scope as a error message. This is the code for the pixycam2 and arduino
#include <Adafruit_MotorShield.h>

#include <PIDLoop.h>
#include <Pixy2.h>
#include <Pixy2CCC.h>
#include <Pixy2I2C.h>
#include <Pixy2Line.h>
#include <Pixy2SPI_SS.h>
#include <Pixy2UART.h>
#include <Pixy2Video.h>
#include <TPixy2.h>

#include <SPI.h>
#include <Pixy2.h>
#include <Wire.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *leftMotor = AFMS.getMotor(1);
Adafruit_DCMotor *rightMotor = AFMS.getMotor(2);

//AFMS.getMotor(1); //Left Motor on Motorshield
//AFMS.getMotor(2); //Right Motor on Motorshield

#define X_CENTER 160L //Taken from the Pixy CMUcam5 code
#define Y_CENTER 100L
#define RCS_MIN_POS 0L
#define RCS_MAX_POS 1000L

// Servo Loop Class
// A Proportional/Derivative feedback
// loop for pan/tilt servo tracking of
// blocks.
class ServoLoop
ServoLoop(int32_t proportionalGain, int32_t derivativeGain);

void update(int32_t error);

int32_t m_pos;
int32_t m_prevError;
int32_t m_proportionalGain;
int32_t m_derivativeGain;

// ServoLoop Constructor
ServoLoop::ServoLoop(int32_t proportionalGain, int32_t derivativeGain)
m_proportionalGain = proportionalGain;
m_derivativeGain = derivativeGain;
m_prevError = 0x80000000L;

// ServoLoop Update
// Calculates new output based on the measured
// error and the current state.
void ServoLoop::update(int32_t error)
long int velocity;
char buf[32];
if (m_prevError!=0x80000000)
velocity = (error*m_proportionalGain + (error - m_prevError)*m_derivativeGain)>>10;

m_pos += velocity;
if (m_pos>RCS_MAX_POS)
m_pos = RCS_MAX_POS;
else if (m_pos<RCS_MIN_POS)
m_pos = RCS_MIN_POS;
m_prevError = error;
// End Servo Loop Class

Pixy2 pixy2; // The camera used

ServoLoop panLoop(200, 200); // Servo loop for pan
ServoLoop tiltLoop(150, 200); // Servo loop for tilt

// Setup
void setup()




uint32_t lastBlockTime = 0;

// Main loop
void loop()
uint16_t blocks;
blocks = pixy.getBlocks();

// If we have blocks in sight, track and follow them
if (blocks)
int trackedBlock = TrackBlock(blocks);
lastBlockTime = millis();
else if (millis() - lastBlockTime > 100)



int oldX, oldY, oldSignature;

// Track blocks via the Pixy pan/tilt mech
// (based in part on Pixy CMUcam5 pantilt example)
int TrackBlock(int blockCount)
int trackedBlock = 0;
long maxSize = 0;

Serial.print(“blocks =”);

for (int i = 0; i < blockCount; i++)
if ((oldSignature == 0) || (pixy.blocks*.signature == oldSignature))*

  • {*
    long newSize = pixy.blocks_.height * pixy.blocks*.width;
    if (newSize > maxSize)
    trackedBlock = i;
    maxSize = newSize;
    int32_t panError = X_CENTER - pixy.blocks[trackedBlock].x;
    int32_t tiltError = pixy.blocks[trackedBlock].y - Y_CENTER;
    _ panLoop.update(panError);
    pixy2.setServos(panLoop.m_pos, tiltLoop.m_pos);
    _ oldX = pixy2.blocks[trackedBlock].x;
    oldY = pixy2.blocks[trackedBlock].y;
    oldSignature = pixy2.blocks[trackedBlock].signature;
    return trackedBlock;
    // Follow blocks via the robot drive*
    // This code makes the robot base turn
    // and move to follow the pan/tilt tracking
    // of the head.
    int32_t size = 400;
    void FollowBlock(int trackedBlock)
    * int32_t followError = RCS_CENTER_POS - panLoop.m_pos; // How far off-center are we looking now?*
    * // Size is the area of the object.
    // We keep a running average of the last 8.
    size += pixy2.blocks[trackedBlock].width * pixy2.blocks[trackedBlock].height;
    size -= size >> 3;
    // Forward speed decreases as we approach the object (size is larger)
    int forwardSpeed = constrain(400 - (size/256), -100, 400);
    // Steering differential is proportional to the error times the forward speed*
    int32_t differential = (followError + (followError * forwardSpeed))>>8;
    * // Adjust the left and right speeds by the steering differential.
    int leftSpeed = constrain(forwardSpeed + differential, -400, 400);
    int rightSpeed = constrain(forwardSpeed - differential, -400, 400);
    // And set the motor speeds*
    * leftMotor.setSpeed(100);
    // Random search for blocks*
    // This code pans back and forth at random
    // until a block is detected
    int scanIncrement = (RCS_MAX_POS - RCS_MIN_POS) / 150;
    uint32_t lastMove = 0;
    void ScanForBlocks()
    * if (millis() - lastMove > 20)
    lastMove = millis();_
    panLoop.m_pos += scanIncrement;
    if ((panLoop.m_pos >= RCS_MAX_POS)||(panLoop.m_pos <= RCS_MIN_POS))
    _ {
    tiltLoop.m_pos = random(RCS_MAX_POS * 0.6, RCS_MAX_POS);
    scanIncrement = -scanIncrement;
    if (scanIncrement < 0)
    * {
    delay(random(250, 500));
    pixy2.setServos(panLoop.m_pos, tiltLoop.m_pos);
    _ }
    Thank you for any help_

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don’t want to be in the code tags. If your browser doesn’t show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup (the italics in your code above, for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the “How to use this forum” post. Please read it.

Please do this:

  • When you encounter an error, you’ll see a button on the right side of the orange bar “Copy error messages” in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button…
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum’s 9000 character limit, save it to a .txt file and podst it as an attachment. If you click the “Reply” button here, you will see an “Attachments and other settings” link.

AFMS and AMFS are not the same thing.

Just a guess because the error message was not properly posted.

One of these things is not like the others:

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *leftMotor = AFMS.getMotor(1);
Adafruit_DCMotor *rightMotor = AFMS.getMotor(2);

Thank you for the help, i updated a new post with the fixed code tags and a couple new error messages, apologies for the first post being badly drafted.