本帖最后由 90后小白搭 于 2014-5-22 22:09 编辑
void setup() {
Serial.begin(9600); //使用9600速率进行串口通讯
}
void loop() {
int n = analogRead(A0); //读取A0口的电压值
float vol = n * (5.0 / 1023.0*100); //使用浮点数存储温度数据,温度数据由电压值换算得到
Serial.println(vol); //串口输出温度数据
delay(2000); //等待2秒,控制刷新速度
if (vol>=28)
{digitalWrite (7,HIGH);
pinMode(2,OUTPUT); //让2号IO口输出
tone(2,10000);
//发出指定频响
delay(40); //最高频率下维持0.04秒钟
if (vol<28)
noTone(2);
digitalWrite (7,LOW);
delay(1000);
noTone(2);
digitalWrite (7,LOW);
}
}
|