18 April 2021

Pepsi Controller: The (not) official drink/controller of Pepsiman!

 The idea behind this controller is to take a Pepsi can and make it work for the game Pepsiman to really bring the soda theme full circle. How it works is that the CPE, which is inside the can, is basically being used for Gyro controls, recognizing where the can is being tilted and moving either left or right accordingly as well as jumping if flicked up or sliding if pulled back. The controls are intuitive I think, as if you were to go in without any idea of the controls, you'd naturally just start moving it left and right and realize how it works. As the game is fast paced and requires the player to make inputs quickly, the feedback is quick and snappy as they're constantly moving around. I think the controller mostly holds up to this, although a flaw might be where the person playing doesn't reset the controller back to a neutral position, which leads to the game not getting some inputs as you drift farther away from where the controller would register certain positions. There is also the use of the sound sensors as you can see in the code, which would have been used to activate the boost in the game Sodaman, requiring the player to scream at it. However, the game stopped working due to an update, which required me to use a different pepsi based runner game to demonstrate instead. Pepsiman doesn’t have a boost function however, so the feature isn’t shown despite it being supported. In all honesty that might be for the best, as it wasn’t a particularly intuitive design and might have led to people activating it accidentally at times that would make them lose a life.

 

         



 
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
#include <math.h>
#include <Wire.h>
#include <SPI.h>
#include <Keyboard.h>


//Code by Christopher Flango for the Pepsi Controller!

#define SAMPLE   10  // Sample window for average level

const int debounce = 100;
const int threshold = 500;

float mapf(float x, float in_min, float in_max, float out_min, float out_max);

void setup() {
 // put your setup code here, to run once:
 

  Serial.begin(9600);
  //while(!Serial);
  CircuitPlayground.begin();
}

void loop() {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
  // put your main code here, to run repeatedly:

  //read accelerometer x and y
  float y = CircuitPlayground.motionX();
  float x = CircuitPlayground.motionY();
  float rad = atan2(y,x);

  float m = 0; //peak level

  //read microphone and get loadest level over sample window
  m = CircuitPlayground.mic.soundPressureLevel(SAMPLE);

  //Serial.print("\t S value: ");
 // Serial.print(m);
  //Serial.print("\t X value: ");
  //Serial.print(x);
  //Serial.print("\t Y value: ");
  //Serial.println(y);

  //controls for boost
  if(m > 90)
  {
  Keyboard.write(129);     
  delay(debounce);
  }

  //controls for gyro
  if(x >= 4 && y <= 5)
  {
  Keyboard.press(216);
  delay(debounce);
  }
  else
  {
    Keyboard.release(216);
  }

  if(x <= -4 && y <= 5)
  {
  Keyboard.press(215);
  delay(debounce);
  }
  else
  {
    Keyboard.release(215);
  }

  if(y >= 5 && x <= 4)
  {
  Keyboard.press('Z');
  delay(debounce);
  }
  else
  {
    Keyboard.release('Z');
  }

  if(y < -5 && x < 2)
  {
  Keyboard.press('S');
  delay(debounce);
  }
  else
  {
    Keyboard.release('S');
  }
 
  delay(20);
}
 


Question: Do you think that the scream feature should have been included in the first place, or was there a better way to go about implementing it?


No comments:

Post a Comment

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