Created
July 30, 2018 21:34
-
-
Save hidsh/ea58a4be0d9e23cd50d0ee13ae1ada8a to your computer and use it in GitHub Desktop.
arduino test tool for calibration of analog joypad
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 <stdio.h> | |
#define JOY_X A0 | |
#define JOY_Y A1 | |
void setup() { | |
pinMode(JOY_X, INPUT); | |
pinMode(JOY_Y, INPUT); | |
Serial.begin(38400); | |
} | |
void loop() { | |
short x, y; | |
static short xmin = 512, xmax = 512; | |
static short ymax = 512, ymin = 512; | |
char s[255]; | |
x = analogRead(JOY_X); | |
y = analogRead(JOY_Y); | |
xmin = min(x, xmin); xmax = max(x, xmax); | |
ymin = min(y, ymin); ymax = max(y, ymax); | |
// X: center (min-max) Y: center (min-max) | |
sprintf(s, "X:%4d (%d-%d), Y:%4d (%d-%d)\n", | |
x, xmin, xmax, y, ymin, ymax); | |
Serial.print(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment