楼主: Jane
|
[入门教程] Arduino教程08 温度报警器「DFR0100 」 |
刚开始学,不过刚才把LED灯也加进来了,成为了闪灯的温度蜂鸣报警器。 代码里处事给LED 9端口,然后把灯闪的代码加到FOR循环里。 |
求助:刚开始运行正常,一段时间后串口监视器上以极快的速度刷出温度数据,而非500ms,求问大神哪儿出了问题。 代码: #define VOICE 8 float sinV; int toneV; int tempD; int tempT = 0; double data; void setup() { // put your setup code here, to run once: pinMode(8,OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: tempD = analogRead(3); data = double(tempD)/10.23*5; if (data >= 30) { buzz(); } else { noTone(8); } if (millis() - tempT > 500) { tempT = millis(); Serial.print("temperature ="); Serial.print(data); Serial.println("C"); } } void buzz() { for(int i=0;i<180;i++) { sinV = sin(float(i)/180*3.1416); toneV = int(sinV*1000 + 2000); tone(8,toneV); delay(2); } } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed