将数据保存在arduino的文本文件中

时间:2015-11-10 19:38:21

标签: arduino

我有一个arduino温度测量设备,它将使用LM35传感器测量温度。电气侧不是我的区域。我正在使用一个c程序,它将从两个不同的传感器获得平均两个不同的数据并将其写入文件。这是我第一次为微控制器编写c程序。我收到了这个错误:

  

"的fopen'未在此范围内声明

为什么我收到此错误?怎么解决这个?

int sensor1 = A0;
int sensor2 = A1;

void setup() 
{
  pinMode(sensor1,INPUT);
  pinMode(sensor2,INPUT);
  Serial.begin(9600);

  analogReference(INTERNAL1V1);
}

void loop()
{
int temp1 = analogRead(sensor1);
int temp2 = analogRead(sensor2);
double t1 = ((1.100000001/1024)*temp1)/.01;
double t2 = ((1.100000001/1024)*temp2)/.01;
double tempavg=(t1+t2)/2;
FILE *fp;
if(fp=fopen('myfile.txt','w')){
   fprintf(fp,"%d",tempavg);
   fclose(fp);
}
Serial.print(temp1);
Serial.print("     ");
Serial.println(t1,4);
Serial.print(temp2);
Serial.print("     ");
Serial.println(t2,4);
Serial.println("----------------");
delay(2000);

}

1 个答案:

答案 0 :(得分:-1)

您需要包含具有该功能的库。有时,将错误消息粘贴到谷歌并阅读开头的任何内容也是有好处的。随着时间的推移,您的眼睛将接受如何将有用信息从无用信息分类到您的特定问题的培训。 C++ program compilation fails in Ubuntu, but works in MacOSX