add Central example folder

This commit is contained in:
Todd Treece committed 2017-03-09 10:00:48 -05:00
1 parent 62704ad287
commit f43c8df7e2
2 files changed
+137

No files matched your search

@@ -0,0 +1,73 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <bluefruit.h>
void setup()
{
Serial.begin(115200);
Serial.println("Bluefruit52 Central Scan Example");
// up to 1 peripheral conn and 1 central conn
Bluefruit.begin(true, true);
Bluefruit.setName("Bluefruit52");
// Increase BLink rate to different from PrPh advertising mode
Bluefruit.setConnLedInterval(250);
// Callbacks for Central
Bluefruit.Central.setConnectCallback(connect_callback);
Bluefruit.Central.setDisconnectCallback(disconnect_callback);
// Start Central Scan
Bluefruit.Central.setScanCallback(scan_callback);
Bluefruit.Central.startScanning();
}
void scan_callback(ble_gap_evt_adv_report_t* report)
{
// Check if advertising contain BleUart service
if ( Bluefruit.Central.checkUuidInScan(report, BLEUART_UUID_SERVICE) )
{
Serial.println("BLE UART service detected");
Serial.println("Attempt to connect ... ");
// Connect to device with bleuart service in advertising
// Use Min & Max Connection Interval default value
Bluefruit.Central.connect(report);
}
}
void connect_callback(void)
{
Serial.println("Connected");
}
void disconnect_callback(uint8_t reason)
{
(void) reason;
Serial.println("Disconnected");
Serial.println("Bluefruit will auto start scanning (default)");
}
void loop()
{
// Toggle both LEDs every 1 second
digitalToggle(LED_BUILTIN);
delay(1000);
}
@@ -0,0 +1,64 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <bluefruit.h>
void setup()
{
Serial.begin(115200);
Serial.println("Bluefruit52 Central Scan Example");
// up to 1 peripheral conn and 1 central conn
Bluefruit.begin(true, true);
Bluefruit.setName("Bluefruit52");
// Start Central Scan
Bluefruit.setConnLedInterval(250);
Bluefruit.Central.setScanCallback(scan_callback);
Bluefruit.Central.startScanning();
}
void scan_callback(ble_gap_evt_adv_report_t* report)
{
Serial.println("Timestamp Addr Rssi Data");
Serial.printf("%09d ", millis());
Serial.printBuffer(report->peer_addr.addr, 6, ':');
Serial.print(" ");
Serial.print(report->rssi);
Serial.print(" ");
Serial.printBuffer(report->data, report->dlen, '-');
Serial.println();
// Check if advertising contain BleUart service
if ( Bluefruit.Central.checkUuidInScan(report, BLEUART_UUID_SERVICE) )
{
Serial.println(" BLE UART service detected");
}
Serial.println();
}
void loop()
{
// Toggle both LEDs every 1 second
digitalToggle(LED_BUILTIN);
delay(1000);
}