Hi
I am working on a visual accelerometer, 3 axis, adxl 335, pins on the device= Vin, 3vo, GND, Z out, Y out, X out, and test.
I am running this program in arduino. Its working - when there's motion in y, a green LED goes on, then back to off state when back in its original position. Same for Z axis, but with a blue LED. BUT - - not x...
I am asking for advice on how to program a digitalwrite to LED when there's CHANGE in X axis, rather than when X integer = or != a specific value.
im doing this on one axis, the x, and not all axis
the reason im trying to do this is that my accelerometer seems to give back slowly increasing values even when the device isn't experiencing motion of any kind, but ONLY on the X axis. So, the its impossible to program the LED if the value never returns to its original number. It just keeps going up and up forever.
The other two axis, y and z, are working perfectly, and I've been able to program their respective, designated LEDs when I move the device in those directions. Maybe the accelerometer is just broken! I don't know.
Ive seen a few examples for this type of thing online, but I need to know the ACTUAL terms in the programming language that will help me accomplish this. I am a beginner.
one approach is to subtract trend = new value - old value, and if trend >< 1, etc ..then digitalwrite to LED
BUT - - what are the actual terms I would use in the sketch?!
THANKS FOR YOUR HELP
-a beginner arduino fan
BTW, this is my code if you want to see it:
Moderators note : please use code tags for pieces of code
I am working on a visual accelerometer, 3 axis, adxl 335, pins on the device= Vin, 3vo, GND, Z out, Y out, X out, and test.
I am running this program in arduino. Its working - when there's motion in y, a green LED goes on, then back to off state when back in its original position. Same for Z axis, but with a blue LED. BUT - - not x...
I am asking for advice on how to program a digitalwrite to LED when there's CHANGE in X axis, rather than when X integer = or != a specific value.
im doing this on one axis, the x, and not all axis
the reason im trying to do this is that my accelerometer seems to give back slowly increasing values even when the device isn't experiencing motion of any kind, but ONLY on the X axis. So, the its impossible to program the LED if the value never returns to its original number. It just keeps going up and up forever.
The other two axis, y and z, are working perfectly, and I've been able to program their respective, designated LEDs when I move the device in those directions. Maybe the accelerometer is just broken! I don't know.
Ive seen a few examples for this type of thing online, but I need to know the ACTUAL terms in the programming language that will help me accomplish this. I am a beginner.
one approach is to subtract trend = new value - old value, and if trend >< 1, etc ..then digitalwrite to LED
BUT - - what are the actual terms I would use in the sketch?!
THANKS FOR YOUR HELP
-a beginner arduino fan
BTW, this is my code if you want to see it:
C:
const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
const int apin = 6;
const int bpin = 5;
const int cpin = 3;
void setup()
{
pinMode (xpin, INPUT);
pinMode (ypin, INPUT);
pinMode (zpin, INPUT);
pinMode (apin, OUTPUT);
pinMode (bpin, OUTPUT);
pinMode (cpin, OUTPUT);
Serial.begin (9600);
}
void loop()
{
float x = analogRead(xpin);
delay (500);
float y = analogRead(ypin);
delay (500);
float z = analogRead(zpin);
Serial.print (x); //find a way to change this output to LEDs
Serial.print ("\t");
Serial.print (y); //find a way to change this output to LEDs
Serial.print ("\t");
Serial.print (z); //find a way to change this output to LEDs
Serial.print ("\n");
if (x < 678)
{
digitalWrite (apin, HIGH);
}
if (y <= 464)
{
digitalWrite (bpin, HIGH);
}
if (z <= 4 )
{
digitalWrite (cpin, HIGH);
}
if (x >= 680)
{
digitalWrite (apin, LOW);
}
if (y >= 674)
{
digitalWrite (bpin, LOW);
}
if (z >= 6)
{
digitalWrite (cpin, LOW);
}
}
Last edited by a moderator: