18 April 2021

Final Project: Toy Car Game Controller

    This toy car controller started as several conceptual models before the final one. I was originally going to use a potentiometer, the accelerometer, and even an energy drink can. However, in the end, I ended up using a small box that had a pre-made hole on the top and ended up with the final design. The final main concept was to use foil tape and a toy car to move around in a space to touch certain places within that space, and doing so would correspond to the WASD and shift keys on the keyboard. I also needed the car to be on a lifted space so that the Circuit Playground Express would be under the car comfortably; this is because on top of the touch sensors being used for the keys, I was also utilizing the analog light sensor on the CPE that, when light touched it, would make the in-game car jump. 

Toy Car Controller Enclosure

    The mapping of the controller was simple; each mark of tape on the enclosure corresponded to a key (either WASD or shift) and when the toy car touched these points the in-game car would move in that direction, and when the car would be lifted off of the enclosure and light was let in, the in-game car would jump. When it comes to feedback, because the CPE would be underneath something and not really seen, I chose to depend on the gameplay to be the feedback to players. The signifier of the direction of the box is evident by the direction of the power connection of the CPE and the layout of the foil tape; the WASD keys correspond to the shape of the tape on the enclosure and for the boost, the player would physically move the car forward past the W mark and boost the in-game car (this was the original intent). 


How else could I have set up the enclosure to make the controls more responsive?

Controller Schematic

//CODE BY SAMANTHA BARRIZONTE 2021
//DIG3620

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

const int debounce = 0;
const int threshold = 700;                      

void setup() {
  Serial.begin(9600);
  delay(1000);
  CircuitPlayground.begin();
  Keyboard.begin();
}

void loop() {
  if(CircuitPlayground.readCap(A5) > threshold) { //move car forward
    Keyboard.press('W');
    delay(debounce); }
    else if(CircuitPlayground.readCap(A5) < threshold){
      Keyboard.release('W');
      delay(debounce);
    }
   
    if(CircuitPlayground.readCap(A6) > threshold) { //steer left
    Keyboard.press('A');
    delay(debounce); }
    else if(CircuitPlayground.readCap(A6) < threshold){
      Keyboard.release('A');
      delay(debounce);
    }

   if(CircuitPlayground.readCap(A4) > threshold) { //steer right
    Keyboard.press('D');
    delay(debounce); }
    else if(CircuitPlayground.readCap(A4) < threshold){
      Keyboard.release('D');
      delay(debounce);
    }

    if(CircuitPlayground.readCap(A1) > threshold) { //reverse
    Keyboard.press('S');
    delay(debounce); }
    else if(CircuitPlayground.readCap(A1) < threshold){
      Keyboard.release('S');
      delay(debounce);
    }

  if(CircuitPlayground.readCap(A3) > threshold) { //boost the car forward
    Keyboard.press(129);
    delay(debounce); }
    else if(CircuitPlayground.readCap(A3) < threshold) {
    Keyboard.release(129);
    delay(debounce); 
    }

  int light = analogRead(A8); //reading the light sensor, jump
  if(light > 500) {
    Keyboard.press(' ');
    delay(debounce);
  }
  else if(light < 500) {
    Keyboard.release(' ');
    delay(debounce);                                                                            
  }
  
}



No comments:

Post a Comment

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