带有F()的println中的Arduino sprintf

时间:2015-05-27 20:40:36

标签: c arduino arduino-uno arduino-ide

您好我的C代码有问题,我正在尝试println(F(VARIABLE))但我收到错误

void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    sendData(25,60);
}

void loop() {
    // put your main code here, to run repeatedly:    
}

void sendData(float temperature,float batterylvl){
    char tmp[25];
    char batt[25];
    sprintf(tmp, "temperature=%f", temperature);
    sprintf(batt, "battery=%f", batterylvl);

    Serial.println(F(tmp));
    Serial.println(F(batt));      
}

1 个答案:

答案 0 :(得分:3)

[nil<-header1->nil][data1 ...............................] 用于常量字符串。例如传递给F()的格式字符串。与传递给sprintf()的变量不同。