How to print my calculated value to the serial monitor

I’m new to Arduino and I’m not sure how to get my calculated Angle value to update in the acceleration loop and print to the serial monitor. Would I need to use a float and serial.print?

Midterm_Pro_Commentless.ino (1.39 KB)

OP’s code

#include <Wire.h> // Must include Wire library for I2C
#include <SparkFun_MMA8452Q.h> // Includes the SFE_MMA8452Q library

MMA8452Q accel;

void setup()
{
  Serial.begin(9600);
  Serial.println("MMA8452Q Test Code!");
  
    accel.init();
  
}
void loop()
{
    if (accel.available())
  {
        accel.read();
    
        printCalculatedAccels();
        
        printOrientation();
   float Angle= atan(accel.cy/(sqrt(pow(accel.cx, 2)+pow(accel.cz, 2))))*180/3.14159265;
   
    printAngle();
    
    Serial.println(); // Print new line every time.
  }
}

void printAccels()
{
  Serial.print(accel.x, 3);
  Serial.print("\t");
  Serial.print(accel.y, 3);
  Serial.print("\t");
  Serial.print(accel.z, 3);
  Serial.print("\t");
}

void printCalculatedAccels()
{ 
  Serial.print(accel.cx, 3);
  Serial.print("\t");
  Serial.print(accel.cy, 3);
  Serial.print("\t");
  Serial.print(accel.cz, 3);
  Serial.print("\t");
}

void printAngle()
{

}
void printOrientation()
{
    byte pl = accel.readPL();
  switch (pl)
  {
  case PORTRAIT_U:
    Serial.print("Portrait Up");
    break;
  case PORTRAIT_D:
    Serial.print("Portrait Down");
    break;
  case LANDSCAPE_R:
    Serial.print("Landscape Right");
    break;
  case LANDSCAPE_L:
    Serial.print("Landscape Left");
    break;
  case LOCKOUT:
    Serial.print("Flat");
    break;
  }
}

He sure has an awful lot of Serial.print statements for someone who doesn’t know how to get something printed over Serial.

OP, if you want your printAngle function to be able to print the float variable you have named angle, then you will need to make sure that angle is either in scope for that function or passed to it.