Arduino VirtualWire Rf模块发送字符串

时间:2014-09-30 01:35:10

标签: arduino

很抱歉,如果我的帖子格式不合适,请点击此处。

/*
    SimpleSend
    This sketch transmits a short text message using the VirtualWire library
    connect the Transmitter data pin to Arduino pin 12
    */
    #include <VirtualWire.h>

String Mensagem  = "eureca"; //I want to send this string

void setup(){
   // Initialize the IO and ISR
   vw_setup(2000); // Bits per sec
}
void loop(){
    send(Mensagem); //Putting a string inside the function does not work, 
    //I want to send a String message inside that function like a parameter
    delay(1000);
}

void send (char *message){
    vw_send((uint8_t *)message, strlen(message));
    vw_wait_tx(); // Wait until the whole message is gone
}

1 个答案:

答案 0 :(得分:1)

char *message表示字符串文字或字符指针,但是您传递给函数的是String。 您可以使用以下方法修复它:

char Mensagem[]= "eureca";

以匹配类型。这是因为Mensagem现在是该字符数组的静态指针。