Go Down

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


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 );


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.


I believe you can use the map function to reverse a set of points like this:
y = map(x, 1, 50, 50, 1);


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.
The art of getting good answers lies in asking good questions.


@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.
Per Arduino ad Astra


Multiplying by -1 was the first thing I tried and works fine. Thanks to all who replied.


Go Up