When I verify the code in the sketch i downloaded, it gives the following error:
D:\Users\dwmit\Documents\Arduino\libraries\Arduino_Repeater_Controller-master\Arduino_cos_repeater\Arduino_cos_repeater.ino: In function 'void txAutoId(Radio&)':
D:\Users\dwmit\Documents\Arduino\libraries\Arduino_Repeater_Controller-master\Arduino_cos_repeater\Arduino_cos_repeater.ino:281:36: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
morseCode(radio.micPin,CALLSIGN);
^
It occurs at another point in the sketch, also.
Here is the sketch code causing the issue.:
//broadcast ID if applicable
void txAutoId(Radio &radio)
{
//If we're only suppsoed to ID after TX
//and we didn't TX
if (onlyIdAfterTx && !radio.needsId)
{
//keep resetting the last ID time to now
radio.lastIdTime = millis();
}
if (isEnabled(radio.txAllowed) && isEnabled(radio.autoId) && (millis() - radio.lastIdTime) > idTimeout)
{
#ifdef ENABLE_DEBUG
Serial.print("Sending autoID on ");
Serial.println(radio.nametag);
#endif
boolean tx = digitalRead(radio.pttPin);
digitalWrite(radio.pttPin, HIGH);
delay(500);
morseCode(radio.micPin, CALLSIGN);
I am thinking something has changed in the syntax rules since the sketch was written 5 years ago.
Can someone please explain to a noob?
You didn't include the complete program. But, I'm gonna guess that one of the parameters to the morseCode() function is a 'char *' or, equivalently, a 'char []'. Trouble is you're passing a constant value ('CALLSIGN' I'm guessing). If morseCode() doesn't need to modify the string, declare the parameter as 'const char *'.
And next time, post the complete program. If you truly knew where the trouble was, you wouldn't need assistance.
If I have found the correct sketch, the problem is that the morseCode function expects a char* for the 2nd argument, you are giving it a string constant, which is a const char*. Changing the function header to take a const char* will fix the warning, as long as the function does not alter the char array that is pointed to.
//send morse code message by applying tone to codePin
void morseCode(int codePin, char* message)
It does need to be fixed in the source, because some non-AVR based boards, such as the ESP8266, will generate an error instead of a warning.
gfvalvo:
You didn't include the complete program. But, I'm gonna guess that one of the parameters to the morseCode() function is a 'char *' or, equivalently, a 'char []'. Trouble is you're passing a constant value ('CALLSIGN' I'm guessing). If morseCode() doesn't need to modify the string, declare the parameter as 'const char *'.
And next time, post the complete program. If you truly knew where the trouble was, you wouldn't need assistance.
Okay. I will post the entire program next time. I just thought that would take a considerable amount of resources on this site and maybe someone could help me given the section where the error was indicated. Only programming experience I have had is batch file programming and some MIcrorosft BASIC under DOS/WINDOWS. I am here to learn... if I wasn't, I wouldn't be asking questions. But, thank you very much for your helpful answer.
Turn on warnings in the preferences tab and you will get a few warnings with every sketch. Then endeavour to fix them. Even though warnings compile and work as intended, correcting them in your code will make you a better programmer. Also, you never know when a future release of the compiler will make your warnings into errors.