We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi im making a simple compass using an arduino and processing, to make things smoother im using "easing code" but when i rotate past 360 instead of rotating right to 0, it takes the long way around. Can someone please help me with this code, i would appreciate it a lot, thanks! :)
Here is my draw() code:
void draw()
{
background(255);
// this is the input.
ArInputComp = controlInput[0] - SmInputComp;
SmInputComp += ArInputComp * 0.1;
pushMatrix();
imageMode(CENTER);
translate(400,300);
rotate((SmInputComp) * TWO_PI/360);
image(img,0,0);
popMatrix();
Serial_Loop();
}
Answers
I think the issue is with the value of
controlInput[0]
what range of values does it produce.Also please explain what the variables
ArInputComp
andSmInputComp
represent?do you know the function radians? It converts degree to radians.
Does arduino deliver degree or radians?
Did you try
Hi quark :D
controlInput[0] goes from 0 to 360
ArInputComp and SmInputComp =
They are just temporary values for the "smoothing/Easing" of the rotation, i dont use them anywhere else in the code :)
Hi Chrisir :D
Arduino delivers degrees, il try your code and see if it works! :)
didnt do much :( thx anyway! :)
Please confirm these statements.
1) controlInout is the angle indicated by the arduino device?
2) SmInputComp is the current rotateion of the image?
3) ArInputComp is the angle from the last rotation value and the current rotation value?
3.Im not sure, i didn't make the equation, i don't know exactly how it works :(
Are SmInputComp and ArInputComp used outside the draw() method?
Working on it :)
Thx! :D no its not outside draw :)
Took me a while because I have been doing other things. The solution is shown below. Obviously I don't have the arduino device to play with so I have simulated it by the mouse position about the window centre (mouse must be inside the red circle to be considered. I have got rid of the variables SmInputComp and ArInputComp and replaced them with currAngle and deltaAngle because these names better represent their meaning.
The ofiginal sketch measures angles in degrees and I have kept to that practice, although it is more usual to use radians.
If you have questions about the code ask away :)
This is exactly what i was looking for! Thank you! :D