06 April 2022

Hongxu Li Progress Review

 Progress Review: Journey Controller (wearable)

Sketch:


Schematic:


For the final design, I decided to go for a wearable controller. I will use the accelerometer as the movement control. The CPE will be attached to a vest that one can wear. When the player tilts forward, backward, left, and right, the character will move in the corresponding direction. The sound sensor will be used as the whistle key in the game. When the player speaks or makes a sound, the character will whistle in the game. The last part of the system is an air pressure sensor. When the player blows the air pressure sensor, the character will make the jump move. For the enclosure, I will make a whole outfit simulating the characters style. A cape will cover the body of the player. Underneath is the vest with the CPE and the air pressure sensor. A mask will cover the players face. A silicone tube attached to the back of the mask will connect the players mouth and the air pressure sensor. My first question about the controller is would the cape necessary to enhance the game experience overall since it does not contribute to the game control. The second question, instead of using an air pressure sensor, using the shake sensor of the CPE to control the character jump would make more sense?


Video:



Code:

//Libraries

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

//bluetooth variables
BLEDis bledis;
BLEHidAdafruit blehid;

int debounce = 100;


void setup() {
  Bluefruit.begin();
  Bluefruit.setTxPower(4);

  bledis.setManufacturer("Adafruit Industries");
  bledis.setModel("Bluefruit Feather 52");
  bledis.begin();
  blehid.begin();
  startAdv();
  Serial.begin(9600);
  while (!Serial);
  CircuitPlayground.begin();
  pinMode(4, INPUT_PULLDOWN);
}

void loop() {
  if (Bluefruit.connected()) {
    //variables for aix value and sound sensor value
    float m = CircuitPlayground.mic.soundPressureLevel(10);
    float x = CircuitPlayground.motionX();
    float y = CircuitPlayground.motionY();
    float z = CircuitPlayground.motionZ();

    //checking the values
    Serial.print(m);
    Serial.print("\t");
    Serial.print(x);
    Serial.print("\t");
    Serial.print(y);
    Serial.print("\t");
    Serial.println(z);

    //sound sensor reading controls the whislte of the character ("p" key).
    if (m > 70) {
      blehid.keyPress('p');
    }

    //Section for reading the air pressure input. Controls the character jump. ("Space" key)

    
    //accelerometer controlls the character movement.("WASD" keys)
    if (x > -2 && x < 2 && y > -10 && y < -8 && z > -2 && z < 2 && m < 70) {
      blehid.keyRelease();
    }
    if (x > -2 && x < 2 && y > -10 && y < -8 && z < -2) {
      blehid.keyPress('w');
    }
    if (x > -2 && x < 2 && y > -10 && y < -8 && z > 2) {
      blehid.keyPress('s');
    }
    if (x < -2 && y > -10 && y < -8 && z > -2 && z < 2) {
      blehid.keyPress('d');
    }
    if (x > 2 && y > -10 && y < -8 && z > -2 && z < 2) {
      blehid.keyPress('a');
    }
    delay(debounce);
  }
}

//bluetooth connection.
void startAdv(void)
{
  // Advertising packet
  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  Bluefruit.Advertising.addTxPower();
  Bluefruit.Advertising.addAppearance(BLE_APPEARANCE_HID_KEYBOARD);

  // Include BLE HID service
  Bluefruit.Advertising.addService(blehid);

  // There is enough room for the dev name in the advertising packet
  Bluefruit.Advertising.addName();

  /* Start Advertising
     - Enable auto advertising if disconnected
     - Interval:  fast mode = 20 ms, slow mode = 152.5 ms
     - Timeout for fast mode is 30 seconds
     - Start(timeout) with timeout = 0 will advertise forever (until connected)

     For recommended advertising interval
     https://developer.apple.com/library/content/qa/qa1931/_index.html
  */
  Bluefruit.Advertising.restartOnDisconnect(true);
  Bluefruit.Advertising.setInterval(32, 244);    // in unit of 0.625 ms
  Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
  Bluefruit.Advertising.start(0);                // 0 = Don't stop advertising after n seconds
}

No comments:

Post a Comment

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