In one of my engineering classes we were posed with the challenge of writing a program in which you used an accelerometer to control 3 different LED's. The premise was: "Write a program which detects when the accelerometer indicates an ecceleration > 0.5g in one axis. While the acceleration in direction (X/Y/Z) is greater thean the threshold, the corresponding LED should be on When the acceleration is less than the threshold, the LED should be off". I am completely new to Arduino and tried what I could so I understand if this is terribly written, but I'm looking for any help I can get. Thanks in advance.
// x is A0
// y is A1
// z is A2
// pin13 is X
// pin10 is y
// pin07 is z
int xPin = A0;
int yPin = A1;
int zPin = A2;
int LED1Pin = 13;
int LED2Pin = 10;
int LED3Pin = 07;
int x = 0;
int y = 0;
int z = 0;
void setup()
{
Serial.begin(9600);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
pinMode(LED1Pin, OUTPUT);
pinMode(LED2Pin, OUTPUT);
pinMode(LED3Pin, OUTPUT);
}
void loop()
{
x = analogRead(xPin);
if (x > .5)
{ digitalWrite(LED1Pin, HIGH); }
else
{ digitalWrite(LED1Pin, LOW); }
y = analogRead(yPin);
if (y > .5)
{ digitalWrite(LED2Pin, HIGH); }
else
{ digitalWrite(LED2Pin, LOW); }
z = analogRead(zPin);
if (z > .5)
{ digitalWrite(LED3Pin, HIGH); }
else
{ digitalWrite(LED3Pin, LOW); }
}