2017년 6월 1일 목요일
Bluetooth 연결테스트
////////////블루투스 통신읽기
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2,3);
int analog0;
void setup()
{
// Serial.begin(9600);
BTSerial.begin(9600);
}
void loop()
{
analog0 = analogRead(A0);
BTSerial.print("poten#: ");
BTSerial.println(analog0);
// Serial.println(analog0);
delay(500);
}
/////////////블루투스 설정변경
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2,3);
void setup()
{
Serial.begin(9600);
BTSerial.begin(9600);
}
void loop()
{
if (BTSerial.available()) {
Serial.write(BTSerial.read()); }
if (Serial.available()) {
BTSerial.write(Serial.read()); }
}
////////////시리얼 입출력
int inData;
int LED1 = 8;
void setup()
{
Serial.begin(9600);
pinMode(LED1,OUTPUT);
}
void loop()
{
if(Serial.available()>0)
{
inData = Serial.read();
if (inData == 'A')
digitalWrite(LED1,HIGH);
if (inData == 'D')
digitalWrite(LED1,LOW);
delay(1000);
}
}
////////////////블루투스 입출력
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2,3);
int inData;
int LED1 = 8;
void setup()
{
BTSerial.begin(9600);
pinMode(LED1,OUTPUT);
}
void loop()
{
if(BTSerial.available())
{
inData = BTSerial.read();
if (inData == 'A')
digitalWrite(LED1,HIGH);
if (inData == 'D')
digitalWrite(LED1,LOW);
delay(1000);
}
}
//////////////빛센서cds 출력
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2,3);
void setup()
{
BTSerial.begin(9600);
}
void loop()
{
int cds = analogRead(A0);
BTSerial.print("Cds: ");
BTSerial.println(cds);
delay(500);
}
///////////////'0'문자형테스트
int inData;
int cha;
int LED1 = 8;
void setup()
{
Serial.begin(9600);
pinMode(LED1,OUTPUT);
}
void loop()
{
if(Serial.available())
{
inData = Serial.read();
cha = (inData-'0');
if (cha == 1)
digitalWrite(LED1,HIGH);
if (cha == 0)
digitalWrite(LED1,LOW);
delay(1000);
}
}
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기