I am trying to read data from a senor using my PI and in order to calculate the magnitude to determine acceleration but but I always get the following error when I run a test program
Time elasped: 0
Traceback (most recent call last):
File "MMA7455.py", line 47, in <module>
print("X = ", x2)
NameError: name 'x2' is not defined
This is the the code that ive been using
def calculateMag():
x = MMA7455.getValueX()
x2 = ((x + 128) % 256) -128
y = MMA7455.getValueY()
y2 = ((y - 240 + 128) % 256) -128
z = MMA7455.getValueZ()
z2 = ((z - 64 + 128) % 256) -128
magnitude = int(math.sqrt((x2*x2) + (y2*y2) + (z2*z2)))
return x2, y2, z2, magnitude
for i in range (1000):
timeGo()
calculateMag()
print("X = ", x2)
print("Y = ", y2)
print("Z = ", z2)
Ive tried passing x, y, z into the function but this didnt seem to work.Thanks for the help it would be much appreciated.