diff options
Diffstat (limited to 'arduino/libraries/Bluefruit52Lib/examples/Peripheral/neomatrix/neomatrix.ino')
-rwxr-xr-x | arduino/libraries/Bluefruit52Lib/examples/Peripheral/neomatrix/neomatrix.ino | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/arduino/libraries/Bluefruit52Lib/examples/Peripheral/neomatrix/neomatrix.ino b/arduino/libraries/Bluefruit52Lib/examples/Peripheral/neomatrix/neomatrix.ino new file mode 100755 index 0000000..6462a29 --- /dev/null +++ b/arduino/libraries/Bluefruit52Lib/examples/Peripheral/neomatrix/neomatrix.ino @@ -0,0 +1,168 @@ +/********************************************************************* + 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 +*********************************************************************/ + +/* How to run this sketch + * - Connect the Neopixel FeatherWing and load this sketch to your Bluefruit52 + * - Connect to the board using the Bluefruit Connect LE app + * - Send character(s) using BLEUART + * - Bluefruit will render the received character(s) on Neopixel FeatherWing + * + * Note: due to the font being larger than the 4x8 Neopixel Wing, you can + * only see part of the characters in some cases. + * Run the sketch with a larger Neopixel Matrix for a complete demo + */ + +/* NOTE: This sketch required at least version 1.1.0 of Adafruit_Neopixel !!! */ + +#include <Arduino.h> +#include <Adafruit_NeoPixel.h> +#include <Adafruit_GFX.h> +#include <Adafruit_NeoMatrix.h> +#include <bluefruit.h> + +#define PIN 30 /* Pin used to drive the NeoPixels */ + +#define MATRIX_WIDTH 4 +#define MATRIX_HEIGHT 8 +#define MATRIX_LAYOUT (NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE) + +// MATRIX DECLARATION: +// Parameter 1 = width of NeoPixel matrix +// Parameter 2 = height of matrix +// Parameter 3 = pin number (most are valid) +// Parameter 4 = matrix layout flags, add together as needed: +// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT: +// Position of the FIRST LED in the matrix; pick two, e.g. +// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner. +// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal +// rows or in vertical columns, respectively; pick one or the other. +// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed +// in the same order, or alternate lines reverse direction; pick one. +// See example below for these values in action. +// Parameter 5 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) + +Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, PIN, + MATRIX_LAYOUT, + NEO_GRB + NEO_KHZ800); + +// BLE Service +BLEDis bledis; +BLEUart bleuart; + +void setup() +{ + Serial.begin(115200); + while ( !Serial ) delay(10); // for nrf52840 with native usb + + Serial.println("Adafruit Bluefruit NeoMatrix"); + Serial.println("----------------------------"); + + Serial.println(); + Serial.println("Please connect using Bluefruit Connect LE application"); + + // Config Neopixels Matrix + matrix.begin(); + matrix.setTextWrap(false); + matrix.setBrightness(40); + matrix.setTextColor( matrix.Color(0, 0, 255) ); // Blue for Bluefruit + + matrix.print('?'); // print out ? + matrix.show(); + + // Init Bluefruit + Bluefruit.begin(); + // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 + Bluefruit.setTxPower(4); + Bluefruit.setName("Bluefruit52"); + Bluefruit.setConnectCallback(connect_callback); + + // Configure and Start Device Information Service + bledis.setManufacturer("Adafruit Industries"); + bledis.setModel("Bluefruit Feather52"); + bledis.begin(); + + // Configure and start BLE UART service + bleuart.begin(); + + // Set up and start advertising + startAdv(); +} + +void startAdv(void) +{ + // Advertising packet + Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + Bluefruit.Advertising.addTxPower(); + + // Include bleuart 128-bit uuid + Bluefruit.Advertising.addService(bleuart); + + // Secondary Scan Response packet (optional) + // Since there is no room for 'Name' in Advertising packet + Bluefruit.ScanResponse.addName(); + + /* Start Advertising + * - Enable auto advertising if disconnected + * - Interval: fast mode = 20 ms, slow mode = 152.5 ms + * - Timeout for fast mode is 30 seconds + * - Start(timeout) with timeout = 0 will advertise forever (until connected) + * + * For recommended advertising interval + * https://developer.apple.com/library/content/qa/qa1931/_index.html + */ + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds +} + +void connect_callback(uint16_t conn_handle) +{ + char central_name[32] = { 0 }; + Bluefruit.Gap.getPeerName(conn_handle, central_name, sizeof(central_name)); + + Serial.print("Connected to "); + Serial.println(central_name); + + Serial.println("Please select 'Uart' tab and send any characters"); +} + + +void loop() +{ + // Echo received data + if ( Bluefruit.connected() && bleuart.notifyEnabled() ) + { + if ( bleuart.available() ) + { + char ch = (char) bleuart.read(); + + // skip newline + if ( ch != '\r' && ch != '\n' ) + { + matrix.fillScreen(0); + matrix.setCursor(0, 0); + matrix.print(ch); + + matrix.show(); + delay(200); + } + } + } +} + |