Thanks, it is pretty much your joystick code, but with some minor changes here and there.Bennachie wrote:In my topside code, the variables I am using for the joystick inputs are slider, xaxis, yaxis and zaxis. Pretty much the first lines in the main loop.
I'm not sure how you are reading your joystick but looking at your graph, it seems you are succeeding in reading values from the stick and putting them in to some sort of variables.
Start with the vertical axis first. If you can get the value from one of your joystick axes and assign it to the variable 'slider', you should be able to get the verts working.
You could always post the code you are using to read the stick here and I could try to stitch it in to mine. I'm away from home all week so it may take me a bit of time to get around to it though.
It would be amazing if you could help me stitch it together with your topside code, I will continue to try and I will get back to you if I get it working before you get it working.
Thanks for all the help so far and I hope that you have a good day.
- Rasmus
Code: Select all
#include <EasyTransfer.h>
#include <Wire.h>
#define baudRate 9600 // Serial port baud rate
#include <Servo.h>
#include "joystick.h"
Servo panservo;
Servo tiltservo;
Servo vertservo1;
Servo vertservo2;
Servo latservo;
Servo portaftservo; n
Servo stbdaftservo;
Servo stbdfwdservo;
Servo portfwdservo;
Servo dimmer;
int hat = 0x0F;
int panvalue = 2500;
int panvaluescale;
int tiltvalue = 2500;
int tiltvaluescale;
int buttons_1_8 = 0;
int buttons_9_13 = 0;
int vertvalue1 = 127;
int vertvalue2 = 127;
int vertvalue1scale;
int vertvalue2scale;
int portaftvalue = 127;
int portaftvaluescale;
int stbdaftvalue = 127;
int stbdaftvaluescale;
int stbdfwdvalue = 127;
int stbdfwdvaluescale;
int portfwdvalue = 127;
int portfwdvaluescale;
int dimmervalue;
int dimmervaluescale;
int dimmerlatch = 0;
void setup() {
panservo.attach(2);
tiltservo.attach(3);
vertservo1.attach(4,1000,2000);
vertservo2.attach(5);
portaftservo.attach(6);
stbdaftservo.attach(7);
portfwdservo.attach(8);
stbdfwdservo.attach(9);
// dimmer.attach(13);
panservo.write(89);
tiltservo.write(89);
vertservo1.write(1000);
vertservo2.write(89);
portaftservo.write(89);
stbdaftservo.write(89);
portfwdservo.write(1000);
stbdfwdservo.write(89);
Serial1.begin(baudRate);
delay(20);
analogWrite(13, 255);
delay(20);
analogWrite(13, 0);
delay(20);
analogWrite(13, 255);
delay(20);
analogWrite(13, 0);
}
void loop() {
get_joystick();
if(joystick_ok==1)
{
vertvalue1 = (255-tdata[6]);
vertvalue1scale = map(vertvalue1, 0, 255, 0, 180);
vertservo1.write(vertvalue1scale);
vertvalue2 = (255 - joystick.joystick_z);
vertvalue2scale = map(vertvalue2, 0, 255, 0, 179);
vertservo2.write(vertvalue2scale);
portaftvalue = (((joystick.joystick_rz) - (joystick.joystick_x) - (joystick.joystick_y)) + 255);
if (portaftvalue >= 255){
portaftvalue = 255;
}
if (portaftvalue <= 0){
portaftvalue = 0;
}
stbdaftvalue = (((joystick.joystick_x) - (joystick.joystick_y) - (joystick.joystick_rz)) + 255);
if (stbdaftvalue >= 255){
stbdaftvalue = 255;
}
if (stbdaftvalue <= 0){
stbdaftvalue = 0;
}
portfwdvalue = (((joystick.joystick_x) - (joystick.joystick_y) + (joystick.joystick_rz)));
if (portfwdvalue >= 255){
portfwdvalue = 255;
}
if (portfwdvalue <= 0){
portfwdvalue = 0;
}
stbdfwdvalue = (512 - ((joystick.joystick_x) + (joystick.joystick_y) + (joystick.joystick_rz)));
if (stbdfwdvalue >= 255){
stbdfwdvalue = 255;
}
if (stbdfwdvalue <= 0){
stbdfwdvalue = 0;
}
portaftvaluescale = map(portaftvalue, 0, 255, 0, 179);
portaftservo.write(portaftvaluescale);
stbdaftvaluescale = map(stbdaftvalue, 0, 255, 0, 179);
stbdaftservo.write(stbdaftvaluescale);
portfwdvaluescale = map(portfwdvalue, 0, 255, 0, 179);
portfwdservo.write(portfwdvaluescale);
stbdfwdvaluescale = map(stbdfwdvalue, 0, 255, 0, 179);
stbdfwdservo.write(stbdfwdvaluescale);
hat = joystick.hat;
if (hat == 0x06 or hat == 0x07 or hat == 0x08){
if (panvalue < 10000){
panvalue = panvalue + 1;
panvaluescale = map(panvalue, 0, 5000, 0, 179);
panservo.write(panvaluescale);
}
}
if (hat == 0x02 or hat == 0x03 or hat == 0x04){
if (panvalue > 0){
panvalue = panvalue - 1;
panvaluescale = map(panvalue, 0, 5000, 0, 179);
panservo.write(panvaluescale);
}
}
if (hat == 0x08 or hat == 0x01 or hat == 0x02){
if (tiltvalue < 4500){
tiltvalue = tiltvalue + 1;
tiltvaluescale = map(tiltvalue, 0, 5000, 0, 179);
tiltservo.write(tiltvaluescale);
}
}
if (hat == 0x04 or hat == 0x05 or hat == 0x06){
if (tiltvalue > 500){
tiltvalue = tiltvalue - 1;
tiltvaluescale = map(tiltvalue, 0, 5000, 0, 179);
tiltservo.write(tiltvaluescale);
}
}
buttons_1_8 = joystick.buttons_1_8;
if (bitRead(buttons_1_8, 0) == 1 and hat == 0x0F){
panvalue = 2500;
panvaluescale = map(panvalue, 0, 5000, 0, 179);
panservo.write(89);
tiltvalue = 2500;
tiltvaluescale = map(tiltvalue, 0, 5000, 0, 179);
tiltservo.write(89);
}
buttons_9_13 = joystick.buttons_9_13;
if ((bitRead(buttons_9_13, 3) == 1) and dimmerlatch == 0 and dimmervalue < 10){
dimmervalue = dimmervalue +1;
dimmervaluescale = map(dimmervalue, 0, 10, 0, 255);
analogWrite(13, dimmervaluescale);
dimmerlatch = 1;
}
if ((bitRead(buttons_9_13, 4) == 1) and dimmerlatch == 0 and dimmervalue > 0){
dimmervalue = dimmervalue -1;
dimmervaluescale = map(dimmervalue, 0, 10, 0, 255);
analogWrite(13, dimmervaluescale);
dimmerlatch = 1;
}
if (bitRead(buttons_9_13, 3) == 0 and bitRead(buttons_9_13, 4) == 0)
dimmerlatch = 0;
}
// Serial.print('X');
// Serial.println(vertvalue1scale);
// Serial.print('Y');
// Serial.println(joystick.joystick_y);
// Serial.print('Z');
// Serial.println(joystick.joystick_z);
// Serial.print('rz');
// Serial.println(joystick.joystick_rz);
// Serial.print('knap');
// Serial.println(joystick.buttons_1_8);
// delay(100);
}