Last active
August 29, 2015 14:19
-
-
Save K-ways/e33d3a4ed7317ede1d08 to your computer and use it in GitHub Desktop.
Code for Arduino and Bluetooth module. Copyright © 2014 by K-ways.
This file contains 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 <SoftwareSerial.h> | |
SoftwareSerial BT(11, 12); // RX & TX | |
char val; | |
boolean state2 = 0; | |
void setup() | |
{ | |
pinMode(13, OUTPUT); | |
digitalWrite(13, 1); | |
pinMode(2, INPUT); | |
digitalWrite(2, 1); | |
BT.begin(9600); | |
} | |
void loop() | |
{ | |
val = digitalRead(2); | |
if(val == 0 && state2 == 0) | |
{ | |
BT.write('2'); | |
//BT.print('2'); | |
state2 = 1; | |
} | |
else if(val == 1 && state2 == 1) | |
{ | |
BT.write('0'); //不可write(0) | |
state2 = 0; | |
} | |
} |
This file contains 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 <SoftwareSerial.h> | |
SoftwareSerial BT(11, 12); // RX & TX | |
char val; | |
void setup() | |
{ | |
BT.begin(9600); | |
pinMode(13, OUTPUT); | |
digitalWrite(13, 0); | |
} | |
void loop() | |
{ | |
if (BT.available()) | |
{ | |
val = BT.read(); | |
if (val == '2') | |
digitalWrite(13, 1); | |
else | |
digitalWrite(13, 0); | |
} | |
} |
This file contains 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 <SoftwareSerial.h> | |
SoftwareSerial BT(11, 12); // RX & TX | |
void setup() | |
{ | |
BT.begin(38400); | |
Serial.begin(9600); | |
Serial.println("Enter commands:"); | |
} | |
void loop() | |
{ | |
if (BT.available()) | |
{ | |
char data = BT.read(); | |
Serial.print(data); | |
} | |
if (Serial.available()) | |
BT.write(Serial.read()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment