PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

100 linhas
2.9KB

  1. /*********************************************************************
  2. This is an example for our nRF8001 Bluetooth Low Energy Breakout
  3. Pick one up today in the adafruit shop!
  4. ------> http://www.adafruit.com/products/1697
  5. Adafruit invests time and resources providing this open source code,
  6. please support Adafruit and open-source hardware by purchasing
  7. products from Adafruit!
  8. Written by Kevin Townsend/KTOWN for Adafruit Industries.
  9. MIT license, check LICENSE for more information
  10. All text above, and the splash screen below must be included in any redistribution
  11. *********************************************************************/
  12. // This version uses call-backs on the event and RX so there's no data handling in the main loop!
  13. #include <SPI.h>
  14. #include "Adafruit_BLE_UART.h"
  15. #define ADAFRUITBLE_REQ 10
  16. #define ADAFRUITBLE_RDY 2
  17. #define ADAFRUITBLE_RST 9
  18. Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
  19. /**************************************************************************/
  20. /*!
  21. This function is called whenever select ACI events happen
  22. */
  23. /**************************************************************************/
  24. void aciCallback(aci_evt_opcode_t event)
  25. {
  26. switch(event)
  27. {
  28. case ACI_EVT_DEVICE_STARTED:
  29. Serial.println(F("Advertising started"));
  30. break;
  31. case ACI_EVT_CONNECTED:
  32. Serial.println(F("Connected!"));
  33. break;
  34. case ACI_EVT_DISCONNECTED:
  35. Serial.println(F("Disconnected or advertising timed out"));
  36. break;
  37. default:
  38. break;
  39. }
  40. }
  41. /**************************************************************************/
  42. /*!
  43. This function is called whenever data arrives on the RX channel
  44. */
  45. /**************************************************************************/
  46. void rxCallback(uint8_t *buffer, uint8_t len)
  47. {
  48. Serial.print(F("Received "));
  49. Serial.print(len);
  50. Serial.print(F(" bytes: "));
  51. for(int i=0; i<len; i++)
  52. Serial.print((char)buffer[i]);
  53. Serial.print(F(" ["));
  54. for(int i=0; i<len; i++)
  55. {
  56. Serial.print(" 0x"); Serial.print((char)buffer[i], HEX);
  57. }
  58. Serial.println(F(" ]"));
  59. /* Echo the same data back! */
  60. uart.write(buffer, len);
  61. }
  62. /**************************************************************************/
  63. /*!
  64. Configure the Arduino and start advertising with the radio
  65. */
  66. /**************************************************************************/
  67. void setup(void)
  68. {
  69. Serial.begin(9600);
  70. while(!Serial); // Leonardo/Micro should wait for serial init
  71. Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Callback Echo demo"));
  72. uart.setRXcallback(rxCallback);
  73. uart.setACIcallback(aciCallback);
  74. // uart.setDeviceName("NEWNAME"); /* 7 characters max! */
  75. uart.begin();
  76. }
  77. /**************************************************************************/
  78. /*!
  79. Constantly checks for new events on the nRF8001
  80. */
  81. /**************************************************************************/
  82. void loop()
  83. {
  84. uart.pollACI();
  85. }