I'm a fairly inexperienced with arduino, so i'm asking you for a bit of help!
I'm trying to send and integer from one arduino to another one. Ex: you set an integer on one arduino to 1007. You send it to other arduino with virtual wire library and the number becomes the value of some other integer on the receiving side. (433 MHz module, transmitter and receiver). How would i do that? What is the simplest way of doing that?
I've been searching on the internet for a simple solution, but no luck. I don't know if everything they put in is necessary for the program to function, and it's always some weird obscure case where they add a bunch of other code in and it gets messy and i'm left even more confused than i'm at the start. It would help me a ton if someone would be kind enough to write the code for both the transmitting and receiving side.
Virtual Wire has been deprecated (not maintained and not recommended for new development) for several years. You should instead use the Radio Head library from the same developer.
johnwasser:
Virtual Wire has been deprecated (not maintained and not recommended for new development) for several years. You should instead use the Radio Head library from the same developer.
I know yes, but i figured that it would be simpler if I did it with the virtual wire. What about radio head but for integer only? Would You happen to know how to write the proper code?
VirtualWire works as advertised, has no known bugs and takes up far less memory than RadioHead, so you can ignore the warnings about deprecation.
The solution proposed by johnwasser will work for a variable of any type. For the receiving code, use the same approach, but do not forget to reset the message length to maximum expected every time.
int message = 0;
uint8_t buflen = sizeof(message);
if (vw_get_message( (uint8_t *) &message, &buflen)) // Non-blocking
{
if(buflen == sizeof(message) ) { //correct message size received