Map real time accelerometer values to 3D objects

edited November 2016 in Arduino

Hi, I am trying to implement a situation where a 3D object in the IDE orients itself according to the values it gets from an accelerometer outside the IDE. The values are read using serial port. How do I use the rotate function to achieve this?

Thanks in advance!

Answers

  • Answer ✓

    the core idea is to use map() to match the range of the incoming data to the range of the angle you need as shown here for mouseX:

    void setup() { 
      size(640, 360, P3D);
    } 
    
    void draw() 
    {     
      background(0, 0, 26);
      lights();
    
      translate(width/2, height/2);
    
      pushMatrix();
      fill(112);
      rotateY(map(mouseX, 0, width, 0, TWO_PI));
      box(200);
      popMatrix();
    } 
    
Sign In or Register to comment.