Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (47 sloc) 1.33 KB
/*
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 <XYReplacer.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 XYReplacer(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()));
}
/**
Return title of the input joystick move.
*/
String moveTitle(const Joystick::Move move) {
if (move == Joystick::Move::NOT) {
return "NOT";
} else if (move == Joystick::Move::PRESS) {
return "PRESS";
} else if (move == Joystick::Move::UP) {
return "UP";
} else if (move == Joystick::Move::DOWN) {
return "DOWN";
} else if (move == Joystick::Move::RIGHT) {
return "RIGHT";
} else if (move == Joystick::Move::LEFT) {
return "LEFT";
} else {
return "???";
}
}
You can’t perform that action at this time.