|
| 1 | +/********************************************************************* |
| 2 | + This is an example for our nRF52 based Bluefruit LE modules |
| 3 | +
|
| 4 | + Pick one up today in the adafruit shop! |
| 5 | +
|
| 6 | + Adafruit invests time and resources providing this open source code, |
| 7 | + please support Adafruit and open-source hardware by purchasing |
| 8 | + products from Adafruit! |
| 9 | +
|
| 10 | + MIT license, check LICENSE for more information |
| 11 | + All text above, and the splash screen below must be included in |
| 12 | + any redistribution |
| 13 | +*********************************************************************/ |
| 14 | + |
| 15 | +// This sketch is intended to be used with the NeoPixel control |
| 16 | +// surface in Adafruit's Bluefruit LE Connect mobile application. |
| 17 | + |
| 18 | +#include <Arduino.h> |
| 19 | +#include <Adafruit_NeoPixel.h> |
| 20 | +#include <Adafruit_GFX.h> |
| 21 | +#include <Adafruit_NeoMatrix.h> |
| 22 | +#include <bluefruit.h> |
| 23 | + |
| 24 | +#define PIN 30 /* Pin used to drive the NeoPixels */ |
| 25 | + |
| 26 | +#define MATRIX_WIDTH 4 |
| 27 | +#define MATRIX_HEIGHT 8 |
| 28 | +#define MATRIX_LAYOUT (NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE) |
| 29 | + |
| 30 | +// MATRIX DECLARATION: |
| 31 | +// Parameter 1 = width of NeoPixel matrix |
| 32 | +// Parameter 2 = height of matrix |
| 33 | +// Parameter 3 = pin number (most are valid) |
| 34 | +// Parameter 4 = matrix layout flags, add together as needed: |
| 35 | +// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT: |
| 36 | +// Position of the FIRST LED in the matrix; pick two, e.g. |
| 37 | +// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner. |
| 38 | +// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal |
| 39 | +// rows or in vertical columns, respectively; pick one or the other. |
| 40 | +// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed |
| 41 | +// in the same order, or alternate lines reverse direction; pick one. |
| 42 | +// See example below for these values in action. |
| 43 | +// Parameter 5 = pixel type flags, add together as needed: |
| 44 | +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) |
| 45 | +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) |
| 46 | +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) |
| 47 | +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) |
| 48 | + |
| 49 | +Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, PIN, |
| 50 | + MATRIX_LAYOUT, |
| 51 | + NEO_GRB + NEO_KHZ800); |
| 52 | + |
| 53 | +// BLE Service |
| 54 | +BLEDis bledis; |
| 55 | +BLEUart bleuart; |
| 56 | + |
| 57 | +void setup() |
| 58 | +{ |
| 59 | + Serial.begin(115200); |
| 60 | + Serial.println(F("Adafruit Bluefruit NeoMatrix")); |
| 61 | + Serial.println(F("------------------------------------")); |
| 62 | + |
| 63 | + // Config Neopixels Matrix |
| 64 | + matrix.begin(); |
| 65 | + matrix.setTextWrap(false); |
| 66 | + matrix.setBrightness(40); |
| 67 | + matrix.setTextColor( matrix.Color(0, 0, 255) ); // Blue for Bluefruit |
| 68 | + |
| 69 | + // Init Bluefruit |
| 70 | + Bluefruit.begin(); |
| 71 | + Bluefruit.setName("Bluefruit52"); |
| 72 | + |
| 73 | + // Configure and Start Device Information Service |
| 74 | + bledis.setManufacturer("Adafruit Industries"); |
| 75 | + bledis.setModel("Bluefruit Feather52"); |
| 76 | + bledis.begin(); |
| 77 | + |
| 78 | + // Configure and start BLE UART service |
| 79 | + bleuart.begin(); |
| 80 | + |
| 81 | + // Set up the advertising packet |
| 82 | + setupAdv(); |
| 83 | + |
| 84 | + // Start advertising |
| 85 | + Bluefruit.Advertising.start(); |
| 86 | +} |
| 87 | + |
| 88 | +void setupAdv(void) |
| 89 | +{ |
| 90 | + // Bluefruit.Advertising.addTxPower(); |
| 91 | + Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); |
| 92 | + Bluefruit.Advertising.addTxPower(); |
| 93 | + |
| 94 | + // Include bleuart 128-bit uuid |
| 95 | + Bluefruit.Advertising.addService(bleuart); |
| 96 | + |
| 97 | + // There is no room for Name in Advertising packet |
| 98 | + // Use Scan response for Name |
| 99 | + Bluefruit.ScanResponse.addName(); |
| 100 | +} |
| 101 | + |
| 102 | +void loop() |
| 103 | +{ |
| 104 | + // Echo received data |
| 105 | + if ( Bluefruit.connected() && bleuart.notifyEnabled() ) |
| 106 | + { |
| 107 | + if ( bleuart.available() ) |
| 108 | + { |
| 109 | + char ch = (char) bleuart.read(); |
| 110 | + |
| 111 | + matrix.fillScreen(0); |
| 112 | + matrix.setCursor(0, 0); |
| 113 | + matrix.print(ch); |
| 114 | + |
| 115 | + matrix.show(); |
| 116 | + delay(100); |
| 117 | + } |
| 118 | + } |
| 119 | +} |
| 120 | + |
0 commit comments