INT, BYTE, CHAR, help with maths.

Folks,

I am off on another project.

This needs a bit of maths behind it and although I think I have that part down, just putting it in a way Arduino understands is a bit difficult.

The sketch so far is WORK IN PROGRESS, so don't bombard me with "things are missing".

I am posting it here to get help on what I need to define/declare the variables as.

Now, I am trying to build structures into my code to maybe become a better programmer. Who knows?

Alas the code is called V1 - as it is version 1.
HSI is one of the sub-routines. Well, the only for now.

It should be self explanatory but just in case:
I have my little Accelerometer/GYRO/thingy sitting there and I turn it on.

Skipping "Zero-ing" it, apart from that in the code, it works out how to show attitude on an LED ring.
(From ADA fruit and each LED is addressable, controllable, etc.. LED NEOPIXEL)

Given that pitch is 0 to +90 or 0 to -90 I calculate how to "share" the leds to values.
There is a Zero Value Offset to tell the program where to show level.
The other offset is if LED #1 is not at the top. (Not used just yet)

Roll I shall hope is the same for values.

Excuse the BASIC way I have done it for now, but as the code said: BASIC PITCH.

There in lies the problem.
0 - 30 is one LED, 31 - 60 is another and 61 - 90 is the third.
Not really good.

Yes, INT() doesn't help.

So if I do (what I seem to remember as "single precision") I will then be able to work out if I need to show TWO LED's.
But what is that in Arduino lingo?

I "need" -90 to +90 range on these two axis.

Sure I can "cheat" and make it 0 - 180 and "-90" from what comes out.
What ever.....

Could someone please help me with this small sticking point?
Thanks in advance.

HSI.ZIP (885 Bytes)

You made this so far:

int ZVO = 3;
int OS = 0;
int LED_Loop = 12;
int QL = LED_Loop/4;

...

//  Basic Pitch
int _A1 = (x / (90/QL)) + ZVO;
int _A2 = LED_Loop - _A1;
  
//  Basic Roll
int _B1 = (y / (90/QL)) + ZVO;
int _B2 = LED_Loop - _B1;

That is very little to say something about it. I would like to know what 'x' and 'y' are, and I don't know the range of the other variables or what they stand for. Sorry, I hope someone else can say something more useful.

You can start by giving meaningful names, and write in the comments what it is (degrees or something else).

OK, sorry Peter.

The X and Y values are what come out of the "thingy" which are probably degrees of X and Y.

Or Pitch and Roll.

ZVO is a "Zero Value Offset" so when the X and Y are at zero, the arduino adds this to turn on LED 3 and 9.
I made an excel spreadsheet to test the maths and it works until you are changing the values less than 30 degrees.

OS is the OffSet which I mentioned and also said isn't used yet.

LED_Loop is how many leds in the loop.
QL is ......... 12./4 in this case.

The input range is probably going to be -90 to +90 from the "thingy" with which I have played so far.