Created
April 24, 2013 09:32
-
-
Save nilclass/5450937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
int offsetX = 514, offsetY = 504; | |
float minX = -270, maxX = 264; | |
float minY = -271, maxY = 278; | |
void setup() { | |
Serial.begin(9600); | |
} | |
float calcAngle(float _x, float _y) { | |
float x = _x / maxX, y = _y / maxY; | |
float c = sqrt(pow(x, 2) + pow(y, 2)); | |
return (acos(x / c) + (y < 0 ? PI : 0))/(2*PI) * 360.0; | |
} | |
void loop() { | |
int x = analogRead(A0) - offsetX; | |
int y = analogRead(A1) - offsetY; | |
Serial.println(calcAngle((float)x, (float)y), DEC); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment