Accelerometer to calculate the result does not work

I think yes

if so, why not (not sure about order of arguments)

   horizontalAng = atan2(axis_Y, axis_X ) * 180 / PI;
   verticalAng   = atan2(axis_Z, axis_X ) * 180 / PI;

presumably these are small angles where zero is along the x-axis

thank you and is it possible to somehow stop counting below 90 degrees? I want this code to only work from 90 to 150 degrees, I don't know how to write this code :slight_smile:

void loop()
{

  result = 63.0 / 90.0 * y;<---------------how to edit 


  Wire.beginTransmission(MPU_addr); //Begins I2C transmission
  Wire.write(0x3B);                 //Start with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr, 14, true); //Request 14 Registers from MPU6050

  axis_X = Wire.read() << 8 | Wire.read(); //Obtain 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  axis_Y = Wire.read() << 8 | Wire.read(); //0x3B (ACCEL_YOUT_H) & 0x3C (ACCEL_YOUT_L)
  axis_Z = Wire.read() << 8 | Wire.read(); //0x3B (ACCEL_ZOUT_H) & 0x3C (ACCEL_ZOUT_L)

  int xAng = map(axis_X, minVal, maxVal, -90, 90);
  int yAng = map(axis_Y, minVal, maxVal, -90, 90);
  int zAng = map(axis_Z, minVal, maxVal, -90, 90);

  y = RAD_TO_DEG * (atan2(-zAng, -xAng) + PI);  //Formula to calculate x values in degree


  int pos = map(y, 0, 180, 0, 180);

i don't understand what you're counting

the can repeatedly measure acceleration, compute angles and decide whether to do something on not.

what determines when the code "counts"?

my airsoft gun has a range of 63 meters, so 63:90 (angle) = 0.7 per angle (degree) * 100 angle and then maybe * 110 120 ... that's my calculation, but more than 140 or 150 no longer flies projectile gave :slight_smile:

stromecek_555:
range of 63 meters, so 63:90 (angle)

i'm lost. how does a distance 63 become an angle?

please try using google translate

are you trying to determine a launch angle to reach a specific distance?

yes I'm trying to determine the distance angle (when 90 degrees = 63 m, about 100 degrees = 70 m) and i use google translator :slight_smile:

ok.
don't understand how you reach 63 m if 90 deg is straight up.
and don't understand how you reach 63m if the target is at the height as the launch if 90 deg is horizontal

not sure what the accelerometer is used for nor the need to calculate an angle
seems that there can be a table associating a distance and angle that can be pre-calculated

I was thinking of another idea, for example serial.print (pos (90 <---> 150)) can something be done that will only print from 90 to 150 degrees? Otherwise, thank you :slight_smile:

     if (90 < ang && ang < 150)
          Serial.println (ang);

??

exactly, thank you :slight_smile:

it doesn't work but I'm close :slight_smile: ,when I turn it below 90 degrees nothing and above 150 nothing but it shows only 1 when it is inside 90-150 degrees, what about that?

result = 63.0 / 90.0 * 90.0 < y && y < 149.0;
result = 63.0 / 90.0 * 90.0 < y && y < 149.0

this isn't a valid statement.

please explain what you're trying to do?
is 90 degrees straight up?
??

I try to count it only in 90-150 degrees, but somehow it doesn't work

gcjr:
please explain what you're trying to do?

what are you counting?

i'm guessing you want to hit a target with you gun and need to know the launch angle. so you enter the desired distance and the program determines and possible adjusts the launch angle and fires the gun.

yes :slight_smile:

you're counting "yes"? ....

do you want to make sure a valid angle is being entered? so ignore the input if (ang < 90 || 150 < ang)?

part of developing code is being able to describe what your doing ... to yourself and others.

what's the purpose of the accelerometer? are you using an accelerometer?

the last code you posted is receiving 3 parameters. do they represent some target location? and are you trying to determine angles from the coordinates?

please explain what you're trying to do? ....

I try to do the same and use an accelometr the purpose of the action accelometr is to calculate using an angle my example which is 63/90 * 90-150 degrees the target place is target, I'm trying to reach range,I'm trying to create a prototype ballistic_cpu calculates the range from the weapon using the angle :smiley:

are you trying to estimate a distance from an angle or an angle for a target distance?

i don't understand what 63/90 * 90-150 = -87 means. what is the variable?

you're not answering all my questions ... i'm, running out of patience.

are you using translate to translate my responses?
are you using translate to translate your response to english?

google translator very bad,I'm trying to estimate the distance from an angle(63/90100=70m,63/110=77m)