-
Notifications
You must be signed in to change notification settings - Fork 2
/
PAN1321.h
61 lines (50 loc) · 1.61 KB
/
PAN1321.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
PAN1321.ino: this file is used to control a PAN1321 module. this
requires flow control. We use RTS and CTS to control when we can
send. These pins can be any pins you dont need in your design.
*/
#include "Arduino.h"
#ifndef PAN1321_h
#define PAN1321_h
#define PAN1321_VERSION 1 // software version of this library
#define CTS 2
#define RTS 14
/*
Init_Bluetooth: initializes the bluetooth module so the host
can connect. In this condition it is discoverable and requires
the passweord 1234
*/
void Init_Bluetooth() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// initialize RTS and CTS respectivley
pinMode(RTS, OUTPUT);
pinMode(CTS, INPUT);
// set RTS high
digitalWrite(RTS, HIGH);
digitalWrite(RTS, LOW);
delay(2000);
// wait for the clear to send from the BT module
while(digitalRead(CTS) != LOW) { }
Serial.println("AT+JRES" );
delay(4000);
while(digitalRead(CTS) != LOW) { }
Serial.println("AT+JSEC=1,2,2,04,1234" );
while(digitalRead(CTS) != LOW) { }
Serial.println("AT+JDIS=3" );
while(digitalRead(CTS) != LOW) { }
Serial.println("AT+JRLS=1101,11,Serial port,01,000000" );
while(digitalRead(CTS) != LOW) { }
Serial.println("AT+JAAC=1" );
while(digitalRead(CTS) != LOW) { }
// wait for a device to connect and then enter streaming mode
while(Serial.read() != '+') { }
while(Serial.read() != 'R') { }
while(Serial.read() != 'C') { }
while(Serial.read() != 'C') { }
Serial.println("AT+JSCR");
// this delay allows the BT "OK" checks to be cleared
delay(1000);
digitalWrite(RTS, LOW);
}
#endif