This coding gives the wrong result for the sin value. I get -.22. The correct result for Sin b is .60847687. even if I used the abbreviated value of b in the print out I would get closer to the correct result. Can somebody please let me know where my coding is wrong.
int d;
float b;
float n=.986301369;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("input value for variable d: ");
while (Serial.available() == 0) {
}
d = Serial.parseInt();
Serial.print("d=");
Serial.println(d);
b=(n*(d-81));
Serial.print("b=");
Serial.println(b);
Serial.print("sinb=");
Serial.println(sin(b));
}
John, 'd' gets its value input from the serial monitor. Then the value of 'b' is derived from 'n' and 'd'. I was thinking I needed to put in a data type for sin b. I used this float ((sin)(b));
I get an error input for this. 'expected ') 'before '(' token'. all the brackets seem to be there already so I don't see why i am getting this error.
Any ideas.
All sorted guys. Thanks for your help. There was 2 problems with my code. I was using degrees in the trig functions. Arduino works with radians as someone pointed out. It is a simple matter to convert to radians using PI. That is also the code in arduino for PI. A capital P and I.
The second problem was the ratio 360/365. Using a calculator this gives .986301369. I was getting zero from arduino. It was pointed out to me on this forum that the numbers in this ratio are treated as integers. The result is not an integer so the result you get is zero. Who would have thought of that for such a simple calculation.
This had an easy fix which would be totally unknown to most uses of arduino. You had to us 360.0/365.0 to get the result which some wise user on the forum pointed out. But even when you print out the result you only get 2 decimals places .99. If you select more decimal places in the anwer you can get at the most 7 places which is ok for most applications. Presumably any further calculations use the 7 places and not just .99.