hmc6352 set north

Hi all! Im using the following code for servo position according to compass module north position.
How can i set the servo to current position any time i push a button? For example, if the compass is to 90 deg. east, then i push a button and the servo set as default position the 90 deg.
Could you help me in code changes?
Thank you!

#include <Wire.h>
#include <Servo.h>

// Pins
#define SDA 4 // analog
#define SCL 5 // analog
#define servoPointerPin 10

// Controllers
Servo servoPointer;

void setup()
{
  Serial.begin( 4800 );
  delay( 500 );
  setupCompass();
  setupServo();
  Serial.println( "Setup Complete" );
}

void setupCompass()
{
  Wire.begin();
}

void setupServo()
{
  servoPointer.attach( servoPointerPin );
  positionServo( &servoPointer, 50 );
}

void positionServo( Servo* pServo, int position )
{
  int currentPosition = pServo->read();
  if( currentPosition != position )
    pServo->write( position );
}

int lastHeading = -1;

bool getCurrentHeading( int& reading )
{
  int compassAddress = 0x42 >> 1;
  Wire.beginTransmission( compassAddress );
  Wire.send( 'A' );
  Wire.endTransmission();

  delay(10);  
  Wire.requestFrom( compassAddress, 2 );
  while( Wire.available() < 2 )
    delay(10);

  int newReading = Wire.receive();
  newReading = newReading << 8;
  newReading += Wire.receive();
  newReading /= 10;
  bool result = ( lastHeading == -1 ) ? true : ( abs( newReading - lastHeading ) > 2 );
  reading = newReading;
  if( result )
    lastHeading = reading;  
  return result;
}

void loop()
{
  int heading = 0;
  if( getCurrentHeading(heading) )
    PositionNeedle( heading );
}

void PositionNeedle( const int currentHeading )
{
  int bearing = -currentHeading;
  if( bearing < 0 )
    bearing += 360;

  Serial.print( "Bearing=" );
  Serial.print( bearing, DEC );
  float minSweep = 80.0f;
  float sweepRange = 145.0f - minSweep;
  int servoPosition = (int)(sweepRange - (bearing / 360.0f * sweepRange) + minSweep);
  Serial.print( " Servo=" );
  Serial.println( servoPosition, DEC );
  positionServo( &servoPointer, servoPosition );
}

The code you posted does something. You failed to say what it actually does. How are we supposed to help you make it better, when we don't know what it actually does, or how that differs from what you want it to do?

Hi PaulS and thank you for your replay! Im using a hmc 6352 compass module and a 360 deg. servo is connected to din 10. When the arduino turn on, the servo set the arm position always to north.
So, i want to connect a button and if the compass looks, for example, to south, then i push the button and the position of servo set to south etc.

When the arduino turn on, the servo set the arm position always to north.

So, it works properly, but you want to do something different. I don't understand what or why, but don't let that stop you.

Yes, i want to set the "north" to different position by push a button.

Yes, i want to set the "north" to different position by push a button.

So, what is the problem? Which pin is the "button" connected to?

No mate, the problem is that i did a lot of code changes without success. Could you help me on code?

Could you help me on code?

If you can answer the questions I've asked.

Im using uno and the button is connected to di 2

Im using uno and the button is connected to di 2

This is like pulling hens teeth. HOW is the switch wired? Why haven't you made any effort to read the pin state?

EXACTLY what value do you want to write to the servo when the switch BECOMES pressed? Or, is that when the switch IS pressed? They are not the same...