Lego motor problem

Hi, I’m an arduino beginner, and I have a problem with my lego motor shield for my arduino uno. I am trying to turn a lego stepper motor 90 degrees. When I upload this code to my arduino, it works:

#include <Wire.h>
#include <Bricktronics.h>
#include <Motor.h>
Bricktronics brick = Bricktronics();
PIDMotor m = PIDMotor(&brick, 1);

void setup()
{
Bricktronics brick = Bricktronics();
brick.begin();
m.begin();
Serial.begin(115200);
}

void loop()
{
m.go_to_pos(180);
m.update();
}
But when I try to involve serial communication, like changing the void loop to this code,:
int pos;
pos = Serial.parseInt();
m.go_to_pos(pos);
m.update();
it starts doing really weird things. Can anybody help?

You declared a variable called brick as a local inside setup() and you called its begin() method. But this doesn’t do anything for the global with the same name.

Please use [ code ] tags next time, with the </> button.