Help with code

Hello you guys. I made a project from here: http://www.riyas.org/2015/06/a-simple-uhf-beacon-for-fox-hunt-arduino-rf-433MHZ.html.

But when I compile in Arduino I have this errors:

C:\Users\USER\Documents\Arduino\sketch_feb09b\sketch_feb09b.ino: In function ‘void loop()’:

C:\Users\USER\Documents\Arduino\sketch_feb09b\sketch_feb09b.ino:122:39: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

sendmsg(“VVV VVV VVV TESTING TESTING”);

^

Could anyone help me?, thanks

This is the code:

// A simple uhf beacon using 433 mhz rf module
// credits to the author of the morse code generator
// more details on http://blog.riyas.org

struct t_mtab { char c, pat; } ;

struct t_mtab morsetab = {
{’+’, 42},
{’-’, 97},
{’=’, 49},
{’.’, 106},
{’,’, 115},
{’?’, 76},
{’/’, 41},
{‘A’, 6},
{‘B’, 17},
{‘C’, 21},
{‘D’, 9},
{‘E’, 2},
{‘F’, 20},
{‘G’, 11},
{‘H’, 16},
{‘I’, 4},
{‘J’, 30},
{‘K’, 13},
{‘L’, 18},
{‘M’, 7},
{‘N’, 5},
{‘O’, 15},
{‘P’, 22},
{‘Q’, 27},
{‘R’, 10},
{‘S’, 8},
{‘T’, 3},
{‘U’, 12},
{‘V’, 24},
{‘W’, 14},
{‘X’, 25},
{‘Y’, 29},
{‘Z’, 19},
{‘1’, 62},
{‘2’, 60},
{‘3’, 56},
{‘4’, 48},
{‘5’, 32},
{‘6’, 33},
{‘7’, 35},
{‘8’, 39},
{‘9’, 47},
{‘0’, 63}
} ;

#define N_MORSE (sizeof(morsetab)/sizeof(morsetab[0]))
#define SPEED (13)
#define txpin (13)
#define DOTLEN (1200/SPEED)
#define DASHLEN (3*(1200/SPEED))

void
dash()
{
digitalWrite(txpin, HIGH);
delay(DASHLEN);
digitalWrite(txpin, LOW);
delay(DOTLEN);
}

void
dit()
{
digitalWrite(txpin, HIGH);
delay(DOTLEN);
digitalWrite(txpin, LOW);
delay(DOTLEN);
}

void
send(char c)
{
int i ;
if (c == ’ ') {
delay(7DOTLEN) ;
return ;
}
for (i=0; i<N_MORSE; i++) {
if (morsetab
.c == c) {*
_ unsigned char p = morsetab*.pat ;_
_
while (p != 1) {_
_
if (p & 1)_
_
dash() ;_
_
else*_
* dit() ;*
* p = p / 2 ;*
* }*
_ delay(2DOTLEN) ;_
_
}_
_
Serial.print("?") ;_
_
}_
_
}_
void
sendmsg(char *str)
_
{_
_ while (str)
send(str++) ;_
_
}
_
void
setup()
_
{ _
_
pinMode(txpin, OUTPUT); _
_
}_
void
loop()
_
{_
sendmsg(“VVV VVV VVV TESTING TESTING”);
delay(1500); //delay can be increased to save battery
_
}*_

Welcome to the forum (= Maybe I can help.

sendmsg expects a char variable but you give it a string.

void sendmsg(char *str)
{
  while (*str)
    send(*str++) ;
}

And also you can't increment through a string like that (I think that is what you are trying to do here). Maybe this is helpful: https://www.arduino.cc/en/Reference/StringCharAt

Thanks a lot, for your rapid response and sorry about my english. I dont understand a lot of arduino code. I want to know how can I solve this issue, because this is not my code, I get it from here: http://www.riyas.org/2015/06/a-simple-uhf-beacon-for-fox-hunt-arduino-rf-433MHZ.html

Thanks a lot for your help MarkGoingToSpace

The message is just a warning, not a problem. The program should work.

If your program didn’t work, there is another problem somewhere else.

Please use code tags (</> button) to post code.

Hey! I'm new to the forums too but i'll try help you with formating

Put the code inside the:

[*code] YOUR CODE [/code] --------> delete the *

and it will look like this:

    YOUR CODE

ok so i have fixed the code. I have gotten rid of the pointers, changed the parameter type of sendmsg to string, changed the second struct to an array and indexed it accordingly. Here is the code:

struct t_mtab { char c, pat; } ;

t_mtab morsetab[] = {
 {'+', 42},   
 {'-', 97},
 {'=', 49},
 {'.', 106},
 {',', 115},
 {'?', 76},
 {'/', 41},
 {'A', 6},
 {'B', 17},
 {'C', 21},
 {'D', 9},
 {'E', 2},
 {'F', 20},
 {'G', 11},
 {'H', 16},
 {'I', 4},
 {'J', 30},
 {'K', 13},
 {'L', 18},
 {'M', 7},
 {'N', 5},
 {'O', 15},
 {'P', 22},
 {'Q', 27},
 {'R', 10},
 {'S', 8},
 {'T', 3},
 {'U', 12},
 {'V', 24},
 {'W', 14},
 {'X', 25},
 {'Y', 29},
 {'Z', 19},
 {'1', 62},
 {'2', 60},
 {'3', 56},
 {'4', 48},
 {'5', 32},
 {'6', 33},
 {'7', 35},
 {'8', 39},
 {'9', 47},
 {'0', 63}
} ;

#define N_MORSE  (sizeof(morsetab)/sizeof(morsetab[0]))
#define SPEED  (13) 
#define txpin    (13)
#define DOTLEN  (1200/SPEED)
#define DASHLEN  (3*(1200/SPEED))


void
dash()
{
  digitalWrite(txpin, HIGH);
  delay(DASHLEN);
  digitalWrite(txpin, LOW);
  delay(DOTLEN);
}

void
dit()
{
  digitalWrite(txpin, HIGH);
  delay(DOTLEN);
  digitalWrite(txpin, LOW);
  delay(DOTLEN);
}


void
send(char c)
{
  int i;
  if (c == ' ') {
    delay(7*DOTLEN) ;
    return ;
  }
  for (i=0; i<N_MORSE; i++) {
    if (morsetab[i].c == c) {
      unsigned char p = morsetab[i].pat ;

      while (p != 1) {
          if (p & 1)
            dash();
          else
            dit() ;
          p = p / 2 ;
      }
      delay(2*DOTLEN);
 }
  Serial.print("?") ;
}
}


void
sendmsg(String str)
{
  int i = 0;
  while (str)
  {
    send(str.charAt(i)) ;
    i++;
  }
}


void
setup()
{                
  pinMode(txpin, OUTPUT);     
}

void 
loop() 
{
 sendmsg("VVV VVV VVV TESTING TESTING"); 
 delay(1500); //delay can be increased to save battery
}

I am not sure if it works properly since I can’t morse tho… xD

It is a bad idea, and completely unnecessary, to use a String.

Thanks a lot!!!! I will try it

void
dash()
{

Toss AdaFruit's playbook in the trash. The return type goes on the same line as the function.

MarkGoingToSpace:
sendmsg expects a char variable but you give it a string.

No, that is not the problem. C strings re arrays of char, which are passed around as pointers to char.

The problem is that string constants are treated as if they had the ‘const’ modifier in C++. The function does not declare its parameter as const. This means that the function is not guaranteeing that it will not modify the string. Of course - the function does not actually do this, but the issue is that the function declaration does not state it.

But, the code ca still be compiled and will work just fine. This is a warning only.

Thanks a lot you guys!!!!!!!