Giter VIP home page Giter VIP logo

Comments (2)

9Volts9er avatar 9Volts9er commented on August 21, 2024
  1. Configure the sensor (as basis you can use e.g. the "Cartesian" example)
  2. In the loop: Readout the sensor
  3. Map magnetic field values to PWM output (convert magnetic field values to 0-255 integer values for pwm output)
  4. Write PWM to the pins

I've not tested it, but it should work somehow like this:

#include <Tle493d.h>

#define MAX_MAG_FIELD 50
#define PWM_X_PIN 1
#define PWM_Y_PIN 2
#define PWM_Z_PIN 3

Tle493d Tle493dMagnetic3DSensor = Tle493d();

void setup() {
  Serial.begin(9600);
  while (!Serial);
  
  //If using the MS2Go-Kit: Enable following lines to switch on the sensor
  // ***
  pinMode(LED2, OUTPUT);
  digitalWrite(LED2, HIGH);
  delay(50);
  // ***
  
  Tle493dMagnetic3DSensor.begin();
  Tle493dMagnetic3DSensor.enableTemp();
}

void loop() {
  double x,y,z;
  //Read magnetic values into variables
  Tle493dMagnetic3DSensor.updateData();
  x=abs(Tle493dMagnetic3DSensor.getX());
  y=abs(Tle493dMagnetic3DSensor.getY());
  z=abs(Tle493dMagnetic3DSensor.getZ());

  //map magnetic field to pwm value
  int pwm_x = map(x,0,MAX_MAG_FIELD,0,255);
  int pwm_y = map(y,0,MAX_MAG_FIELD,0,255);
  int pwm_z = map(z,0,MAX_MAG_FIELD,0,255);

  //write pwm value to outputs
  analogWrite(PWM_X_PIN, pwm_x);
  analogWrite(PWM_Y_PIN, pwm_y);
  analogWrite(PWM_Z_PIN, pwm_z);
  
  delay(5);
}

from tle493d-3dmagnetic-sensor.

ozzcet avatar ozzcet commented on August 21, 2024

Thank You so much my friend.

from tle493d-3dmagnetic-sensor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.