Go Down

Topic: Arduino DUE dosent caclulate cos correctly (Read 63 times) previous topic - next topic

DUEDUE

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
Code: [Select]
00Å.
this is my code

Code: [Select]

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));
}

robtillaart


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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

KeithRB


PCWorxLA

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

TFTLCDCyg

#4
Today at 01:17 am Last Edit: Today at 01:43 am by TFTLCDCyg
Your code is wrong. Try this:

Code: [Select]

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  :smiley-draw:

3D triangle

Go Up