Created
March 30, 2018 21:56
-
-
Save nirodg/ac173a5ccc9ac141b958904bbb382c61 to your computer and use it in GitHub Desktop.
Potentiometer's degree's position for Arduino
This file contains 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
// author: Dorin Brage | |
// repo: https://github.com/nirodg | |
long maxRotPtr = 1023; // Max potentiometr value | |
long totalDegr = 360; // Max degree | |
long rotationPtr = 0; // Will be fetch from the A0 input | |
const int sensorInput = 0; | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
Serial.print("Position: "); | |
Serial.print(getPositionDegrees(), 0); // 0 (zero) won't display decimals | |
Serial.println(" º degr "); | |
delay(500); | |
} | |
float getPositionDegrees() { | |
rotationPtr = analogRead(sensorInput); | |
return abs((totalDegr * rotationPtr) / maxRotPtr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment