DFRobot
Published © LGPL

DIY Posture-controlled Among Us Dagger with 9-axis sensor

Use this 9-axis sensor to make a Posture-controlled Dagger to play Imposter in Among Us

IntermediateFull instructions provided5 hours265
DIY Posture-controlled Among Us Dagger with 9-axis sensor

Things used in this project

Hardware components

BNO055 9-Axis Sensor
×1
DFRobot Dreamer Nano V4.1
×1
Gravity:Digital Push Button (Yellow)
DFRobot Gravity:Digital Push Button (Yellow)
×1

Story

Read more

Custom parts and enclosures

3D Modeling and Printing

Code

9 axis Sensor.ino

Arduino
#include "Keyboard.h"
#include "DFRobot_BNO055.h"
#include "Wire.h"

typedef DFRobot_BNO055_IIC    BNO;    // ******** use abbreviations instead of full names ********

BNO   bno(&Wire, 0x28);    // input TwoWire interface and IIC address
BNO::sEulAnalog_t   sEul;
BNO::sAxisAnalog_t   sAxis;
BNO::eAxis_t eAxis_t1;

void printLastOperateStatus(BNO::eStatus_t eStatus)
{
  switch(eStatus) {
  case BNO::eStatusOK:    Serial.println("everything ok"); break;
  case BNO::eStatusErr:   Serial.println("unknow error"); break;
  case BNO::eStatusErrDeviceNotDetect:    Serial.println("device not detected"); break;
  case BNO::eStatusErrDeviceReadyTimeOut: Serial.println("device ready time out"); break;
  case BNO::eStatusErrDeviceStatus:       Serial.println("device internal status error"); break;
  default: Serial.println("unknow status"); break;
  }
}

void setup()
{
  Serial.begin(115200);
  pinMode(4, INPUT_PULLUP);
  //pinMode(LED_BUILTIN, OUTPUT);
  Keyboard.begin();
  bno.reset();
  while(bno.begin() != BNO::eStatusOK) {
    Serial.println("bno begin faild");
    printLastOperateStatus(bno.lastOperateStatus);
    delay(2000);
  }
  Serial.println("bno begin success");
}

void loop()
{
  while(digitalRead(4)){

  sEul = bno.getEul();
//  Serial.print("pitch:");
//  Serial.print(sEul.pitch, 3);
//  Serial.print(" ");
//  Serial.print("roll:");
//  Serial.print(sEul.roll, 3);
//  Serial.print(" ");
//  Serial.print("yaw:");
//  Serial.print(sEul.head, 3);
//  Serial.println(" ");

  sAxis = bno.getAxis(BNO::eAxisAcc);
//  Serial.print("x:");
//  Serial.print(sAxis.x, 3);
//  Serial.print(" ");
//  Serial.print("y:");
//  Serial.print(sAxis.y, 3);
//  Serial.print(" ");
//  Serial.print("z:");
//  Serial.print(sAxis.z, 3);
//  Serial.println(" ");
  delay(100);

  if(sEul.pitch<-120){
    //
   Keyboard.press('D');
   delay(200);
   Keyboard.releaseAll();
  }
  else if(sEul.pitch>-60){
    //
    Keyboard.press('A');
    delay(200);
    Keyboard.releaseAll();
  }
  
  if(sEul.roll>10){
    //
    Keyboard.press('W');
    delay(200);
    Keyboard.releaseAll();
  }
  else if(sEul.roll<-10){
    //
    Keyboard.press('S');
    delay(200);
    Keyboard.releaseAll();
  }
  
  if((sAxis.x>500)&&(sAxis.y>500)){
    //Q
    Keyboard.press('Q');
    delay(200);
    Keyboard.releaseAll();
  }
  else if((sAxis.x>1000)&&(sAxis.y<200)){
    //
    delay(200);
  }
  else if((sAxis.y>1000)&&(sAxis.z<1000)){
    //
    delay(200);
  }
  else if((sAxis.y>1000)&&(sAxis.z<-1000)){
    //
    delay(200);
  }
  
  }
}

Credits

DFRobot
66 projects • 153 followers
Empowering Creation for Future Innovators
Contact

Comments

Please log in or sign up to comment.