0
我有一個奇怪的問題,我希望有人可以幫忙。上傳到我的UNO時,我的素描完美地工作,但是當我拔下插頭並插回時,它無法正常工作。如果我重新上傳它,它會再次運行,直到電源循環。 上傳後,液晶顯示屏上寫着:帶2個DS18B20的Arduino LCD。改變週期電源時
Ferm:73.4 73/75
Room:75.1 75/75
循環電源後:
Ferm:73.45 73/18
Room:74.83 75/18
於是重新上電後,我現在得到2位小數和「高」溫度是停留在「18」。
/*
The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
* CLK to Analog #5
* DAT to Analog #4
*/
// include the library code:
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
#include <OneWire.h>
#include <DallasTemperature.h>
//variables for temp readings
float fermTemp;
float fermTempL=100;
float fermTempH=5;
float roomTemp;
float roomTempL=100;
float roomTempH=5;
// set OneWire bus to digital PIN 4 on the Arduino
#define ONE_WIRE_BUS 4
// Setup OneWire instance
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to Dallas Temp
DallasTemperature sensors(&oneWire);
// Connect via i2c, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);
void setup()
{
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// turn on backlight
lcd.setBacklight(HIGH);
}
void loop() {
readtemp();
LCDPrint();
}
void readtemp()
{
// get data from sensors
sensors.requestTemperatures();
fermTemp = (sensors.getTempFByIndex(0));
roomTemp = (sensors.getTempFByIndex(1));
// check/set High and Low temp
if (fermTemp<fermTempL) {
fermTempL=fermTemp;
}
if (fermTemp>fermTempH) {
fermTempH=fermTemp;
}
if (roomTemp<roomTempL) {
roomTempL=roomTemp;
}
if (roomTemp>roomTempH) {
roomTempH=roomTemp;
}
}
void LCDPrint()
{
lcd.setCursor(0,0);
lcd.print("Ferm:");
lcd.print(fermTemp,1);
lcd.setCursor(11,0);
lcd.print(fermTempL,0);
lcd.print("/");
lcd.print(fermTempH,0);
lcd.setCursor(0,1);
lcd.print("Room:");
lcd.print(roomTemp,1);
lcd.setCursor(11,1);
lcd.print(roomTempL,0);
lcd.print("/");
lcd.print(roomTempH,0);
}
這很奇怪..怎麼樣重置?如果您啓動並按下重置按鈕?如果有效,請嘗試延遲設置功能,然後重置LCD和溫度傳感器。如果沒有,請嘗試。在任何情況下..我通常看到相反的行爲(工作在開機,而不是在重置後) – frarugi87
謝謝frarugi87。按下重置按鈕。我會嘗試在設置功能中添加一個延遲,但我不確定通過重置LCD和溫度傳感器的含義。 – MarkZ
應該有一些初始化代碼來在啓動時設置一切。我不知道adafruit圖書館和達拉斯傳感器,但我認爲應該有。嘗試閱讀庫文檔和/或數據表 – frarugi87