I use a ps3 joystick to control a variable . When I use the joystick to the maximum i noticed that when the variable is low the progress of increasing the variable is much slower than when the variable is higher.
#include <PS3USB.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
USB Usb;
/* You can create the instance of the class in two ways */
PS3USB PS3(&Usb); // This will just create the instance
//PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
bool printAngle;
uint8_t state = 0;
// Arduino code for Neopixel LED controller
// using a joystick
// (C) Ismail Uddin, 2015
// www.scienceexposure.com
#include <Adafruit_NeoPixel.h>
#define PIN 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);
// set pin numbers for joystick axes:
const int xAxis = LeftHatY; // Right joystick Y axis
const int yAxis = LeftHatY; // Left joystick Y axis
// parameters for reading the joystick:
int range = 50; // output range of X or Y movement
int responseDelay = 0; // response delay of the mouse, in ms
int threshold = range / 4; // resting threshold
int center = range / 2; // resting position value
int reading = 0;
int readingtemp = 0;
int readingbyte = 0;
int prevreadingbyte = 0;
int lengtepot = 20;
int val = 0;
int x;
int prevVal = 0;
int ps3check = 0;
void setup()
{
// put your setup code here, to run once:
delay(2000);//give ps3 controller time for startup
// open a serial connection to display values
Serial.begin(115200); // 9600);
#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start/r/n"));
Serial.print(F("\r\n"));
strip.setPixelColor(0,255,0,0);
strip.show();
while (1); //halt
}
Serial.print(F("\r\nPS3 USB Library Started"));
Serial.print(F("\r\n"));
strip.setPixelColor(0,0,255,0);
strip.show();
strip.begin();
strip.show();
}
void loop() {
Usb.Task();
if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
int xReading = readAxis(LeftHatY);
reading=reading+xReading;
readingbyte = reading/8;
val = map(reading, 0, 1023, 0, lengtepot);
if (readingbyte != prevreadingbyte)
{
Serial.print("FF 01 ");
Serial.println(readingbyte,HEX);
prevreadingbyte = readingbyte;
}
int readAxis(int thisAxis) {
int reading = PS3.getAnalogHat(thisAxis);//read the ps3 input:
reading = map(reading, 0, 255, range, 0); // map the reading from the ps3 input range to the output range:
int distance = reading - center;// if the output reading is outside from the rest position threshold, use it:
if (abs(distance) < threshold) {
distance = 0;
}
// return the distance for this axis:
return distance;