Accelerometer ( Road Condition ) Need a sketch

Anyone knows how to program a road condition in switch case statement regarding accelerometer based on its reading.

example:

void accelerometer(int direction)
{
switch(direction)
{

case 1: //forward
digitalWrite()
break;
}
}

Thanks for your help

Could you rephrase your question - it isn't clear (to me) what it is you want to do.

Basically, i have a project regarding road conditions which is (forward,backward,right,left based on accelerometer sensor that detects X-Y axis). My input is 2axis-accelerometer and the output is LED. I need a sketch regarding the road conditions. Example, when a vehicle move forward which is Y axis LED must be turn ON. Example no.2, when a vehicle move backward which is -Y axis LED must be turn ON. Example no. 3, when a vehicle move right which is X axis LED must be turn ON, also in -X axis.

when detect Y axis LED turn ON:
-y axis must off:
x axis must off:
-x axis must off:

Thanks for your reply. Hoping for your reply again :slight_smile:

I'm sorry, I'm still not clear - are you asking about switch/case, or how to combine two axes into one variable "direction"?

Gabertzz:
Basically, i have a project regarding road conditions which is (forward,backward,right,left based on accelerometer sensor that detects X-Y axis). My input is 2axis-accelerometer and the output is LED. I need a sketch regarding the road conditions. Example, when a vehicle move forward which is Y axis LED must be turn ON. Example no.2, when a vehicle move backward which is -Y axis LED must be turn ON. Example no. 3, when a vehicle move right which is X axis LED must be turn ON, also in -X axis.

when detect Y axis LED turn ON:
-y axis must off:
x axis must off:
-x axis must off:

Thanks for your reply. Hoping for your reply again :slight_smile:

Unless gravity points along your road, there's no way to do it. Accelerometers can tell tilt angles but can't tell orientations. Try magnetic sensor or digital compass. They can but they're also limited thus the IMU, with both accelerometer and compass, and maybe even a gyro, to tell orientations and tilt angles.