I want to input this #011* over de serial to send using VirtualWire.h library on Rf communication.
This example i only send number:
while (Serial.available() > 0) {
int x = Serial.parseInt();
Serial.println(x);
for(i=2;i>=0;i--){
buf1[i]= x % 10;
x /= 10;
}
vw_send((uint8_t *)buf1, strlen(buf1));
}
But i want to send #011* to the receiver.Anyone help me?
Why don't you just put the string in the buffer and send it?
Am I missing something (apart from, the rest of the code)?
How is declared buf1 ?
You send buf1 ?
But in buf1 every elements are not a numerical character "011" => '0' , '1' , '1' but 0, 1 and 1 real number !!!
To send also '#' and '*' you need to declare buf1 with 2 other elements, first will be
buf[0]='#';
and last will be
buf[4]='*';
all before send
for cicle modified starting 3 to 1 but add to formula '0' to x % 10
for(i=3;i>=1;i--)
{ buf1[i]= '0' + x % 10;
x /= 10;
}
EDIT: sorry for missing tags. Two moderator's messages for the same mistake?
And that, ladies and gentlemen, is why we ask you to please use CODE TAGS.
I declare buf[0]=’#’ and buf[4]=’*’.And put 011 over the Serial?
Iam using VirtualWire.h.I have one transmitter and receiver.
I want to send #111* and the receive this sequence.
Example receive code:
#include <VirtualWire.h>
int led=13;
void setup()
{
vw_setup(2000);
vw_set_rx_pin(2);
vw_rx_start();
}
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message(buf, &buflen)) // non-blocking I/O
{
if(buf[0]=='#'&&buf[4]=='*'){
digitalWrite(led,HIGH);
}
}