auto calibrate zero for ps joystick


result sent on zigbee, everything's working fine, feels more concise because have more axises want control , feels clunky, if have 3 or more time per loop... oh , way controlling motion @ point...

the gist if don't want dl .ino
the analog value (really hoping it's @ rest @ point) captured in setup loop, , mapped  against more granular output (0-5000), set midpoint virtue of couple re-maps (0-setup val = map1  & setup val - 1023 = map2    combine map1&2 , map less granular desired range)

how do more efficiently... or thinking wrong go?

thanks in advance :)

rtfm okay got code embed now...
code: [select]

/*
circuit:

controller pinout
1  right button    (red stripe)
2  right x    a2
3  right y    a3
4  gnd
5  vcc
6  left x    a0
7  left y    a1
8  left button

bottom view:
                    red stripe
[ ] [ ] [8] [6] [4] [2]
[ ] [ ] [7] [5] [3] [1]
 
*/
#include <softwareserial.h>
softwareserial xbee(2, 3); // rx, tx

const int joystick1x = a0;  // analog input pin potentiometer attached to

int joystick1xval = 0;        // value read pot
int joystick1xout = 0;        // mapped output
int temp1 = 0;                // temp holders calc top , bottom halves of map
int temp2 = 0;                // etc...
int temp3 = 0;
int temp4 = 0;

void setup() {
  serial.begin(9600);
  xbee.begin(9600);
  temp3 = analogread(joystick1x); // grab baseline calibrate to
}

void loop() {

  joystick1xval = analogread(joystick1x);     // read analog in value:
  temp1 = map(joystick1xval, temp3, 1023, 0, 5000);    // map bottom half of range
  temp2 = map(joystick1xval, 0, temp3, 0, 5000)-5000;  // map top half of range
  temp4 = temp1 + temp2;
  joystick1xout = map(temp4,-10000 ,10000, 0, 100);
  xbee.write( joystick1xout ); 
  // print results serial monitor:
  /* or dont if slow in debug verbose...
  serial.print("sensor 1x = " );                       
  serial.print("\t");     
  serial.print(joystick1xval);
  serial.print("\t");
 
  serial.print("\t output 1x = ");     
  serial.print("\t");     
  serial.print(temp1);
  serial.print("\t");     
  serial.print(temp2);
  serial.print("\t");
  serial.print(temp3);
  serial.print("\t");
  serial.print(temp4);
  serial.print("\t");   
  */
  serial.println(joystick1xout);

  // wait 200 milliseconds before next loop
  delay(200);                     
}


Arduino Forum > Using Arduino > Programming Questions > auto calibrate zero for ps joystick


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support