Pages: [1]   Go Down
Author Topic: accelerometer 180 degree rotated  (Read 477 times)
0 Members and 1 Guest are viewing this topic.
Nova Scotia
Offline Offline
Full Member
***
Karma: 4
Posts: 191
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  float tempAccel = readAccel();           
  int abc=acc_data[0];
  display.print((float) abc, 0 );
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some arithmetic, like multiply by -1?
Logged

"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.

NE PA
Offline Offline
Full Member
***
Karma: 5
Posts: 156
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged

Per Arduino ad Astra

Nova Scotia
Offline Offline
Full Member
***
Karma: 4
Posts: 191
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mike
Logged

Pages: [1]   Go Up
Jump to: