Last active
July 10, 2019 05:38
-
-
Save surinoel/93acba031c862bc0398db363bb099340 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String sCommand = ""; | |
char cTemp; | |
int receiveFlag = 0; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
if(receiveFlag) { | |
Serial.println(sCommand); | |
receiveFlag = 0; | |
sCommand = ""; | |
} | |
} | |
void serialEvent(void) | |
{ | |
while(Serial.available()) | |
{ | |
cTemp = Serial.read(); | |
if(cTemp == '\n') { // 개행까지 받는다 | |
receiveFlag = 1; | |
return; | |
} | |
sCommand += cTemp; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DHT.h> | |
#define DHTTYPE DHT11 | |
int pinDht = 2; | |
char buf1[30], buf2[30]; | |
DHT dht(pinDht, DHTTYPE); | |
void setup() { | |
Serial.begin(115200); | |
dht.begin(); | |
} | |
void loop() { | |
delay(1000); | |
float fTemp = dht.readTemperature(); | |
float fHumi = dht.readHumidity(); | |
if (isnan(fTemp) || isnan(fHumi)) { | |
Serial.println("Failed to read from DHT sensor!"); | |
return; | |
} | |
String msg1 = "Temperature: "; | |
msg1 += fTemp; | |
msg1 += "[C]\t\n"; | |
String msg2 = "Humidity: "; | |
msg2 += fHumi; | |
msg2 += "[%]\n"; | |
String msg1 = "TH"; | |
msg1.toCharArray(buf1, 30); | |
msg2.toCharArray(buf2, 30); | |
Serial.write(buf1); | |
Serial.write(buf2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment