Greeting Sir...
My project is about power factor detector.
So, I am using cos(x) function in my program
type data that I declare x = double
I use several math work like divide, time before I use cos() function
but, there a error I can't understand what its mean?
You make it hard to answer questions when you post your code as an image. Please try again, posting between code tags (the </> button) after using the autoformat tool (CTRL-T) of the IDE.
There are permanent articles at the top of this forum that describe this in more detail. You should read these first before posting here.
Your immediate problem is that you probably want cos(P), NOT cos("P").
[Notice that "P" is of type const char* as the error message says, and P is of type double as required by the cos(...) function and as also described in the error message.]
However, you are going to have other problems because:
(1) You use int arithmetic when you should have used float or double, AND
(2) You use uninitialized variables.
Perhaps you need an introductory course in programming in the C language?
@vaj4088 : sorry... that was my bad. I totally newbie here. I try to fix it @westfw : ya I know, but I was looking in https://www.arduino.cc/en/Reference/Cos , that cos("P") .
I dunno, its sound like you may use cos() function in degree by doing cos("P")
Cz I do all math work in degree perspective. I hope I can do cos() in degree. that all
@westwf : Sorry Sir, I don't understand. I had try many ways to fix, but still not work.
In early, I want the function read degrees value, and that not work,
so then, I try to make my value to radians, consider cos() read radian, but still fail.
I don't know why it happen... Is there wrong in my calculation? or my function?
@UKHelibob : I used both of that spelling degrees/degress... and its no effect of that @oqibipido : How I put it in my code? I tried but nothing happen
#include <LiquidCrystal.h>
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
int pin = 7;
double Hz = 50;
double T = (1000/Hz);
const float Pi = 3.14159;
double P;
double PF;
double duration;
LiquidCrystal lcd(12, 11, 5, 4, 10, 9);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(17, 3);
pinMode(pin, INPUT);
P = (duration*2*Pi)/T;
PF = cos(P);
}
void loop() {
lcd.setCursor(0, 0);
duration = pulseIn(pin, HIGH);
lcd.print(PF);
lcd.setCursor(0, 1);
lcd.print(P);
lcd.setCursor(7, 0);
lcd.print(T);
lcd.setCursor(7, 3);
lcd.print(duration);
no error this time, but P always zero
I already setting duration but still the same