Disabling the accelerometer

i want to disable the function of the accelerometer if I put an LED in A2 (analog output for Arduino Uno) which is in high condition... if it is low condition, the function of the accelerometer can function it back normally.. during high state i want the accelerometer to disable...
my problem is how to make a command to disable the function of the accelerometer... Is it possible to use an IF/ELSE statement here...
can anyone help me??? please...

this is the code for my accelerometer taken from the net...

const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
int xpin = A3;                            // x-axis of the accelerometer
int sensorValue = 0;                    // variable to store the value coming from the sensor

void setup()
{
  // initialize the serial communications:
  Serial.begin(9600);

  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW); 
  digitalWrite(powerpin, HIGH);
}

void loop()
{
  
  // read the value from the sensor:
  sensorValue = analogRead(xpin);    
  
  // print the sensor values:
  Serial.print(analogRead(xpin));
  // print a tab between values:
  Serial.print("\t");
  Serial.println();
  // delay before next reading:
  delay(100);
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

I'm not sure what you're trying to do. The LED has no way of turning off in your code so even if you programmed it to stop taking readings from the accelerometer it won't do anything. How were you planning to toggle the LED on and off?

Lets say you added a button or some other way to toggle the LED on/off then you could only take readings from the accelerometer when powerpin is LOW like this.

if (digitalRead(powerpin) == LOW)
{
Serial.print(analogRead(xpin);
}

While A0 can be used as a DIGITAL I/O pin it can only do ANALOG INPUT. A link to the accelerometer you are using would be helpful.

Why do you want to disable it?

Mark

to Mark:

I am using right now an RF module... If I press the button of the remote of the RF MODULE which is "ON", I want to disable the function of the accelerometer... when it is turn off, I want to go back in normal the function of the accelerometer... just make an on and off to the accelerometer...

So you wan't to talk to the Arduino with an RF remote control and then have it do something? Is this correct?

Mark

To mark:

yes it is... i want to communicate the RF module to the Accelerometer... what can i do to make it???

Some Acceleromers have a Sleep (SL) pin, which I suppose you could activate.

As for 'turning' accelerometer off then surely you could just toggle a variable accell_active = 0|1 and then only read the inputs and use them if it's active.

Pseudo code

declare accell_active and set to 1 (on by default)

if remote control set accelerometer on then set accell_active to 1
if remote control set accelerometer off then set accell_active to 0

if accell_active is 1 then read the accelerometer pins and do any processing
if accell_active is 0 then don't read the accelerometer pins of do any processing

While A0 can be used as a DIGITAL I/O pin it can only do ANALOG INPUT.

That doesn't make sense - "I/O" means "Input/Output".
A0 can be a digital input, a digital output or an analogue input.