26 November 2023

Game Controller for Super Mario Kart


 


For my controller, I did a steering wheel type controller for the game Super Mario Kart. It consists of two parts, the first part is the steering wheel which controls the left and right movement in the game. The second part is the acceleration pedal which sits on the floor. This is mainly the reason why there are wires coming out the first part of the controller into the second part. Overall, the conceptual model for this was a steering wheel and an accelerator pedal like you would find in a car. The way this controller is mapped is by the acceleration being controlled by pushing your foot down on the acceleration pedal. This causes the lowering of an LED which is read off of a photocell resistor. This will cause the kart to accelerate in game. For steering, you would steer the top part of the controller like you would a steering wheel. When these two sections are used in unison with each other, we are able to play through a game of Super Mario Kart.

Schematic:


Video:

https://youtu.be/l7gboomtgeI


Code:

#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Keyboard_da_DK.h>
#include <Keyboard_de_DE.h>
#include <Keyboard_es_ES.h>
#include <Keyboard_fr_FR.h>
#include <Keyboard_it_IT.h>
#include <Keyboard_sv_SE.h>

#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>


//Create variables
//Store motion of accelerometer in X, Y, and Z variables
float x;
float y;

//For turning on the circuits
bool slideSwitch;
int lightSensor = 1;
int val;
bool accelerate = false;

void setup() {

  //Initialize pins A2, A1, and A3.
  //Pin 1 is external light sensor
  //Pin 3 is external switch
  pinMode(A1,INPUT);
  pinMode(CPLAY_SLIDESWITCHPIN,INPUT_PULLDOWN);

  //Initialize Circuit Playground
  CircuitPlayground.begin();
  Keyboard.begin();
  Serial.begin(9600);

}

void loop() {
  if (digitalRead(CPLAY_SLIDESWITCHPIN)) {
    val = analogRead(A1);
    //Serial.println(val);
    if (val >= 180) {
      accelerate = true;
    }
    if (val < 180) {
      accelerate = false;
    }

    //If accelerate equals true, then car in SMK accelerates.
    if (accelerate == true) {
      Keyboard.press('X');
    }
    else if (accelerate == false) {
      Keyboard.release('X');
    }

   
    //If accelerometer is tilted (rolled) a certain amount on the Z axis, depending on the direction of the roll, the right and left arrow keys are given signals.
    x = CircuitPlayground.motionX();
    y = CircuitPlayground.motionY();
     
    if (y > -10 && y < -3) {
      if (x < -1) {
        //Go Left
        Keyboard.press(0xD8);
      }
      else if (x > 1) {
        //Go Right
        Keyboard.press(0xD7);
      }
      else if (x > -1 && x < 1) {
        Keyboard.release(0xD8);
        Keyboard.release(0xD7);
      }
    }

  }
 
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.