void setup() {
///pinMode(PWMout, OUTPUT); // sets the pin as output
val = 3;
///PWMperiod = 10000; // PWM changes every 10000 uS.
Serial.begin(9600);
}
void loop() {
///time1 = micros();
delay(500);
doOneBeaconCycle;
Serial.print(val);
Serial.println();
}
void doOneBeaconCycle(){
val++;
}
I condensed my problem to the code I posted above. My function "doOneBeaconCycle" is never called. Output is always a string of "3"s. If my function was being called the output should print an increasing series of numbers. I'm assuming I've done something wrong but I don't see it.
C:\stuff\SW\Arduino\_Others\Tst\Tst.ino: In function 'void setup()':
Tst:3:5: error: 'val' was not declared in this scope
val = 3;
^~~
C:\stuff\SW\Arduino\_Others\Tst\Tst.ino: In function 'void loop()':
C:\stuff\SW\Arduino\_Others\Tst\Tst.ino:12:21: warning: statement is a reference, not call, to function 'doOneBeaconCycle' [-Waddress]
doOneBeaconCycle;
^
C:\stuff\SW\Arduino\_Others\Tst\Tst.ino:12:21: warning: statement has no effect [-Wunused-value]
Tst:13:18: error: 'val' was not declared in this scope
Serial.print(val);
^~~
C:\stuff\SW\Arduino\_Others\Tst\Tst.ino: In function 'void doOneBeaconCycle()':
Tst:19:5: error: 'val' was not declared in this scope
val++;
^~~
exit status 1
'val' was not declared in this scope
C:\stuff\SW\Arduino\_Others\Tst\Tst.ino:12:21: warning: statement is a reference, not call, to function 'doOneBeaconCycle' [-Waddress]
doOneBeaconCycle;
under the IDE File->Preferences, set Compiler Warnings: to at least More
Yes it does execute, and does exactly what you wrote. It just doesn't do what you hoped.
For reasons that may some day become apparent to you, referring to a function by using its identifier without parentheses has actual purposes.
This line of code
doOneNeaconCycle;
is not an error, it is perfectly valid code that… does nothing at all, and that is recognized at some point so no code is generated, and it's as good (or worthless) as never having typed it at all.
That's why warnings are important. The compiler has no clue… C and C++ are languages that trust that you know you want to be shooting yourself in the foot, if that's what you write.
It's the high wire act with no safety net.
Other languages take a great deal more care handholding and actually keeping you from making mistakes which are not mistakes. "Real" programmers need to be able to do stuff that C allows, we rely on compiler warnings and other tools to provide some measure of safety.