BASIC4MCU | 질문게시판 | 아두이노 소스 2개만 합쳐주세요
페이지 정보
작성자 햄스팸 작성일2018-06-07 15:41 조회8,282회 댓글0건본문
#include <SoftwareSerial.h>
#define BT_RXD 8
#define BT_TXD 7
SoftwareSerial bluetooth(BT_RXD,BT_TXD);
SoftwareSerial gps(11,12); //tx,rx를 각각의 핀에 연결
//
#include <OneWire.h>
int DS18S20_Pin=2; //온도센서를 2번 핀으로 연결
OneWire ds(DS18S20_Pin); //2번 핀과 연결되 OneWire 객체 생성
//
int red=11; //빨간색led를 11번 핀으로 연결
int blue=10; //파란색led를 10번 핀으로 연결
//
void setup(){
pinMode(red,OUTPUT); pinMode(blue,OUTPUT);
Serial.begin(9600);
bluetooth.begin(9600);
gps.begin(9600);
}
//
void loop(){
if(gps.available()){ Serial.write(gps.read()); }
//
if(bluetooth.available()){ Serial.write(bluetooth.read()); }
if(Serial.available()){ bluetooth.write(Serial.read()); }
//
float temperature=getTemp(); //온도 측정 후 변수에 저장
Serial.println(temperature);
if(temperature<24){ digitalWrite(red,LOW); digitalWrite(blue,HIGH); delay(100); } //온도가 24도 이하일 때,파란색 LED 점등
else{ digitalWrite(red,HIGH); digitalWrite(blue,LOW); delay(100); } //온도가 24도 이상일 때,빨간색 LED 점등
}
//
float getTemp(){ //온도 측정 후 반환하는 함수
byte data[12];
byte addr[8];
if(!ds.search(addr)){ ds.reset_search(); return-1000; }
if(OneWire:: crc8(addr,7)!=addr[7]){ Serial.println("CRC is not valid!"); return-1000; }
if(addr[0]!=0x10&&addr[0]!=0x28){ Serial.print("Device is not recognized"); return-1000; }
ds.reset();
ds.select(addr);
ds.write(0x44,1);
byte present=ds.reset();
ds.select(addr);
ds.write(0xBE);
for(int i=0; i<9; i++){ data[i]=ds.read(); }
ds.reset_search();
byte MSB=data[1]; byte LSB=data[0];
float tempRead=((MSB<<8)|LSB);
float TemperatureSum=tempRead/16;
return TemperatureSum;
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
위 소스에다가 심장박동 모니터링 소스를 추가하고싶은데 밑에 소스는 있는데 합치는 방법을 잘 모르겠습니다.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ심장박동소스ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.// Variables
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore.
// Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default "550" value.
PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"
void setup() {Serial.begin(9600); // For Serial Monitor
// Configure the PulseSensor object, by assigning our variables to it.
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat.
pulseSensor.setThreshold(Threshold);// Double-check the "pulseSensor" object was created and "began" seeing a signal.
if (pulseSensor.begin()) {
Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset.
}
}
void loop() {
int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
// "myBPM" hold this BPM value now.if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
// If test is "true", print a message "a heartbeat happened".
Serial.print("BPM: "); // Print phrase "BPM: "
Serial.println(myBPM); // Print the value inside of myBPM.
}delay(200); // considered best practice in a simple sketch.
}
댓글 0
조회수 8,282등록된 댓글이 없습니다.