Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Peter Ma
Published © Apache-2.0

3D Magnetic Sensor Space Shooter

Unity based Space Shooter based on Infineon 3D Magnetic Sensor.

BeginnerFull instructions provided4 hours2,588

Things used in this project

Hardware components

3D Magnetic Sensor 2Go
Infineon 3D Magnetic Sensor 2Go
×1

Software apps and online services

Unity
Unity
Arduino IDE
Arduino IDE

Story

Read more

Schematics

3dgo schematic

3dgo magnetic sensor schematic

Code

Tle493d Arduino code

Arduino
This outputs the raw sensor data of x,y,z
#include <Tle493d_w2b6.h>

Tle493d_w2b6 Tle493dMagnetic3DSensor = Tle493d_w2b6();

//for firing
float x = 0;
float y = 0;
float z = 0;
float norm = 0;
bool fire = false;
int frame = 0;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  pinMode(14, OUTPUT);

  Tle493dMagnetic3DSensor.begin();
  Tle493dMagnetic3DSensor.begin();
  Tle493dMagnetic3DSensor.setWakeUpThreshold(1,-1,1,-1,1,-1);
  Tle493dMagnetic3DSensor.disableTemp();
  x = Tle493dMagnetic3DSensor.getX();
  y = Tle493dMagnetic3DSensor.getY();
  z = Tle493dMagnetic3DSensor.getZ();
  norm = Tle493dMagnetic3DSensor.getNorm();
}


void loop() {
  Tle493dMagnetic3DSensor.updateData();
  
  Serial.print(Tle493dMagnetic3DSensor.getX());
  Serial.print(" ; ");
  Serial.print(Tle493dMagnetic3DSensor.getY());
  Serial.print(" ; ");
  Serial.print(Tle493dMagnetic3DSensor.getZ());
  Serial.print(" ; ");
  Serial.print(Tle493dMagnetic3DSensor.getNorm());
  Serial.print(" ; ");
  Serial.println(Tle493dMagnetic3DSensor.getAzimuth());

  //It doubles when press down, and halves when releases
  if((abs(Tle493dMagnetic3DSensor.getNorm()) > abs(norm*1.5))){
    fire = true;
  }
  else if
  ((abs(Tle493dMagnetic3DSensor.getNorm()) < abs(norm/1.5)))
  {
    fire = false;
  }
  x = Tle493dMagnetic3DSensor.getX();
  y = Tle493dMagnetic3DSensor.getY();
  z = Tle493dMagnetic3DSensor.getZ();
  norm = Tle493dMagnetic3DSensor.getNorm();
  if(fire)
  {
    digitalWrite(14, HIGH);
  }
  else
  {
    digitalWrite(14, LOW);
  }
  delay(10);
}

Space Shooter

Space Shooter full source code

Credits

Peter Ma

Peter Ma

49 projects • 394 followers
Prototype Hacker, Hackathon Goer, World Traveler, Ecological balancer, integrationist, technologist, futurist.
Thanks to Unity Tutorial.

Comments