/
ReplaceXY.ino
59 lines (49 loc) · 1.38 KB
/
ReplaceXY.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Replace X- and Y-axis of Joystick
Reads a press of the joystick and displays information
in the default Serial.
https://github.com/YuriiSalimov/AxisJoystick
Created by Yurii Salimov, December, 2018.
Released into the public domain.
*/
#include <Joystick.h>
#include <AxisJoystick.h>
#include <XYReplacerJoystick.h>
#define SW_PIN 5
#define VRX_PIN A1
#define VRY_PIN A2
Joystick* original;
Joystick* xyReplacer;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
original = new AxisJoystick(SW_PIN, VRX_PIN, VRY_PIN);
xyReplacer = new XYReplacerJoystick(original);
}
// the loop function runs over and over again forever
void loop() {
Serial.print("original: " + moveTitle(original->multipleRead()));
Serial.println(" | replace XY: " + moveTitle(xyReplacer->multipleRead()));
delay(500); // optionally, only to delay the output of information in the example
}
/**
Return title of the input joystick move.
*/
String moveTitle(const Joystick::Move move) {
switch (move) {
case Joystick::Move::NOT:
return "NOT";
case Joystick::Move::PRESS:
return "PRESS";
case Joystick::Move::UP:
return "UP";
case Joystick::Move::DOWN:
return "DOWN";
case Joystick::Move::RIGHT:
return "RIGHT";
case Joystick::Move::LEFT:
return "LEFT";
default:
return "???";
}
}