Which way am I facing

I am new on arduino and taking a mechatronics class in which we have to debug this code but we do not know where to start.. Please Help

You just bought a brand new accelerometer and want to use it to determine which way your device is oriented. So you know that the rst thing you need is a unit vector describing your gravity vector. So you made this program, but it doesn't work. Fix it! Remember the square root sum of the squares on a unit vector should equal 1.0! int AccelXValue = 0; int AccelYValue = 0; int AccelZValue = 0;

oat[3] Vector = [0.0, 0.0, 0.0]; function getAccelXValue return oat acceldevice.xReading; . for testing you can simply return the value 1.1 here end function function getAccelYValue return oat acceldevice.yReading; . for testing you can simply return the value 2.2 here end function function getAccelZValue return oat acceldevice.zReading; . for testing you can simply return the value 3.3 here end function loop . Get values from Accelerometer AccelXValue = getAccelXValue(); AccelYValue = getAccelYValue(); AccelZValue = getAccelZValue(); . Determine Vector int magnitude = AccelXV alue2 + AccelY V alue2 + AccelZV alue2; Vector = [ AccelXV alue=magnitude, AccelY V alue=magnitude, AccelZV alue=magnitude ]; println(Vector); . for testing you'll have to use multiple prints end loop

That doesn't look a) remotely like C Or b) complete.

Please use code tags.

You want us to do your homework for you? :astonished:

Rule 1: When you post your updated (!) code, please use the # button to put code tags around it. That way, your code will look more like this:

**  Isn't this better?

oke what is the totalvector length?
the normal length is 1
so what are the directions
total length is sqrt(xx+yy+z*z)
direcdtionx=1.1/total length
in your program find this squares and sqrt

AntonioGarza: you made this program, but it doesn't work. Fix it!

Understand what it is supposed to do. Discover what it actually does. Think of possible reasons for the difference between required and actual behaviour. Think of a way to test each of the possible reasons, starting with the ones that seem most likely. When dealing with sensor input, it is critical to understand the raw data you're actually getting from the sensor.