I use the arduinodroid app. But there is only one port for the joystick. So i can't put y axis and x axis. And when i put the same port in the code. It doesn't work.
Hi @jayblune ,
welcome to the Arduino forum!
As far as I understand your issue you are using
- hardware from the Keyestudio kit KS0398, especially the Joystick module and
- Arduinodroid app to write sketches
Correct?
From the internet I can see that the Keyestudio uses RJ11 cables to connect the Joystick module with the control board (the controller board).
See here
https://docs.keyestudio.com/projects/KS0398/en/latest/KS0398.html#project-14-joystick
The Joystick uses three input pins:
- D2 (digital for the Joystick button)
- A6 and A7 to read x and y axis of the Joystick
If you follow the link above you'll find code written in the Mixly1.0 software based on Google's Blockly framework.
As you can see there the x axis is connected to A6 and the y axis to A7.
So in your software you have to analogread from A6 for x and A7 for the y axis ...
If you still struggle it is a good idea to post your sketch here! If you do so please use code tags

Good luck!
ec2021
BTW: You might have a look at
How to get the best out of this forum
It's really worth it! ![]()
But i cant plug one to the a6 and one to the a7
Not sure if I understand you right ...
But i cant plug one to the 16 and one to the a7
What do you mean with 16?
Oh i meant a6
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
#define JOYSTICK_X A0
#define JOYSTICK_Y A1
#define BUZZER_PIN 3
#define SNAKE_MAX_LENGTH 20
int snake_x[SNAKE_MAX_LENGTH];
int snake_y[SNAKE_MAX_LENGTH];
int snake_length = 2;
int score = 0;
int snake_dir = 0; // 0 = right, 1 = up, 2 = left, 3 = down
int food_x;
int food_y;
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
pinMode(BUZZER_PIN, OUTPUT);
//randomSeed(analogRead(0));
food_x = random(0, display.width() / 8);
food_y = random(0, display.height() / 8);
snake_x[0] = 0;
snake_y[0] = 0;
snake_x[1] = 1;
snake_y[1] = 0;
drawSnake();
drawFood();
}
void loop() {
delay(80);
//Joystick Control
int xVal = analogRead(JOYSTICK_X);
int yVal = analogRead(JOYSTICK_Y);
if (xVal > 850 && snake_dir != 2) { // Right
snake_dir = 0;
} else if (xVal < 150 && snake_dir != 0) { // Left
snake_dir = 2;
} else if (yVal > 850 && snake_dir != 1) { // Down
snake_dir = 3;
} else if (yVal < 150 && snake_dir != 3) { // UP
snake_dir = 1;
}
for (int i = snake_length - 1; i > 0; i--) {
snake_x[i] = snake_x[i - 1];
snake_y[i] = snake_y[i - 1];
}
switch (snake_dir) {
case 0:
snake_x[0]++;
break;
case 1:
snake_y[0]--;
break;
case 2:
snake_x[0]--;
break;
case 3:
snake_y[0]++;
break;
}
if (snake_x[0] < 0) {
snake_x[0] = display.width() / 8 - 1;
} else if (snake_x[0] >= display.width() / 8) {
snake_x[0] = 0;
}
if (snake_y[0] < 0) {
snake_y[0] = display.height() / 8 - 1;
} else if (snake_y[0] >= display.height() / 8) {
snake_y[0] = 0;
}
//Eat Apple
if (snake_x[0] == food_x && snake_y[0] == food_y) {
if (snake_length < SNAKE_MAX_LENGTH) {
snake_length++;
}
score = score + 1;
digitalWrite(BUZZER_PIN, HIGH);
delay(10);
digitalWrite(BUZZER_PIN, LOW);
food_x = random(0, display.width() / 8);
food_y = random(0, display.height() / 8);
}
for (int i = 1; i < snake_length; i++) {
if (snake_x[0] == snake_x[i] && snake_y[0] == snake_y[i]) {
gameOver();
Reset();
}
}
display.clearDisplay();
drawSnake();
drawFood();
display.display();
}
void drawSnake() {
for (int i = 0; i < snake_length; i++) {
display.fillRect(snake_x[i] * 8, snake_y[i] * 8, 8, 8, WHITE);
}
}
void drawFood() {
display.fillRect(food_x * 8, food_y * 8, 8, 8, WHITE);
}
void gameOver() {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(5, 20);
display.println("Game Over!");
display.setCursor(15, 40);
display.print("Score: ");
display.println(score);
display.display();
delay(3000);
}
void Reset() {
score = 0;
food_x = random(0, display.width() / 8);
food_y = random(0, display.height() / 8);
snake_length = 2;
snake_dir = 0; // 0 = right, 1 = up, 2 = left, 3 = down
snake_x[0] = 0;
snake_y[0] = 0;
snake_x[1] = 1;
snake_y[1] = 0;
}
Ok.
Each of the pins A6 and A7 reads only one axis not two.
Its one rj11 port so i cant put multiple
What that means
The RJ11 port on the control board should already connect
- the three lines to D2, A6 and A7
- and one to GND
The keyestudio board has a special layout, not identical to usual Arduino boards!
Oh i saw that there is a port with a6 and a7
So I'll test it
But you have to change some parameters in your sketch as well!
It won't work with the pins you are using.
This is in your sketch
#define JOYSTICK_X A0
#define JOYSTICK_Y A1
It should read
#define JOYSTICK_X A6
#define JOYSTICK_Y A7
I have not checked the rest of your sketch, there might be more but give it a try ...
Good luck!
ec2021
Thats what i did and it now works fine
That's great!
Lessons learned: "Read the documentation carefully! ..." ![]()
Thank you
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.



