Page 44 - MDP2020-2
P. 44
| 인천전자마이스터고등학교 ·············································································································
38
<아두이노 블루투스 송신코드>
#include <Wire.h>
#include <OneWire.h>
#include <SoftwareSerial.h>
int Tx=8; //전송
int Rx=9; //수신
SoftwareSerial blth(Tx, Rx);
OneWire ds(2);
unsigned long time_previous, time_current;
void setup()
{
Serial.begin(9600);
blth.begin(9600);
time_previous = millis();
}
void loop()
{
time_current = millis();
double temp = getTemp();
if (blth.available()) {
Serial.write(blth.read());
}
if (Serial.available()) {
blth.write(Serial.read());
}
if(time_current-time_previous >=1000)
{
blth.print(temp);
blth.println("");
Serial.println(temp);
}
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];