This repository has been archived on 2020-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
arduino_universal_serial_ad.../Universal_Serial_Adapter/UIJoystickPSP.h

51 lines
1.3 KiB
C
Raw Normal View History

/*
Serial Adapter Project: Dynamic serial TTY passthroughs
by: Mike Crosson
Nusku Networks
date: 2013/03/09
license: CC-BY SA 3.0 - Creative commons share-alike 3.0
use this code however you'd like, just keep this license and
attribute.
*/
// PSP joystick tracking
long pspUpCount = 0; // Used to slow down how fast we repeat up movement
long pspDownCount = 0; // Used to slow down how fast we repeat down movement
int pspXAxisValue;
int pspYAxisValue;
// Read the x/y values from the joystick
pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10);
pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10);
// Move cursor Up
if (pspYAxisValue > 6 ) {
pspUpCount++;
if (pspUpCount > 768) {
pspUpCount = 0;
serialmode newMode = (serialmode)(selectedMode - 1);
if (newMode >= 0) {
//FIXME: Re-enable once new LCD is online
//setSelection(newMode);
}
}
}
else {
pspUpCount = 0;
}
// Move cursor Down
if (pspYAxisValue < 4 ) {
pspDownCount++;
if (pspDownCount > 768) {
serialmode newMode = (serialmode)(selectedMode + 1);
if (newMode <= modelinespeed) {
//FIXME: Re-enable once new LCD is online
//setSelection(newMode);
}
pspDownCount = 0;
}
}
else {
pspDownCount = 0;
}