Go Down

Topic: problems with IF formula RESOLVED (Read 130 times) previous topic - next topic

jcd420

Aug 21, 2017, 11:27 pm Last Edit: Aug 21, 2017, 11:51 pm by jcd420
i get this error:

LDR_Simple.ino:18: error: 'LDRValue' cannot be used as a function

if (LDRValue()==1)Serial.println ("On");

             ^

exit status 1
'LDRValue' cannot be used as a function


my code:

int LDRPWR = 16;
int LDRPin = 5; // select the input pin for LDR
int LDRValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(LDRPWR, OUTPUT);
Serial.begin(9600); //sets serial port for communication
   digitalWrite(LDRPWR, LOW);
}
void loop() {
//LDRValue = analogRead(LDRPin); // read the value from the sensor
 digitalWrite(LDRPWR, HIGH);   // sets the LDR on
 delay(1000);                  // waits for a second
LDRValue = digitalRead(LDRPin); // read the value from the sensor
 digitalWrite(LDRPWR, LOW);    // sets the LDR off
//  delay(1000);                  // waits for a second

Serial.println(LDRValue); //prints the values coming from the sensor on the screen
if (LDRValue()==1)Serial.println ("On");
}

spycatcher2k

Quote
if (LDRValue()==1)Serial.println ("On");
Code: [Select]
if (LDRValue==1)Serial.println ("On");
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

PieterP

#2
Aug 21, 2017, 11:31 pm Last Edit: Aug 21, 2017, 11:32 pm by PieterP
By adding the parentheses to LDRValue, you are trying to evaluate it as a function. This is of course not possible, because it's a variable, not a function. Just delete the parentheses, and it should work.

Please remember to use [code][code] tags when posting code or error messages.

Pieter

MarkT

Its possible to evaluate a variable as a function of course, but only if its of function type - an int
typed variable cannot contain function references, only integers.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

jcd420


Go Up