Hey, im kinda new to all of this so sorry if i made a stupid mistake in advance.
I am currently playing around with 433Mhz wireless modules and am using the "RadioHead" Library. I want to send a message from one arduino to another which i have already done successfully previously. However, i cant figure out how to send a message that i dont hardcode into the code. I have connected a potentiometer to my arduino with the transmitter and am trying to send a value (0-255) to the receiver based on the potentiometer. But i cant figure out how to do that. Here is the problematic code:
my problem is at const char *msg = new_val;. If i do it like that, i receive random letters.
If i just do const char *msg = "test;", it works.
I tried to solve this by doing const char *msg = String(new_val);
but then i just get the
cannot convert 'String' to 'const char*' in initialization
Error.
Actually, i now have a different problem that i didnt notice right away. The code on the receiver end relies on knowing how many letters the message has. previously i just always used 4 letters, but i cant really do that with a number. Is there any way thta i can just extend the number so that it always has 4 digits? like turning 200 into 0200
What i wanted was to measure the state of the potentiometer and then convert that onto a scale that i could use on the receiver to directly put into an analogWrite. I wasnt sure what my program would do if i used a float instead of an integer. thats why i used the map instead of new_var = var/4
You don't use a float in there, and neither does analogWrite.
Either way, the "map" will almost certainly not give you the results you expect (unless you expect slightly odd results).
Ok anyways. i now have another and hopefully my last issue for now. In my receiver code i want to use the message as input for analogWrite. But when i try to convert it to an integer to use it i get "cannot convert 'String' to 'int' for argument '2' to 'void analogWrite(uint8_t, int)'"
here is the part of the code i use for that:
it is not common practice in these cases (and especially with arduino).
qualcomm made us a take a course on using these types of functions to protect against string buffer overflows intentionally attempted by hackers who send extra long strings over the radio interface.