Close

Link to keyboard and skateboard stabilisation

A project log for Subway Surfer game controller

Immersive Subway Surfer controller: Stand on a real hoverboard to control the game with realistic motion!

ccinourCéciNour 12/10/2024 at 10:350 Comments

26/11/2024

As the keyboard code wasn't working because we couldn't connect the board to the computer. we found out that we could use python code to connect it. 

import serial 
import pyautogui

# Connect to the Arduino Serial port 
arduino = serial.Serial('COM13', 9600)  

# Key mappings 
 key_mappings = { 
    "RIGHT": "right",  # Right arrow key      
    "LEFT": "left",    # Left arrow key
    "UP": "up",        # Up arrow key
    "DOWN": "down"     # Down arrow key
}


print("Listening for commands...") 

while True:     
    if arduino.in_waiting > 0:     
        command = arduino.readline().decode('utf-8').strip()  
    if command in key_mappings: 
        pyautogui.press(key_mappings[command])  # Simulate key press

We have tried to make this code work by installing the serial library. 

We couldn't make the code work because we couldn't find a way to install the library pyautogui. We were using Anaconda for python, however Anaconda didn't have this library on its base of information. 

We searched it on Internet. However most of the website where only proposing solutions to connect a USB keyboard to Arduino, NOT the keyboard of the computer. 

However, we found out that the precedent keyboard code wasn't working because of the type of the Arduino board (it was a uno). So we change the Arduino uno by a Arduino leonardo that contained the correct keyboard library. 

Along the way, we found another problem. It seems that our computer wasn't detecting the Arduino leonardo. We did many research and found out that we needed to install the library. After that, the code was working. 

The stabilisation of the skateboard

So the skateboard needed to be stable enough to support the weight of a human, and be able to stand on it without moving (so it doesn't press down the keyboard when it is not needed) 

We tried by just putting and pile up cardboard under the board. However even though it was stable to stand, it was difficult to tilt it. 

Discussions