Hello, excuse me for my bad english i’m french.
I have one problem with the return value by the joystick.
If i move axe x only, get_y() return 1-get_x() value(WTF)
But if i move axe y only, x and y don’t change…
It’s normal?
I have one FEZ Medusa Shield3D with UDOO(Programming port in Arduino)
thank you for your answers
@ matoran - This is not normal behavior. We will be looking into this and get back to you with the results. What socket are you running the Joystick module on?
@ matoran - Sorry to not have asked this in the first question, but are you using the Due or the Mega/ADK?
1 Like
@ matoran - I was unable to reproduce this issue using an Arduino Mega ADK. Can you post your code so that we may look for any possible issues there?
I use the Due.
The code :
#include <Wire.h>
#include <SPI.h>
#include <Gadgeteering.h>
#include <Mainboards/FEZMedusaShield3D.h>
#include <Modules/Button.h>
#include <Modules/Joystick.h>
#include <Modules/PulseCount.h>
#include <Modules/MotorDriverL298.h>
#include <Modules/CharacterDisplay.h>
#include <string.h>
using namespace gadgeteering;
using namespace gadgeteering::mainboards;
using namespace gadgeteering::modules;
fez_medusa_shield_3d board;
//declare pointers of components
button* my_button;
joystick* my_joystick;
motor_driver_l298* my_motor_driver_l298;
character_display* my_character_display;
pulse_count* my_pulse_count;
pulse_count* my_pulse_count2;
float speed_1 = 0;
int last_speed_1 = 0;
int last_speed_2 = 0;
char str[15];
void setup() {
Serial.begin(9600);
//initialise all pointers
my_button = new button(4);
my_motor_driver_l298 = new motor_driver_l298(1);
my_character_display = new character_display(12);
my_joystick = new joystick(2);
my_pulse_count = new pulse_count(3);
my_pulse_count2 = new pulse_count(10);
}
void loop() {
//clear display
my_character_display->clear();
//max speed is 100, joystick is 1
speed_1 = my_joystick->get_y()*100;
//decelerate motor
if(my_joystick->get_y() < 0.4){
speed_1 = (0.5-my_joystick->get_y())*200*-1;
last_speed_1 -= 1;
//accelerate motor
} else if(my_joystick->get_y() > 0.6){
speed_1 = (my_joystick->get_y()-0.5)*200;
last_speed_1 += 1;
}else{
//else goto stop motor
speed_1 = 0;
if(last_speed_1 > 0){
last_speed_1 -= 1;
}else{
last_speed_1 += 1;
}
}
//turn left
if(my_joystick->get_x() < 0.4){
last_speed_1 -= 1;
//turn right
}else if(my_joystick->get_x() > 0.6){
last_speed_2 -= 1;
//go straight
}else{
last_speed_2 = last_speed_1;
}
my_motor_driver_l298->move_motor(0, last_speed_1);
my_motor_driver_l298->move_motor(1, last_speed_2);
//display value of joystick in display
sprintf(str, "%4.2f", my_joystick->get_x());
my_character_display->print(str);
my_character_display->set_cursor(1,0);
sprintf(str, "%4.2f", my_joystick->get_y());
my_character_display->print(str);
system::sleep(100);
}
@ matoran - If you have your joystick physically on Socket 3, then the issue is in code you have it set to use Socket 2. Otherwise, I will retest this today on a Due with your code.