/*
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
*/
// these constants describe the pins. They won't change:
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
const int relay = 2; // Output for the relay
void setup() {
// initialize the LED pin as an output:
pinMode(relay, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
}
void loop()
{
if(analogRead(xpin)>1000001010)
{ digitalWrite(relay, HIGH); }
else if(analogRead(xpin)<0111110110)
{ digitalWrite(relay, HIGH); }
else{digitalWrite(relay, LOW);}
if(analogRead(ypin)>1000001010)
{ digitalWrite(relay, HIGH); }
else if(analogRead(ypin)<0111110110)
{ digitalWrite(relay, HIGH); }
else{digitalWrite(relay, LOW);}
if (analogRead(zpin)>1000001010)
{ digitalWrite(relay, HIGH); }
else if(analogRead(zpin)<0111110110)
{ digitalWrite(relay, HIGH); }
else{digitalWrite(relay, LOW);}
// delay before next reading:
delay(100);
}