Go Down

### Topic: accelerometer 180 degree rotated (Read 1 time)previous topic - next topic

#### 0miker0

##### Feb 28, 2013, 09:11 pm
I have a graphics display and accelerometer connected to my arduino that shows a ball the middle of the screen when level. When on a angle the ball moves to the right when it should lean towards the left. An easy fix would be to rotate the accelerometer 180 degrees but I was wondering if it can somehow be done in code. At 0 the ball is in the middle, -10 is to right when it should be on the left and 10 is to the left when it should be on the right. Somehow all the negative numbers have to be positive and the positive have to be negative.

Right now this is what I have.

Code: [Select]
`  float tempAccel = readAccel();             int abc=acc_data[0];  display.print((float) abc, 0 );`

#### AWOL

#1
##### Feb 28, 2013, 09:12 pm
Some arithmetic, like multiply by -1?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Quick5pnt0

#2
##### Mar 01, 2013, 12:37 am
I believe you can use the map function to reverse a set of points like this:
y = map(x, 1, 50, 50, 1);

#### PaulS

#3
##### Mar 01, 2013, 12:42 am
Quote
I believe you can use the map function to reverse a set of points like this:

You can use a sledge hammer to swat flies, too. But, does that make sense? Converting n from 1 to 50 is a simple matter of 50 - n + 1. No multiplication or division required.

#### Groove

#4
##### Mar 01, 2013, 08:55 am
@OP,the generic 'trick' is to sum the range of the values, and subtract the new value.
In your example, the range is -10 to +10, so -10 +10=0.
Now, say your accelerometer gives you -5.
0 - (-5) = 5.
Say it gives +3.
0 - 3 = 3.
Very simple arithmetic.