From: acevest Date: Sat, 20 Jun 2015 03:34:47 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=edcde256765f348b827d4db0cbce17d7da3e0592;p=acecode.git ... --- diff --git a/arduino/Sensors/Sensors.ino b/arduino/Sensors/Sensors.ino index 2059970..81f45aa 100644 --- a/arduino/Sensors/Sensors.ino +++ b/arduino/Sensors/Sensors.ino @@ -1,6 +1,7 @@ #include #include #include +#include #define TEMP_WIRE_BUS 2 @@ -11,6 +12,8 @@ DallasTemperature TempSensors(&TempWire); SoftwareSerial BTSerial(10, 11); // RX | TX +DHT dht; + int cnt = 0; const int ledPin = 12; @@ -23,46 +26,55 @@ void setup() { pinMode(2, INPUT); pinMode(3, INPUT); - TempSensors.begin(); + TempSensors.begin();//TEMP_WIRE_BUS); + TempSensors.setResolution(12); + + dht.setup(4, DHT::DHT11); } -char* itos(int n) +char *itos(int n) { static char buf[16]; sprintf(buf, "%d", n); return buf; } +char *ftos(float f) +{ + static char buf[32]; + sprintf(buf, "%.2f", f); + return buf; +} + void loop() { cnt ++; +#if 0 + int bd = digitalRead(7); + + Serial.print(">"); + Serial.print(bd); + Serial.println("<"); + delay(100); + return; +#endif + TempSensors.requestTemperatures(); float tv = TempSensors.getTempCByIndex(0); - + + //delay(dht.getMinimumSamplingPeriod()); + float hv = dht.getHumidity(); // Humidity + int lv = analogRead(0); // Light //int tv = analogRead(1); // Temperature int hb = analogRead(2); // Human Body - int hv = analogRead(3); // humidity - - - if(hb < 100) - { - hb = 0; - } - - digitalWrite(ledPin, hb > 0 ? HIGH : LOW); + //int hv = analogRead(3); // humidity - delay(10); - - if(cnt % 100 == 0) + if(cnt % 1 == 0) { - float temperature; - //float resistance = (float)(1023.0-tv)*10000.0/tv; - //temperature = 1.00000/(log(resistance/10000)/3975+1/298.15) - 273.15; - Serial.print(">"); Serial.print(lv); Serial.print(":"); @@ -71,13 +83,31 @@ void loop() { Serial.print(hb); Serial.print(":"); Serial.print(hv); + Serial.print(" Humidity:"); + Serial.print(dht.getHumidity()); + Serial.print(" Temp:"); + Serial.print(dht.getTemperature()); Serial.println(" "); + + +#if 1 + BTSerial.print(">"); + BTSerial.print(lv, DEC); + BTSerial.print(":"); + BTSerial.print(tv, DEC); + BTSerial.print(":"); + BTSerial.print(hv, DEC); + BTSerial.print(":"); + BTSerial.print(hb, DEC); + BTSerial.println("<"); +#endif + #if 0 BTSerial.write(">"); BTSerial.write(itos(lv)); BTSerial.write(":"); - BTSerial.write(itos(tv)); + BTSerial.write(ftos(tv)); BTSerial.write(":"); BTSerial.write(itos(hb)); BTSerial.write(":"); diff --git a/learn/doc/zshrc b/learn/doc/zshrc new file mode 100644 index 0000000..14e93f2 --- /dev/null +++ b/learn/doc/zshrc @@ -0,0 +1,3 @@ +# for mac zsh +alias ls='ls -G' +alias ll='ls -l -G'