Arduino DUE dosent caclulate cos correctly

Hi there I just wanted to test if cos(). sin() works correctly.

So I just wanted get cos(0) ; displayed and I expect 1

But i recive

00Å.

this is my code

double x;
const float pi = 3.14;
float y;
void setup() {
  // put your setup code here, to run once:
  x=0.0;
 y= cos(x*pi/180);
}

void loop() {
   Serial.begin(9600);// r

  // put your main code here, to run repeatedly:
Serial.println(cos(x*pi/180));
}

I miss Serial.begin(9600); in setup()

Where is #include<math.h> ?

robtillaart: I miss Serial.begin(9600); in setup()

Well, in fact putting Serial.begin() in the loop() function is fundamentally wrong. It will be executed over and over again, for all eternity. Or until the power cuts, whatever happens first... :(

Ralf

Your code is wrong. Try this:

double x=0;
const float pi = 3.14;  
float y;

void setup()
{
    Serial.begin(9600);
    y= cos(x*pi/180);
    Serial.println(cos(x*pi/180)); 
}

void loop()
{
}

PD: now you can build an analog clock or something more complicated :art:

3D triangle

Your code is wrong. Try this:

How does having a serial.Print in Setup do anything? This produces 1.00 in either scenario.

double x=0;
double pi = 22/7;  
float y;

void setup()
{
    Serial.begin(9600);
    y= cos(x*pi/180);
}

void loop()
{
    Serial.println(cos(x*pi/180)); 
    Serial.println(y);
}