initial commit
This commit is contained in:
commit
99c1b35226
1
.gitignore
vendored
Executable file
1
.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
|||||||
|
build/
|
||||||
23
.vscode/c_cpp_properties.json
vendored
Normal file
23
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "ESP-IDF",
|
||||||
|
"cStandard": "c11",
|
||||||
|
"cppStandard": "c++17",
|
||||||
|
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
|
||||||
|
"includePath": [
|
||||||
|
"~/esp/esp-idf/components/**",
|
||||||
|
"~/esp/esp-idf/components/arduino/libraries/**",
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"browse": {
|
||||||
|
"path": [
|
||||||
|
"~/esp/esp-idf/components",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"limitSymbolsToIncludedHeaders": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
79
.vscode/settings.json
vendored
Normal file
79
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"*.ipp": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"array": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"regex": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"future": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"condition_variable": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"unordered_set": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"strstream": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"codecvt": "cpp",
|
||||||
|
"csignal": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"map": "cpp",
|
||||||
|
"memory_resource": "cpp",
|
||||||
|
"ratio": "cpp",
|
||||||
|
"set": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"iostream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"mutex": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"thread": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"compare": "cpp",
|
||||||
|
"concepts": "cpp",
|
||||||
|
"netfwd": "cpp",
|
||||||
|
"numbers": "cpp",
|
||||||
|
"semaphore": "cpp",
|
||||||
|
"stop_token": "cpp",
|
||||||
|
"*.inc": "cpp"
|
||||||
|
},
|
||||||
|
|
||||||
|
"cmake.configureOnOpen": false,
|
||||||
|
"C_Cpp.dimInactiveRegions": true,
|
||||||
|
"editor.autoIndent": "full",
|
||||||
|
}
|
||||||
7
CMakeLists.txt
Normal file
7
CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# The following five lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(wellhub)
|
||||||
BIN
components/AdafruitNeoPixel/.DS_Store
vendored
Executable file
BIN
components/AdafruitNeoPixel/.DS_Store
vendored
Executable file
Binary file not shown.
4
components/AdafruitNeoPixel/.gitignore
vendored
Executable file
4
components/AdafruitNeoPixel/.gitignore
vendored
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
# Our handy .gitignore for automation ease
|
||||||
|
Doxyfile*
|
||||||
|
doxygen_sqlite3.db
|
||||||
|
html
|
||||||
1
components/AdafruitNeoPixel/.piopm
Executable file
1
components/AdafruitNeoPixel/.piopm
Executable file
@ -0,0 +1 @@
|
|||||||
|
{"type": "library", "name": "Adafruit NeoPixel", "version": "1.12.0", "spec": {"owner": "adafruit", "id": 28, "name": "Adafruit NeoPixel", "requirements": null, "uri": null}}
|
||||||
3474
components/AdafruitNeoPixel/Adafruit_NeoPixel.cpp
Executable file
3474
components/AdafruitNeoPixel/Adafruit_NeoPixel.cpp
Executable file
File diff suppressed because it is too large
Load Diff
412
components/AdafruitNeoPixel/Adafruit_NeoPixel.h
Executable file
412
components/AdafruitNeoPixel/Adafruit_NeoPixel.h
Executable file
@ -0,0 +1,412 @@
|
|||||||
|
/*!
|
||||||
|
* @file Adafruit_NeoPixel.h
|
||||||
|
*
|
||||||
|
* This is part of Adafruit's NeoPixel library for the Arduino platform,
|
||||||
|
* allowing a broad range of microcontroller boards (most AVR boards,
|
||||||
|
* many ARM devices, ESP8266 and ESP32, among others) to control Adafruit
|
||||||
|
* NeoPixels, FLORA RGB Smart Pixels and compatible devices -- WS2811,
|
||||||
|
* WS2812, WS2812B, SK6812, etc.
|
||||||
|
*
|
||||||
|
* Adafruit invests time and resources providing this open source code,
|
||||||
|
* please support Adafruit and open-source hardware by purchasing products
|
||||||
|
* from Adafruit!
|
||||||
|
*
|
||||||
|
* Written by Phil "Paint Your Dragon" Burgess for Adafruit Industries,
|
||||||
|
* with contributions by PJRC, Michael Miller and other members of the
|
||||||
|
* open source community.
|
||||||
|
*
|
||||||
|
* This file is part of the Adafruit_NeoPixel library.
|
||||||
|
*
|
||||||
|
* Adafruit_NeoPixel is free software: you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Adafruit_NeoPixel is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with NeoPixel. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADAFRUIT_NEOPIXEL_H
|
||||||
|
#define ADAFRUIT_NEOPIXEL_H
|
||||||
|
|
||||||
|
#ifdef ARDUINO
|
||||||
|
#if (ARDUINO >= 100)
|
||||||
|
#include <Arduino.h>
|
||||||
|
#else
|
||||||
|
#include <WProgram.h>
|
||||||
|
#include <pins_arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_TINYUSB // For Serial when selecting TinyUSB
|
||||||
|
#include <Adafruit_TinyUSB.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TARGET_LPC1768
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_RP2040)
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#include "hardware/clocks.h"
|
||||||
|
#include "rp2040_pio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// The order of primary colors in the NeoPixel data stream can vary among
|
||||||
|
// device types, manufacturers and even different revisions of the same
|
||||||
|
// item. The third parameter to the Adafruit_NeoPixel constructor encodes
|
||||||
|
// the per-pixel byte offsets of the red, green and blue primaries (plus
|
||||||
|
// white, if present) in the data stream -- the following #defines provide
|
||||||
|
// an easier-to-use named version for each permutation. e.g. NEO_GRB
|
||||||
|
// indicates a NeoPixel-compatible device expecting three bytes per pixel,
|
||||||
|
// with the first byte transmitted containing the green value, second
|
||||||
|
// containing red and third containing blue. The in-memory representation
|
||||||
|
// of a chain of NeoPixels is the same as the data-stream order; no
|
||||||
|
// re-ordering of bytes is required when issuing data to the chain.
|
||||||
|
// Most of these values won't exist in real-world devices, but it's done
|
||||||
|
// this way so we're ready for it (also, if using the WS2811 driver IC,
|
||||||
|
// one might have their pixels set up in any weird permutation).
|
||||||
|
|
||||||
|
// Bits 5,4 of this value are the offset (0-3) from the first byte of a
|
||||||
|
// pixel to the location of the red color byte. Bits 3,2 are the green
|
||||||
|
// offset and 1,0 are the blue offset. If it is an RGBW-type device
|
||||||
|
// (supporting a white primary in addition to R,G,B), bits 7,6 are the
|
||||||
|
// offset to the white byte...otherwise, bits 7,6 are set to the same value
|
||||||
|
// as 5,4 (red) to indicate an RGB (not RGBW) device.
|
||||||
|
// i.e. binary representation:
|
||||||
|
// 0bWWRRGGBB for RGBW devices
|
||||||
|
// 0bRRRRGGBB for RGB
|
||||||
|
|
||||||
|
// RGB NeoPixel permutations; white and red offsets are always same
|
||||||
|
// Offset: W R G B
|
||||||
|
#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B
|
||||||
|
#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G
|
||||||
|
#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B
|
||||||
|
#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R
|
||||||
|
#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G
|
||||||
|
#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R
|
||||||
|
|
||||||
|
// RGBW NeoPixel permutations; all 4 offsets are distinct
|
||||||
|
// Offset: W R G B
|
||||||
|
#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) ///< Transmit as W,R,G,B
|
||||||
|
#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) ///< Transmit as W,R,B,G
|
||||||
|
#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) ///< Transmit as W,G,R,B
|
||||||
|
#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) ///< Transmit as W,G,B,R
|
||||||
|
#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) ///< Transmit as W,B,R,G
|
||||||
|
#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) ///< Transmit as W,B,G,R
|
||||||
|
|
||||||
|
#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) ///< Transmit as R,W,G,B
|
||||||
|
#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) ///< Transmit as R,W,B,G
|
||||||
|
#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) ///< Transmit as R,G,W,B
|
||||||
|
#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B,W
|
||||||
|
#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) ///< Transmit as R,B,W,G
|
||||||
|
#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G,W
|
||||||
|
|
||||||
|
#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) ///< Transmit as G,W,R,B
|
||||||
|
#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) ///< Transmit as G,W,B,R
|
||||||
|
#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) ///< Transmit as G,R,W,B
|
||||||
|
#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B,W
|
||||||
|
#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,W,R
|
||||||
|
#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R,W
|
||||||
|
|
||||||
|
#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) ///< Transmit as B,W,R,G
|
||||||
|
#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) ///< Transmit as B,W,G,R
|
||||||
|
#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) ///< Transmit as B,R,W,G
|
||||||
|
#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G,W
|
||||||
|
#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,W,R
|
||||||
|
#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R,W
|
||||||
|
|
||||||
|
// Add NEO_KHZ400 to the color order value to indicate a 400 KHz device.
|
||||||
|
// All but the earliest v1 NeoPixels expect an 800 KHz data stream, this is
|
||||||
|
// the default if unspecified. Because flash space is very limited on ATtiny
|
||||||
|
// devices (e.g. Trinket, Gemma), v1 NeoPixels aren't handled by default on
|
||||||
|
// those chips, though it can be enabled by removing the ifndef/endif below,
|
||||||
|
// but code will be bigger. Conversely, can disable the NEO_KHZ400 line on
|
||||||
|
// other MCUs to remove v1 support and save a little space.
|
||||||
|
|
||||||
|
#define NEO_KHZ800 0x0000 ///< 800 KHz data transmission
|
||||||
|
#ifndef __AVR_ATtiny85__
|
||||||
|
#define NEO_KHZ400 0x0100 ///< 400 KHz data transmission
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If 400 KHz support is enabled, the third parameter to the constructor
|
||||||
|
// requires a 16-bit value (in order to select 400 vs 800 KHz speed).
|
||||||
|
// If only 800 KHz is enabled (as is default on ATtiny), an 8-bit value
|
||||||
|
// is sufficient to encode pixel color order, saving some space.
|
||||||
|
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
typedef uint16_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor
|
||||||
|
#else
|
||||||
|
typedef uint8_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// These two tables are declared outside the Adafruit_NeoPixel class
|
||||||
|
// because some boards may require oldschool compilers that don't
|
||||||
|
// handle the C++11 constexpr keyword.
|
||||||
|
|
||||||
|
/* A PROGMEM (flash mem) table containing 8-bit unsigned sine wave (0-255).
|
||||||
|
Copy & paste this snippet into a Python REPL to regenerate:
|
||||||
|
import math
|
||||||
|
for x in range(256):
|
||||||
|
print("{:3},".format(int((math.sin(x/128.0*math.pi)+1.0)*127.5+0.5))),
|
||||||
|
if x&15 == 15: print
|
||||||
|
*/
|
||||||
|
static const uint8_t PROGMEM _NeoPixelSineTable[256] = {
|
||||||
|
128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170,
|
||||||
|
173, 176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211,
|
||||||
|
213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240,
|
||||||
|
241, 243, 244, 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254,
|
||||||
|
254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251,
|
||||||
|
250, 250, 249, 248, 246, 245, 244, 243, 241, 240, 238, 237, 235, 234, 232,
|
||||||
|
230, 228, 226, 224, 222, 220, 218, 215, 213, 211, 208, 206, 203, 201, 198,
|
||||||
|
196, 193, 190, 188, 185, 182, 179, 176, 173, 170, 167, 165, 162, 158, 155,
|
||||||
|
152, 149, 146, 143, 140, 137, 134, 131, 128, 124, 121, 118, 115, 112, 109,
|
||||||
|
106, 103, 100, 97, 93, 90, 88, 85, 82, 79, 76, 73, 70, 67, 65,
|
||||||
|
62, 59, 57, 54, 52, 49, 47, 44, 42, 40, 37, 35, 33, 31, 29,
|
||||||
|
27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, 10, 9, 7, 6,
|
||||||
|
5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 11,
|
||||||
|
12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37,
|
||||||
|
40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
|
||||||
|
79, 82, 85, 88, 90, 93, 97, 100, 103, 106, 109, 112, 115, 118, 121,
|
||||||
|
124};
|
||||||
|
|
||||||
|
/* Similar to above, but for an 8-bit gamma-correction table.
|
||||||
|
Copy & paste this snippet into a Python REPL to regenerate:
|
||||||
|
import math
|
||||||
|
gamma=2.6
|
||||||
|
for x in range(256):
|
||||||
|
print("{:3},".format(int(math.pow((x)/255.0,gamma)*255.0+0.5))),
|
||||||
|
if x&15 == 15: print
|
||||||
|
*/
|
||||||
|
static const uint8_t PROGMEM _NeoPixelGammaTable[256] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
|
||||||
|
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3,
|
||||||
|
3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
|
||||||
|
6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10,
|
||||||
|
11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17,
|
||||||
|
17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
|
||||||
|
25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35,
|
||||||
|
36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48,
|
||||||
|
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||||
|
64, 65, 66, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81,
|
||||||
|
82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, 97, 99, 100, 102,
|
||||||
|
103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 119, 120, 122, 124, 125,
|
||||||
|
127, 129, 130, 132, 134, 136, 137, 139, 141, 143, 145, 146, 148, 150, 152,
|
||||||
|
154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182,
|
||||||
|
184, 186, 188, 191, 193, 195, 197, 199, 202, 204, 206, 209, 211, 213, 215,
|
||||||
|
218, 220, 223, 225, 227, 230, 232, 235, 237, 240, 242, 245, 247, 250, 252,
|
||||||
|
255};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief Class that stores state and functions for interacting with
|
||||||
|
Adafruit NeoPixels and compatible devices.
|
||||||
|
*/
|
||||||
|
class Adafruit_NeoPixel {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor: number of LEDs, pin number, LED type
|
||||||
|
Adafruit_NeoPixel(uint16_t n, int16_t pin = 6,
|
||||||
|
neoPixelType type = NEO_GRB + NEO_KHZ800);
|
||||||
|
Adafruit_NeoPixel(void);
|
||||||
|
~Adafruit_NeoPixel();
|
||||||
|
|
||||||
|
void begin(void);
|
||||||
|
void show(void);
|
||||||
|
void setPin(int16_t p);
|
||||||
|
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||||
|
void setPixelColor(uint16_t n, uint32_t c);
|
||||||
|
void fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0);
|
||||||
|
void setBrightness(uint8_t);
|
||||||
|
void clear(void);
|
||||||
|
void updateLength(uint16_t n);
|
||||||
|
void updateType(neoPixelType t);
|
||||||
|
/*!
|
||||||
|
@brief Check whether a call to show() will start sending data
|
||||||
|
immediately or will 'block' for a required interval. NeoPixels
|
||||||
|
require a short quiet time (about 300 microseconds) after the
|
||||||
|
last bit is received before the data 'latches' and new data can
|
||||||
|
start being received. Usually one's sketch is implicitly using
|
||||||
|
this time to generate a new frame of animation...but if it
|
||||||
|
finishes very quickly, this function could be used to see if
|
||||||
|
there's some idle time available for some low-priority
|
||||||
|
concurrent task.
|
||||||
|
@return 1 or true if show() will start sending immediately, 0 or false
|
||||||
|
if show() would block (meaning some idle time is available).
|
||||||
|
*/
|
||||||
|
bool canShow(void) {
|
||||||
|
// It's normal and possible for endTime to exceed micros() if the
|
||||||
|
// 32-bit clock counter has rolled over (about every 70 minutes).
|
||||||
|
// Since both are uint32_t, a negative delta correctly maps back to
|
||||||
|
// positive space, and it would seem like the subtraction below would
|
||||||
|
// suffice. But a problem arises if code invokes show() very
|
||||||
|
// infrequently...the micros() counter may roll over MULTIPLE times in
|
||||||
|
// that interval, the delta calculation is no longer correct and the
|
||||||
|
// next update may stall for a very long time. The check below resets
|
||||||
|
// the latch counter if a rollover has occurred. This can cause an
|
||||||
|
// extra delay of up to 300 microseconds in the rare case where a
|
||||||
|
// show() call happens precisely around the rollover, but that's
|
||||||
|
// neither likely nor especially harmful, vs. other code that might
|
||||||
|
// stall for 30+ minutes, or having to document and frequently remind
|
||||||
|
// and/or provide tech support explaining an unintuitive need for
|
||||||
|
// show() calls at least once an hour.
|
||||||
|
uint32_t now = micros();
|
||||||
|
if (endTime > now) {
|
||||||
|
endTime = now;
|
||||||
|
}
|
||||||
|
return (now - endTime) >= 300L;
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief Get a pointer directly to the NeoPixel data buffer in RAM.
|
||||||
|
Pixel data is stored in a device-native format (a la the NEO_*
|
||||||
|
constants) and is not translated here. Applications that access
|
||||||
|
this buffer will need to be aware of the specific data format
|
||||||
|
and handle colors appropriately.
|
||||||
|
@return Pointer to NeoPixel buffer (uint8_t* array).
|
||||||
|
@note This is for high-performance applications where calling
|
||||||
|
setPixelColor() on every single pixel would be too slow (e.g.
|
||||||
|
POV or light-painting projects). There is no bounds checking
|
||||||
|
on the array, creating tremendous potential for mayhem if one
|
||||||
|
writes past the ends of the buffer. Great power, great
|
||||||
|
responsibility and all that.
|
||||||
|
*/
|
||||||
|
uint8_t *getPixels(void) const { return pixels; };
|
||||||
|
uint8_t getBrightness(void) const;
|
||||||
|
/*!
|
||||||
|
@brief Retrieve the pin number used for NeoPixel data output.
|
||||||
|
@return Arduino pin number (-1 if not set).
|
||||||
|
*/
|
||||||
|
int16_t getPin(void) const { return pin; };
|
||||||
|
/*!
|
||||||
|
@brief Return the number of pixels in an Adafruit_NeoPixel strip object.
|
||||||
|
@return Pixel count (0 if not set).
|
||||||
|
*/
|
||||||
|
uint16_t numPixels(void) const { return numLEDs; }
|
||||||
|
uint32_t getPixelColor(uint16_t n) const;
|
||||||
|
/*!
|
||||||
|
@brief An 8-bit integer sine wave function, not directly compatible
|
||||||
|
with standard trigonometric units like radians or degrees.
|
||||||
|
@param x Input angle, 0-255; 256 would loop back to zero, completing
|
||||||
|
the circle (equivalent to 360 degrees or 2 pi radians).
|
||||||
|
One can therefore use an unsigned 8-bit variable and simply
|
||||||
|
add or subtract, allowing it to overflow/underflow and it
|
||||||
|
still does the expected contiguous thing.
|
||||||
|
@return Sine result, 0 to 255, or -128 to +127 if type-converted to
|
||||||
|
a signed int8_t, but you'll most likely want unsigned as this
|
||||||
|
output is often used for pixel brightness in animation effects.
|
||||||
|
*/
|
||||||
|
static uint8_t sine8(uint8_t x) {
|
||||||
|
return pgm_read_byte(&_NeoPixelSineTable[x]); // 0-255 in, 0-255 out
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief An 8-bit gamma-correction function for basic pixel brightness
|
||||||
|
adjustment. Makes color transitions appear more perceptially
|
||||||
|
correct.
|
||||||
|
@param x Input brightness, 0 (minimum or off/black) to 255 (maximum).
|
||||||
|
@return Gamma-adjusted brightness, can then be passed to one of the
|
||||||
|
setPixelColor() functions. This uses a fixed gamma correction
|
||||||
|
exponent of 2.6, which seems reasonably okay for average
|
||||||
|
NeoPixels in average tasks. If you need finer control you'll
|
||||||
|
need to provide your own gamma-correction function instead.
|
||||||
|
*/
|
||||||
|
static uint8_t gamma8(uint8_t x) {
|
||||||
|
return pgm_read_byte(&_NeoPixelGammaTable[x]); // 0-255 in, 0-255 out
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief Convert separate red, green and blue values into a single
|
||||||
|
"packed" 32-bit RGB color.
|
||||||
|
@param r Red brightness, 0 to 255.
|
||||||
|
@param g Green brightness, 0 to 255.
|
||||||
|
@param b Blue brightness, 0 to 255.
|
||||||
|
@return 32-bit packed RGB value, which can then be assigned to a
|
||||||
|
variable for later use or passed to the setPixelColor()
|
||||||
|
function. Packed RGB format is predictable, regardless of
|
||||||
|
LED strand color order.
|
||||||
|
*/
|
||||||
|
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief Convert separate red, green, blue and white values into a
|
||||||
|
single "packed" 32-bit WRGB color.
|
||||||
|
@param r Red brightness, 0 to 255.
|
||||||
|
@param g Green brightness, 0 to 255.
|
||||||
|
@param b Blue brightness, 0 to 255.
|
||||||
|
@param w White brightness, 0 to 255.
|
||||||
|
@return 32-bit packed WRGB value, which can then be assigned to a
|
||||||
|
variable for later use or passed to the setPixelColor()
|
||||||
|
function. Packed WRGB format is predictable, regardless of
|
||||||
|
LED strand color order.
|
||||||
|
*/
|
||||||
|
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||||
|
return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||||
|
}
|
||||||
|
static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255);
|
||||||
|
/*!
|
||||||
|
@brief A gamma-correction function for 32-bit packed RGB or WRGB
|
||||||
|
colors. Makes color transitions appear more perceptially
|
||||||
|
correct.
|
||||||
|
@param x 32-bit packed RGB or WRGB color.
|
||||||
|
@return Gamma-adjusted packed color, can then be passed in one of the
|
||||||
|
setPixelColor() functions. Like gamma8(), this uses a fixed
|
||||||
|
gamma correction exponent of 2.6, which seems reasonably okay
|
||||||
|
for average NeoPixels in average tasks. If you need finer
|
||||||
|
control you'll need to provide your own gamma-correction
|
||||||
|
function instead.
|
||||||
|
*/
|
||||||
|
static uint32_t gamma32(uint32_t x);
|
||||||
|
|
||||||
|
void rainbow(uint16_t first_hue = 0, int8_t reps = 1,
|
||||||
|
uint8_t saturation = 255, uint8_t brightness = 255,
|
||||||
|
bool gammify = true);
|
||||||
|
|
||||||
|
static neoPixelType str2order(const char *v);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if defined(ARDUINO_ARCH_RP2040)
|
||||||
|
void rp2040Init(uint8_t pin, bool is800KHz);
|
||||||
|
void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
#ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled...
|
||||||
|
bool is800KHz; ///< true if 800 KHz pixels
|
||||||
|
#endif
|
||||||
|
bool begun; ///< true if begin() previously called
|
||||||
|
uint16_t numLEDs; ///< Number of RGB LEDs in strip
|
||||||
|
uint16_t numBytes; ///< Size of 'pixels' buffer below
|
||||||
|
int16_t pin; ///< Output pin number (-1 if not yet set)
|
||||||
|
uint8_t brightness; ///< Strip brightness 0-255 (stored as +1)
|
||||||
|
uint8_t *pixels; ///< Holds LED color values (3 or 4 bytes each)
|
||||||
|
uint8_t rOffset; ///< Red index within each 3- or 4-byte pixel
|
||||||
|
uint8_t gOffset; ///< Index of green byte
|
||||||
|
uint8_t bOffset; ///< Index of blue byte
|
||||||
|
uint8_t wOffset; ///< Index of white (==rOffset if no white)
|
||||||
|
uint32_t endTime; ///< Latch timing reference
|
||||||
|
#ifdef __AVR__
|
||||||
|
volatile uint8_t *port; ///< Output PORT register
|
||||||
|
uint8_t pinMask; ///< Output PORT bitmask
|
||||||
|
#endif
|
||||||
|
#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32)
|
||||||
|
GPIO_TypeDef *gpioPort; ///< Output GPIO PORT
|
||||||
|
uint32_t gpioPin; ///< Output GPIO PIN
|
||||||
|
#endif
|
||||||
|
#if defined(ARDUINO_ARCH_RP2040)
|
||||||
|
PIO pio = pio0;
|
||||||
|
int sm = 0;
|
||||||
|
bool init = true;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADAFRUIT_NEOPIXEL_H
|
||||||
3
components/AdafruitNeoPixel/CMakeLists.txt
Normal file
3
components/AdafruitNeoPixel/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(SRCS "Adafruit_NeoPixel.cpp" esp.c
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES arduino)
|
||||||
13
components/AdafruitNeoPixel/CONTRIBUTING.md
Executable file
13
components/AdafruitNeoPixel/CONTRIBUTING.md
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
# Contribution Guidelines
|
||||||
|
|
||||||
|
This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/adafruit/Adafruit_NeoPixel/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community.
|
||||||
|
|
||||||
|
The following are some guidelines to observe when creating issues or PRs:
|
||||||
|
|
||||||
|
- Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas
|
||||||
|
|
||||||
|
- [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets
|
||||||
|
|
||||||
|
- Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile:
|
||||||
|
|
||||||
|
- Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library
|
||||||
165
components/AdafruitNeoPixel/COPYING
Executable file
165
components/AdafruitNeoPixel/COPYING
Executable file
@ -0,0 +1,165 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
|
0. Additional Definitions.
|
||||||
|
|
||||||
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
|
General Public License.
|
||||||
|
|
||||||
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
||||||
158
components/AdafruitNeoPixel/README.md
Executable file
158
components/AdafruitNeoPixel/README.md
Executable file
@ -0,0 +1,158 @@
|
|||||||
|
# Adafruit NeoPixel Library [](https://github.com/adafruit/Adafruit_NeoPixel/actions)[](http://adafruit.github.io/Adafruit_NeoPixel/html/index.html)
|
||||||
|
|
||||||
|
Arduino library for controlling single-wire-based LED pixels and strip such as the [Adafruit 60 LED/meter Digital LED strip][strip], the [Adafruit FLORA RGB Smart Pixel][flora], the [Adafruit Breadboard-friendly RGB Smart Pixel][pixel], the [Adafruit NeoPixel Stick][stick], and the [Adafruit NeoPixel Shield][shield].
|
||||||
|
|
||||||
|
After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch.
|
||||||
|
|
||||||
|
Compatibility notes: Port A is not supported on any AVR processors at this time
|
||||||
|
|
||||||
|
[flora]: http://adafruit.com/products/1060
|
||||||
|
[strip]: http://adafruit.com/products/1138
|
||||||
|
[pixel]: http://adafruit.com/products/1312
|
||||||
|
[stick]: http://adafruit.com/products/1426
|
||||||
|
[shield]: http://adafruit.com/products/1430
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### First Method
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
|
||||||
|
1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
|
||||||
|
1. Then search for Neopixel strip using the search bar.
|
||||||
|
1. Click on the text area and then select the specific version and install it.
|
||||||
|
|
||||||
|
### Second Method
|
||||||
|
|
||||||
|
1. Navigate to the [Releases page](https://github.com/adafruit/Adafruit_NeoPixel/releases).
|
||||||
|
1. Download the latest release.
|
||||||
|
1. Extract the zip file
|
||||||
|
1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- ### Simple to use
|
||||||
|
|
||||||
|
Controlling NeoPixels “from scratch” is quite a challenge, so we provide a library letting you focus on the fun and interesting bits.
|
||||||
|
|
||||||
|
- ### Give back
|
||||||
|
|
||||||
|
The library is free; you don’t have to pay for anything. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
|
||||||
|
|
||||||
|
- ### Supported Chipsets
|
||||||
|
|
||||||
|
We have included code for the following chips - sometimes these break for exciting reasons that we can't control in which case please open an issue!
|
||||||
|
|
||||||
|
- AVR ATmega and ATtiny (any 8-bit) - 8 MHz, 12 MHz and 16 MHz
|
||||||
|
- Teensy 3.x and LC
|
||||||
|
- Arduino Due
|
||||||
|
- Arduino 101
|
||||||
|
- ATSAMD21 (Arduino Zero/M0 and other SAMD21 boards) @ 48 MHz
|
||||||
|
- ATSAMD51 @ 120 MHz
|
||||||
|
- Adafruit STM32 Feather @ 120 MHz
|
||||||
|
- ESP8266 any speed
|
||||||
|
- ESP32 any speed
|
||||||
|
- Nordic nRF52 (Adafruit Feather nRF52), nRF51 (micro:bit)
|
||||||
|
- Infineon XMC1100 BootKit @ 32 MHz
|
||||||
|
- Infineon XMC1100 2Go @ 32 MHz
|
||||||
|
- Infineon XMC1300 BootKit @ 32 MHz
|
||||||
|
- Infineon XMC4700 RelaxKit, XMC4800 RelaxKit, XMC4800 IoT Amazon FreeRTOS Kit @ 144 MHz
|
||||||
|
|
||||||
|
Check forks for other architectures not listed here!
|
||||||
|
|
||||||
|
- ### GNU Lesser General Public License
|
||||||
|
|
||||||
|
Adafruit_NeoPixel is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
- begin()
|
||||||
|
- updateLength()
|
||||||
|
- updateType()
|
||||||
|
- show()
|
||||||
|
- delay_ns()
|
||||||
|
- setPin()
|
||||||
|
- setPixelColor()
|
||||||
|
- fill()
|
||||||
|
- ColorHSV()
|
||||||
|
- getPixelColor()
|
||||||
|
- setBrightness()
|
||||||
|
- getBrightness()
|
||||||
|
- clear()
|
||||||
|
- gamma32()
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
There are many examples implemented in this library. One of the examples is below. You can find other examples [here](https://github.com/adafruit/Adafruit_NeoPixel/tree/master/examples)
|
||||||
|
|
||||||
|
### Simple
|
||||||
|
|
||||||
|
```Cpp
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h>
|
||||||
|
#endif
|
||||||
|
#define PIN 6
|
||||||
|
#define NUMPIXELS 16
|
||||||
|
|
||||||
|
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
#define DELAYVAL 500
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pixels.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
pixels.clear();
|
||||||
|
|
||||||
|
for(int i=0; i<NUMPIXELS; i++) {
|
||||||
|
|
||||||
|
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
|
||||||
|
pixels.show();
|
||||||
|
delay(DELAYVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
If you want to contribute to this project:
|
||||||
|
|
||||||
|
- Report bugs and errors
|
||||||
|
- Ask for enhancements
|
||||||
|
- Create issues and pull requests
|
||||||
|
- Tell others about this library
|
||||||
|
- Contribute new protocols
|
||||||
|
|
||||||
|
Please read [CONTRIBUTING.md](https://github.com/adafruit/Adafruit_NeoPixel/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
||||||
|
|
||||||
|
### Roadmap
|
||||||
|
|
||||||
|
The PRIME DIRECTIVE is to maintain backward compatibility with existing Arduino sketches -- many are hosted elsewhere and don't track changes here, some are in print and can never be changed!
|
||||||
|
|
||||||
|
Please don't reformat code for the sake of reformatting code. The resulting large "visual diff" makes it impossible to untangle actual bug fixes from merely rearranged lines. Also, don't bother with PRs for timing adjustments "to better match the datasheet," because the datasheet isn't really true to begin with.
|
||||||
|
|
||||||
|
Things I'd Like To Do But There's No Official Timeline So Please Don't Count On Any Of This Ever Being Canonical:
|
||||||
|
|
||||||
|
- 400 KHz support can be removed, turns out it was never actually necessary; even the earliest NeoPixels can ingest 800 KHz data. Of course the #defines should remain so old sketches still compile, but both can be set to 0 and would have no effect on anything.
|
||||||
|
- For the show() function (with all the delicate pixel timing stuff), break out each architecture into separate source files rather than the current unmaintainable tangle of #ifdef statements!
|
||||||
|
- Please don't use updateLength() or updateType() in new code. They should not have been implemented this way (use the C++ 'new' operator with the regular constructor instead) and are only sticking around because of the Prime Directive. setPin() is OK for now though, it's a trick we can use to 'recycle' pixel memory across multiple strips.
|
||||||
|
- In the M0 and M4 code, use the hardware systick counter for bit timing rather than hand-tweaked NOPs (a temporary kludge at the time because I wasn't reading systick correctly). (As of 1.4.2, systick is used on M4 devices and it appears to be overclock-compatible. Not for M0 yet, which is why this item is still here.)
|
||||||
|
- As currently written, brightness scaling is still a "destructive" operation -- pixel values are altered in RAM and the original value as set can't be accurately read back, only approximated, which has been confusing and frustrating to users. It was done this way at the time because NeoPixel timing is strict, AVR microcontrollers (all we had at the time) are limited, and assembly language is hard. All the 32-bit architectures should have no problem handling nondestructive brightness scaling -- calculating each byte immediately before it's sent out the wire, maintaining the original set value in RAM -- the work just hasn't been done. There's a fair chance even the AVR code could manage it with some intense focus. (The DotStar library achieves nondestructive brightness scaling because it doesn't have to manage data timing so carefully...every architecture, even ATtiny, just takes whatever cycles it needs for the multiply/shift operations.)
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
This library is written by Phil "Paint Your Dragon" Burgess for Adafruit Industries, with contributions by PJRC, Michael Miller and other members of the open source community.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Adafruit_NeoPixel is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
Adafruit_NeoPixel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.en.html) for more details.
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see [this](https://www.gnu.org/licenses/)
|
||||||
224
components/AdafruitNeoPixel/esp.c
Executable file
224
components/AdafruitNeoPixel/esp.c
Executable file
@ -0,0 +1,224 @@
|
|||||||
|
// Implements the RMT peripheral on Espressif SoCs
|
||||||
|
// Copyright (c) 2020 Lucian Copeland for Adafruit Industries
|
||||||
|
|
||||||
|
/* Uses code from Espressif RGB LED Strip demo and drivers
|
||||||
|
* Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#if defined(ESP_IDF_VERSION)
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
|
||||||
|
#define HAS_ESP_IDF_4
|
||||||
|
#endif
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||||
|
#define HAS_ESP_IDF_5
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAS_ESP_IDF_5
|
||||||
|
|
||||||
|
void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
|
||||||
|
rmt_data_t led_data[numBytes * 8];
|
||||||
|
|
||||||
|
if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) {
|
||||||
|
log_e("Failed to init RMT TX mode on pin %d", pin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
for (int b=0; b < numBytes; b++) {
|
||||||
|
for (int bit=0; bit<8; bit++){
|
||||||
|
if ( pixels[b] & (1<<(7-bit)) ) {
|
||||||
|
led_data[i].level0 = 1;
|
||||||
|
led_data[i].duration0 = 8;
|
||||||
|
led_data[i].level1 = 0;
|
||||||
|
led_data[i].duration1 = 4;
|
||||||
|
} else {
|
||||||
|
led_data[i].level0 = 1;
|
||||||
|
led_data[i].duration0 = 4;
|
||||||
|
led_data[i].level1 = 0;
|
||||||
|
led_data[i].duration1 = 8;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//pinMode(pin, OUTPUT); // don't do this, will cause the rmt to disable!
|
||||||
|
rmtWrite(pin, led_data, numBytes * 8, RMT_WAIT_FOR_EVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "driver/rmt.h"
|
||||||
|
|
||||||
|
|
||||||
|
// This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered
|
||||||
|
// to work with the Arduino version of the ESP-IDF (3.2)
|
||||||
|
|
||||||
|
#define WS2812_T0H_NS (400)
|
||||||
|
#define WS2812_T0L_NS (850)
|
||||||
|
#define WS2812_T1H_NS (800)
|
||||||
|
#define WS2812_T1L_NS (450)
|
||||||
|
|
||||||
|
#define WS2811_T0H_NS (500)
|
||||||
|
#define WS2811_T0L_NS (2000)
|
||||||
|
#define WS2811_T1H_NS (1200)
|
||||||
|
#define WS2811_T1L_NS (1300)
|
||||||
|
|
||||||
|
static uint32_t t0h_ticks = 0;
|
||||||
|
static uint32_t t1h_ticks = 0;
|
||||||
|
static uint32_t t0l_ticks = 0;
|
||||||
|
static uint32_t t1l_ticks = 0;
|
||||||
|
|
||||||
|
// Limit the number of RMT channels available for the Neopixels. Defaults to all
|
||||||
|
// channels (8 on ESP32, 4 on ESP32-S2 and S3). Redefining this value will free
|
||||||
|
// any channels with a higher number for other uses, such as IR send-and-recieve
|
||||||
|
// libraries. Redefine as 1 to restrict Neopixels to only a single channel.
|
||||||
|
#define ADAFRUIT_RMT_CHANNEL_MAX RMT_CHANNEL_MAX
|
||||||
|
|
||||||
|
#define RMT_LL_HW_BASE (&RMT)
|
||||||
|
|
||||||
|
bool rmt_reserved_channels[ADAFRUIT_RMT_CHANNEL_MAX];
|
||||||
|
|
||||||
|
static void IRAM_ATTR ws2812_rmt_adapter(const void *src, rmt_item32_t *dest, size_t src_size,
|
||||||
|
size_t wanted_num, size_t *translated_size, size_t *item_num)
|
||||||
|
{
|
||||||
|
if (src == NULL || dest == NULL) {
|
||||||
|
*translated_size = 0;
|
||||||
|
*item_num = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const rmt_item32_t bit0 = {{{ t0h_ticks, 1, t0l_ticks, 0 }}}; //Logical 0
|
||||||
|
const rmt_item32_t bit1 = {{{ t1h_ticks, 1, t1l_ticks, 0 }}}; //Logical 1
|
||||||
|
size_t size = 0;
|
||||||
|
size_t num = 0;
|
||||||
|
uint8_t *psrc = (uint8_t *)src;
|
||||||
|
rmt_item32_t *pdest = dest;
|
||||||
|
while (size < src_size && num < wanted_num) {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
// MSB first
|
||||||
|
if (*psrc & (1 << (7 - i))) {
|
||||||
|
pdest->val = bit1.val;
|
||||||
|
} else {
|
||||||
|
pdest->val = bit0.val;
|
||||||
|
}
|
||||||
|
num++;
|
||||||
|
pdest++;
|
||||||
|
}
|
||||||
|
size++;
|
||||||
|
psrc++;
|
||||||
|
}
|
||||||
|
*translated_size = size;
|
||||||
|
*item_num = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
|
||||||
|
// Reserve channel
|
||||||
|
rmt_channel_t channel = ADAFRUIT_RMT_CHANNEL_MAX;
|
||||||
|
for (size_t i = 0; i < ADAFRUIT_RMT_CHANNEL_MAX; i++) {
|
||||||
|
if (!rmt_reserved_channels[i]) {
|
||||||
|
rmt_reserved_channels[i] = true;
|
||||||
|
channel = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (channel == ADAFRUIT_RMT_CHANNEL_MAX) {
|
||||||
|
// Ran out of channels!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(HAS_ESP_IDF_4)
|
||||||
|
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin, channel);
|
||||||
|
config.clk_div = 2;
|
||||||
|
#else
|
||||||
|
// Match default TX config from ESP-IDF version 3.4
|
||||||
|
rmt_config_t config = {
|
||||||
|
.rmt_mode = RMT_MODE_TX,
|
||||||
|
.channel = channel,
|
||||||
|
.gpio_num = pin,
|
||||||
|
.clk_div = 2,
|
||||||
|
.mem_block_num = 1,
|
||||||
|
.tx_config = {
|
||||||
|
.carrier_freq_hz = 38000,
|
||||||
|
.carrier_level = RMT_CARRIER_LEVEL_HIGH,
|
||||||
|
.idle_level = RMT_IDLE_LEVEL_LOW,
|
||||||
|
.carrier_duty_percent = 33,
|
||||||
|
.carrier_en = false,
|
||||||
|
.loop_en = false,
|
||||||
|
.idle_output_en = true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
rmt_config(&config);
|
||||||
|
rmt_driver_install(config.channel, 0, 0);
|
||||||
|
|
||||||
|
// Convert NS timings to ticks
|
||||||
|
uint32_t counter_clk_hz = 0;
|
||||||
|
|
||||||
|
#if defined(HAS_ESP_IDF_4)
|
||||||
|
rmt_get_counter_clock(channel, &counter_clk_hz);
|
||||||
|
#else
|
||||||
|
// this emulates the rmt_get_counter_clock() function from ESP-IDF 3.4
|
||||||
|
if (RMT_LL_HW_BASE->conf_ch[config.channel].conf1.ref_always_on == RMT_BASECLK_REF) {
|
||||||
|
uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt;
|
||||||
|
uint32_t div = div_cnt == 0 ? 256 : div_cnt;
|
||||||
|
counter_clk_hz = REF_CLK_FREQ / (div);
|
||||||
|
} else {
|
||||||
|
uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt;
|
||||||
|
uint32_t div = div_cnt == 0 ? 256 : div_cnt;
|
||||||
|
counter_clk_hz = APB_CLK_FREQ / (div);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// NS to tick converter
|
||||||
|
float ratio = (float)counter_clk_hz / 1e9;
|
||||||
|
|
||||||
|
if (is800KHz) {
|
||||||
|
t0h_ticks = (uint32_t)(ratio * WS2812_T0H_NS);
|
||||||
|
t0l_ticks = (uint32_t)(ratio * WS2812_T0L_NS);
|
||||||
|
t1h_ticks = (uint32_t)(ratio * WS2812_T1H_NS);
|
||||||
|
t1l_ticks = (uint32_t)(ratio * WS2812_T1L_NS);
|
||||||
|
} else {
|
||||||
|
t0h_ticks = (uint32_t)(ratio * WS2811_T0H_NS);
|
||||||
|
t0l_ticks = (uint32_t)(ratio * WS2811_T0L_NS);
|
||||||
|
t1h_ticks = (uint32_t)(ratio * WS2811_T1H_NS);
|
||||||
|
t1l_ticks = (uint32_t)(ratio * WS2811_T1L_NS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize automatic timing translator
|
||||||
|
rmt_translator_init(config.channel, ws2812_rmt_adapter);
|
||||||
|
|
||||||
|
// Write and wait to finish
|
||||||
|
rmt_write_sample(config.channel, pixels, (size_t)numBytes, true);
|
||||||
|
rmt_wait_tx_done(config.channel, pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
|
// Free channel again
|
||||||
|
rmt_driver_uninstall(config.channel);
|
||||||
|
rmt_reserved_channels[channel] = false;
|
||||||
|
|
||||||
|
gpio_set_direction(pin, GPIO_MODE_OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ifndef IDF5
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ifdef(ESP32)
|
||||||
86
components/AdafruitNeoPixel/esp8266.c
Executable file
86
components/AdafruitNeoPixel/esp8266.c
Executable file
@ -0,0 +1,86 @@
|
|||||||
|
// This is a mash-up of the Due show() code + insights from Michael Miller's
|
||||||
|
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
|
||||||
|
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#ifdef ESP8266
|
||||||
|
#include <eagle_soc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint32_t _getCycleCount(void) __attribute__((always_inline));
|
||||||
|
static inline uint32_t _getCycleCount(void) {
|
||||||
|
uint32_t ccount;
|
||||||
|
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
|
||||||
|
return ccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
IRAM_ATTR void espShow(
|
||||||
|
uint8_t pin, uint8_t *pixels, uint32_t numBytes, __attribute__((unused)) boolean is800KHz) {
|
||||||
|
#else
|
||||||
|
void espShow(
|
||||||
|
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CYCLES_800_T0H (F_CPU / 2500001) // 0.4us
|
||||||
|
#define CYCLES_800_T1H (F_CPU / 1250001) // 0.8us
|
||||||
|
#define CYCLES_800 (F_CPU / 800001) // 1.25us per bit
|
||||||
|
#define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS
|
||||||
|
#define CYCLES_400_T1H (F_CPU / 833333) // 1.2us
|
||||||
|
#define CYCLES_400 (F_CPU / 400000) // 2.5us per bit
|
||||||
|
|
||||||
|
uint8_t *p, *end, pix, mask;
|
||||||
|
uint32_t t, time0, time1, period, c, startTime;
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
uint32_t pinMask;
|
||||||
|
pinMask = _BV(pin);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
p = pixels;
|
||||||
|
end = p + numBytes;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
startTime = 0;
|
||||||
|
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
if(is800KHz) {
|
||||||
|
#endif
|
||||||
|
time0 = CYCLES_800_T0H;
|
||||||
|
time1 = CYCLES_800_T1H;
|
||||||
|
period = CYCLES_800;
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
} else { // 400 KHz bitstream
|
||||||
|
time0 = CYCLES_400_T0H;
|
||||||
|
time1 = CYCLES_400_T1H;
|
||||||
|
period = CYCLES_400;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for(t = time0;; t = time0) {
|
||||||
|
if(pix & mask) t = time1; // Bit high duration
|
||||||
|
while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start
|
||||||
|
#ifdef ESP8266
|
||||||
|
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
|
||||||
|
#else
|
||||||
|
gpio_set_level(pin, HIGH);
|
||||||
|
#endif
|
||||||
|
startTime = c; // Save start time
|
||||||
|
while(((c = _getCycleCount()) - startTime) < t); // Wait high duration
|
||||||
|
#ifdef ESP8266
|
||||||
|
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
|
||||||
|
#else
|
||||||
|
gpio_set_level(pin, LOW);
|
||||||
|
#endif
|
||||||
|
if(!(mask >>= 1)) { // Next bit/byte
|
||||||
|
if(p >= end) break;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while((_getCycleCount() - startTime) < period); // Wait for last bit
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ESP8266
|
||||||
BIN
components/AdafruitNeoPixel/examples/.DS_Store
vendored
Executable file
BIN
components/AdafruitNeoPixel/examples/.DS_Store
vendored
Executable file
Binary file not shown.
177
components/AdafruitNeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino
Executable file
177
components/AdafruitNeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino
Executable file
@ -0,0 +1,177 @@
|
|||||||
|
// NeoPixel test program showing use of the WHITE channel for RGBW
|
||||||
|
// pixels only (won't look correct on regular RGB NeoPixel strips).
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
// On a Trinket or Gemma we suggest changing this to 1:
|
||||||
|
#define LED_PIN 6
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define LED_COUNT 60
|
||||||
|
|
||||||
|
// NeoPixel brightness, 0 (min) to 255 (max)
|
||||||
|
#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255)
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
strip.setBrightness(BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Fill along the length of the strip in various colors...
|
||||||
|
colorWipe(strip.Color(255, 0, 0) , 50); // Red
|
||||||
|
colorWipe(strip.Color( 0, 255, 0) , 50); // Green
|
||||||
|
colorWipe(strip.Color( 0, 0, 255) , 50); // Blue
|
||||||
|
colorWipe(strip.Color( 0, 0, 0, 255), 50); // True white (not RGB white)
|
||||||
|
|
||||||
|
whiteOverRainbow(75, 5);
|
||||||
|
|
||||||
|
pulseWhite(5);
|
||||||
|
|
||||||
|
rainbowFade2White(3, 3, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void whiteOverRainbow(int whiteSpeed, int whiteLength) {
|
||||||
|
|
||||||
|
if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
|
||||||
|
|
||||||
|
int head = whiteLength - 1;
|
||||||
|
int tail = 0;
|
||||||
|
int loops = 3;
|
||||||
|
int loopNum = 0;
|
||||||
|
uint32_t lastTime = millis();
|
||||||
|
uint32_t firstPixelHue = 0;
|
||||||
|
|
||||||
|
for(;;) { // Repeat forever (or until a 'break' or 'return')
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
if(((i >= tail) && (i <= head)) || // If between head & tail...
|
||||||
|
((tail > head) && ((i >= tail) || (i <= head)))) {
|
||||||
|
strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
|
||||||
|
} else { // else set rainbow
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
// There's no delay here, it just runs full-tilt until the timer and
|
||||||
|
// counter combination below runs out.
|
||||||
|
|
||||||
|
firstPixelHue += 40; // Advance just a little along the color wheel
|
||||||
|
|
||||||
|
if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
|
||||||
|
if(++head >= strip.numPixels()) { // Advance head, wrap around
|
||||||
|
head = 0;
|
||||||
|
if(++loopNum >= loops) return;
|
||||||
|
}
|
||||||
|
if(++tail >= strip.numPixels()) { // Advance tail, wrap around
|
||||||
|
tail = 0;
|
||||||
|
}
|
||||||
|
lastTime = millis(); // Save time of last movement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pulseWhite(uint8_t wait) {
|
||||||
|
for(int j=0; j<256; j++) { // Ramp up from 0 to 255
|
||||||
|
// Fill entire strip with white at gamma-corrected brightness level 'j':
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
|
||||||
|
int fadeVal=0, fadeMax=100;
|
||||||
|
|
||||||
|
// Hue of first pixel runs 'rainbowLoops' complete loops through the color
|
||||||
|
// wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to rainbowLoops*65536, using steps of 256 so we
|
||||||
|
// advance around the wheel at a decent clip.
|
||||||
|
for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
|
||||||
|
firstPixelHue += 256) {
|
||||||
|
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the three-argument variant, though the
|
||||||
|
// second value (saturation) is a constant 255.
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
|
||||||
|
255 * fadeVal / fadeMax)));
|
||||||
|
}
|
||||||
|
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
|
||||||
|
if(firstPixelHue < 65536) { // First loop,
|
||||||
|
if(fadeVal < fadeMax) fadeVal++; // fade in
|
||||||
|
} else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
|
||||||
|
if(fadeVal > 0) fadeVal--; // fade out
|
||||||
|
} else {
|
||||||
|
fadeVal = fadeMax; // Interim loop, make sure fade is at max
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int k=0; k<whiteLoops; k++) {
|
||||||
|
for(int j=0; j<256; j++) { // Ramp up 0 to 255
|
||||||
|
// Fill entire strip with white at gamma-corrected brightness level 'j':
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
}
|
||||||
|
delay(1000); // Pause 1 second
|
||||||
|
for(int j=255; j>=0; j--) { // Ramp down 255 to 0
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(500); // Pause 1/2 second
|
||||||
|
}
|
||||||
@ -0,0 +1,231 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example is based on StrandtestBLE example and adapts it to use
|
||||||
|
* the new ArduinoBLE library.
|
||||||
|
*
|
||||||
|
* https://github.com/arduino-libraries/ArduinoBLE
|
||||||
|
*
|
||||||
|
* Supported boards:
|
||||||
|
* Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
|
||||||
|
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
|
||||||
|
*
|
||||||
|
* You can use a generic BLE central app, like LightBlue (iOS and Android) or
|
||||||
|
* nRF Connect (Android), to interact with the services and characteristics
|
||||||
|
* created in this sketch.
|
||||||
|
*
|
||||||
|
* This example code is in the public domain.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
#include <ArduinoBLE.h>
|
||||||
|
|
||||||
|
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
|
||||||
|
|
||||||
|
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
|
||||||
|
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
// begin initialization
|
||||||
|
if (!BLE.begin())
|
||||||
|
{
|
||||||
|
Serial.println("starting BLE failed!");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Peripheral address: ");
|
||||||
|
Serial.println(BLE.address());
|
||||||
|
|
||||||
|
// set advertised local name and service UUID:
|
||||||
|
BLE.setLocalName("LED");
|
||||||
|
BLE.setAdvertisedService(ledService);
|
||||||
|
|
||||||
|
// add the characteristic to the service
|
||||||
|
ledService.addCharacteristic(switchCharacteristic);
|
||||||
|
|
||||||
|
// add service
|
||||||
|
BLE.addService(ledService);
|
||||||
|
|
||||||
|
// set the initial value for the characeristic:
|
||||||
|
switchCharacteristic.writeValue(0);
|
||||||
|
|
||||||
|
// start advertising
|
||||||
|
BLE.advertise();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
pinMode(PIN, OUTPUT);
|
||||||
|
digitalWrite(PIN, LOW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
BLEDevice central = BLE.central();
|
||||||
|
|
||||||
|
// if a central is connected to peripheral:
|
||||||
|
if (central)
|
||||||
|
{
|
||||||
|
Serial.print("Connected to central: ");
|
||||||
|
// print the central's MAC address:
|
||||||
|
Serial.println(central.address());
|
||||||
|
|
||||||
|
// while the central is still connected to peripheral:
|
||||||
|
while (central.connected())
|
||||||
|
{
|
||||||
|
// if the remote device wrote to the characteristic,
|
||||||
|
// use the value to control the LED:
|
||||||
|
if (switchCharacteristic.written())
|
||||||
|
{
|
||||||
|
switch (switchCharacteristic.value())
|
||||||
|
{
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int a = 0; a < 10; a++)
|
||||||
|
{ // Repeat 10 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait)
|
||||||
|
{
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
|
||||||
|
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait)
|
||||||
|
{
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for (int a = 0; a < 30; a++)
|
||||||
|
{ // Repeat 30 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,239 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example is based on StrandtestArduinoBLE example to make use of
|
||||||
|
* callbacks features of the ArduinoBLE library.
|
||||||
|
*
|
||||||
|
* https://github.com/arduino-libraries/ArduinoBLE
|
||||||
|
*
|
||||||
|
* Supported boards:
|
||||||
|
* Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
|
||||||
|
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
|
||||||
|
*
|
||||||
|
* You can use a generic BLE central app, like LightBlue (iOS and Android) or
|
||||||
|
* nRF Connect (Android), to interact with the services and characteristics
|
||||||
|
* created in this sketch.
|
||||||
|
*
|
||||||
|
* This example code is in the public domain.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
#include <ArduinoBLE.h>
|
||||||
|
|
||||||
|
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
|
||||||
|
|
||||||
|
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
|
||||||
|
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
// begin initialization
|
||||||
|
if (!BLE.begin())
|
||||||
|
{
|
||||||
|
Serial.println("starting BLE failed!");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Peripheral address: ");
|
||||||
|
Serial.println(BLE.address());
|
||||||
|
|
||||||
|
// set advertised local name and service UUID:
|
||||||
|
BLE.setLocalName("LEDCallback");
|
||||||
|
BLE.setAdvertisedService(ledService);
|
||||||
|
|
||||||
|
// add the characteristic to the service
|
||||||
|
ledService.addCharacteristic(switchCharacteristic);
|
||||||
|
|
||||||
|
// add service
|
||||||
|
BLE.addService(ledService);
|
||||||
|
// assign event handlers for connected, disconnected to peripheral
|
||||||
|
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
|
||||||
|
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
|
||||||
|
|
||||||
|
// assign event handlers for characteristic
|
||||||
|
switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
|
||||||
|
// set the initial value for the characeristic:
|
||||||
|
switchCharacteristic.writeValue(0);
|
||||||
|
|
||||||
|
// start advertising
|
||||||
|
BLE.advertise();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
pinMode(PIN, OUTPUT);
|
||||||
|
digitalWrite(PIN, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// poll for BLE events
|
||||||
|
BLE.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
void blePeripheralConnectHandler(BLEDevice central)
|
||||||
|
{
|
||||||
|
// central connected event handler
|
||||||
|
Serial.print("Connected event, central: ");
|
||||||
|
Serial.println(central.address());
|
||||||
|
}
|
||||||
|
|
||||||
|
void blePeripheralDisconnectHandler(BLEDevice central)
|
||||||
|
{
|
||||||
|
// central disconnected event handler
|
||||||
|
Serial.print("Disconnected event, central: ");
|
||||||
|
Serial.println(central.address());
|
||||||
|
}
|
||||||
|
|
||||||
|
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic)
|
||||||
|
{
|
||||||
|
// central wrote new value to characteristic, update LED
|
||||||
|
Serial.print("Characteristic event, written: ");
|
||||||
|
|
||||||
|
switch (switchCharacteristic.value())
|
||||||
|
{
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int a = 0; a < 10; a++)
|
||||||
|
{ // Repeat 10 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait)
|
||||||
|
{
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
|
||||||
|
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait)
|
||||||
|
{
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for (int a = 0; a < 30; a++)
|
||||||
|
{ // Repeat 30 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
0
components/AdafruitNeoPixel/examples/StrandtestBLE/.none.test.only
Executable file
0
components/AdafruitNeoPixel/examples/StrandtestBLE/.none.test.only
Executable file
133
components/AdafruitNeoPixel/examples/StrandtestBLE/BLESerial.cpp
Executable file
133
components/AdafruitNeoPixel/examples/StrandtestBLE/BLESerial.cpp
Executable file
@ -0,0 +1,133 @@
|
|||||||
|
#include "BLESerial.h"
|
||||||
|
|
||||||
|
// #define BLE_SERIAL_DEBUG
|
||||||
|
|
||||||
|
BLESerial* BLESerial::_instance = NULL;
|
||||||
|
|
||||||
|
BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) :
|
||||||
|
BLEPeripheral(req, rdy, rst)
|
||||||
|
{
|
||||||
|
this->_txCount = 0;
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
this->_flushed = 0;
|
||||||
|
BLESerial::_instance = this;
|
||||||
|
|
||||||
|
addAttribute(this->_uartService);
|
||||||
|
addAttribute(this->_uartNameDescriptor);
|
||||||
|
setAdvertisedServiceUuid(this->_uartService.uuid());
|
||||||
|
addAttribute(this->_rxCharacteristic);
|
||||||
|
addAttribute(this->_rxNameDescriptor);
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received);
|
||||||
|
addAttribute(this->_txCharacteristic);
|
||||||
|
addAttribute(this->_txNameDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::begin(...) {
|
||||||
|
BLEPeripheral::begin();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::begin()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::poll() {
|
||||||
|
if (millis() < this->_flushed + 100) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
} else {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::end() {
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, NULL);
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
flush();
|
||||||
|
BLEPeripheral::disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::available(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer);
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::available() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::peek(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::peek() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::read(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer);
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::read() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::flush(void) {
|
||||||
|
if (this->_txCount == 0) return;
|
||||||
|
this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount);
|
||||||
|
this->_flushed = millis();
|
||||||
|
this->_txCount = 0;
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::flush()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t BLESerial::write(uint8_t byte) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_txCharacteristic.subscribed() == false) return 0;
|
||||||
|
this->_txBuffer[this->_txCount++] = byte;
|
||||||
|
if (this->_txCount == sizeof(this->_txBuffer)) flush();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::write("));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.print(byte, HEX);
|
||||||
|
Serial.println(F(") = 1"));
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BLESerial::operator bool() {
|
||||||
|
bool retval = BLEPeripheral::connected();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::operator bool() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(const uint8_t* data, size_t size) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer);
|
||||||
|
this->_rxBuffer[this->_rxHead] = data[i];
|
||||||
|
}
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::received("));
|
||||||
|
for (int i = 0; i < size; i++) Serial.print((char) data[i]);
|
||||||
|
Serial.println(F(")"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) {
|
||||||
|
BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength());
|
||||||
|
}
|
||||||
46
components/AdafruitNeoPixel/examples/StrandtestBLE/BLESerial.h
Executable file
46
components/AdafruitNeoPixel/examples/StrandtestBLE/BLESerial.h
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef _BLE_SERIAL_H_
|
||||||
|
#define _BLE_SERIAL_H_
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
|
||||||
|
class BLESerial : public BLEPeripheral, public Stream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BLESerial(unsigned char req, unsigned char rdy, unsigned char rst);
|
||||||
|
|
||||||
|
void begin(...);
|
||||||
|
void poll();
|
||||||
|
void end();
|
||||||
|
|
||||||
|
virtual int available(void);
|
||||||
|
virtual int peek(void);
|
||||||
|
virtual int read(void);
|
||||||
|
virtual void flush(void);
|
||||||
|
virtual size_t write(uint8_t byte);
|
||||||
|
using Print::write;
|
||||||
|
virtual operator bool();
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long _flushed;
|
||||||
|
static BLESerial* _instance;
|
||||||
|
|
||||||
|
size_t _rxHead;
|
||||||
|
size_t _rxTail;
|
||||||
|
size_t _rxCount() const;
|
||||||
|
uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
size_t _txCount;
|
||||||
|
uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
|
||||||
|
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
|
||||||
|
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
|
||||||
|
BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)");
|
||||||
|
BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)");
|
||||||
|
|
||||||
|
void _received(const uint8_t* data, size_t size);
|
||||||
|
static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
192
components/AdafruitNeoPixel/examples/StrandtestBLE/StrandtestBLE.ino
Executable file
192
components/AdafruitNeoPixel/examples/StrandtestBLE/StrandtestBLE.ino
Executable file
@ -0,0 +1,192 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example was developed by the Hackerspace San Salvador to demonstrate
|
||||||
|
* the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice.
|
||||||
|
* To compile this example you'll need to add support for the NRF52 based
|
||||||
|
* following the instructions at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-nRF5
|
||||||
|
* Or adding the following URL to the board manager URLs on Arduino preferences:
|
||||||
|
* https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
|
||||||
|
* Then you can install the BLEPeripheral library avaiable at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-BLEPeripheral
|
||||||
|
* To test it, compile this example and use the UART module from the nRF
|
||||||
|
* Toolbox App for Android. Edit the interface and send the characters
|
||||||
|
* 'a' to 'i' to switch the animation.
|
||||||
|
* There is a delay because this example blocks the thread of execution but
|
||||||
|
* the change will be shown after the current animation ends. (This might
|
||||||
|
* take a couple of seconds)
|
||||||
|
* For more info write us at: info _at- teubi.co
|
||||||
|
*/
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
#include "BLESerial.h"
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
// define pins (varies per shield/board)
|
||||||
|
#define BLE_REQ 10
|
||||||
|
#define BLE_RDY 2
|
||||||
|
#define BLE_RST 9
|
||||||
|
|
||||||
|
// create ble serial instance, see pinouts above
|
||||||
|
BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST);
|
||||||
|
|
||||||
|
uint8_t current_state = 0;
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
BLESerial.setLocalName("UART_HS");
|
||||||
|
BLESerial.begin();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
//pinMode(PIN, OUTPUT);
|
||||||
|
//digitalWrite(PIN, LOW);
|
||||||
|
|
||||||
|
current_state = 'a';
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
while(BLESerial.available()) {
|
||||||
|
uint8_t character = BLESerial.read();
|
||||||
|
switch(character) {
|
||||||
|
case 'a':
|
||||||
|
case 'b':
|
||||||
|
case 'c':
|
||||||
|
case 'd':
|
||||||
|
case 'e':
|
||||||
|
case 'f':
|
||||||
|
case 'g':
|
||||||
|
case 'h':
|
||||||
|
current_state = character;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
switch(current_state) {
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
for(int a=0; a<10; a++) { // Repeat 10 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait) {
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
|
||||||
|
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait) {
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for(int a=0; a<30; a++) { // Repeat 30 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
|
||||||
133
components/AdafruitNeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp
Executable file
133
components/AdafruitNeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp
Executable file
@ -0,0 +1,133 @@
|
|||||||
|
#include "BLESerial.h"
|
||||||
|
|
||||||
|
// #define BLE_SERIAL_DEBUG
|
||||||
|
|
||||||
|
BLESerial* BLESerial::_instance = NULL;
|
||||||
|
|
||||||
|
BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) :
|
||||||
|
BLEPeripheral(req, rdy, rst)
|
||||||
|
{
|
||||||
|
this->_txCount = 0;
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
this->_flushed = 0;
|
||||||
|
BLESerial::_instance = this;
|
||||||
|
|
||||||
|
addAttribute(this->_uartService);
|
||||||
|
addAttribute(this->_uartNameDescriptor);
|
||||||
|
setAdvertisedServiceUuid(this->_uartService.uuid());
|
||||||
|
addAttribute(this->_rxCharacteristic);
|
||||||
|
addAttribute(this->_rxNameDescriptor);
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received);
|
||||||
|
addAttribute(this->_txCharacteristic);
|
||||||
|
addAttribute(this->_txNameDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::begin(...) {
|
||||||
|
BLEPeripheral::begin();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::begin()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::poll() {
|
||||||
|
if (millis() < this->_flushed + 100) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
} else {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::end() {
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, NULL);
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
flush();
|
||||||
|
BLEPeripheral::disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::available(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer);
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::available() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::peek(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::peek() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::read(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer);
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::read() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::flush(void) {
|
||||||
|
if (this->_txCount == 0) return;
|
||||||
|
this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount);
|
||||||
|
this->_flushed = millis();
|
||||||
|
this->_txCount = 0;
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::flush()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t BLESerial::write(uint8_t byte) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_txCharacteristic.subscribed() == false) return 0;
|
||||||
|
this->_txBuffer[this->_txCount++] = byte;
|
||||||
|
if (this->_txCount == sizeof(this->_txBuffer)) flush();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::write("));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.print(byte, HEX);
|
||||||
|
Serial.println(F(") = 1"));
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BLESerial::operator bool() {
|
||||||
|
bool retval = BLEPeripheral::connected();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::operator bool() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(const uint8_t* data, size_t size) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer);
|
||||||
|
this->_rxBuffer[this->_rxHead] = data[i];
|
||||||
|
}
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::received("));
|
||||||
|
for (int i = 0; i < size; i++) Serial.print((char) data[i]);
|
||||||
|
Serial.println(F(")"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) {
|
||||||
|
BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength());
|
||||||
|
}
|
||||||
46
components/AdafruitNeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h
Executable file
46
components/AdafruitNeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef _BLE_SERIAL_H_
|
||||||
|
#define _BLE_SERIAL_H_
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
|
||||||
|
class BLESerial : public BLEPeripheral, public Stream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BLESerial(unsigned char req, unsigned char rdy, unsigned char rst);
|
||||||
|
|
||||||
|
void begin(...);
|
||||||
|
void poll();
|
||||||
|
void end();
|
||||||
|
|
||||||
|
virtual int available(void);
|
||||||
|
virtual int peek(void);
|
||||||
|
virtual int read(void);
|
||||||
|
virtual void flush(void);
|
||||||
|
virtual size_t write(uint8_t byte);
|
||||||
|
using Print::write;
|
||||||
|
virtual operator bool();
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long _flushed;
|
||||||
|
static BLESerial* _instance;
|
||||||
|
|
||||||
|
size_t _rxHead;
|
||||||
|
size_t _rxTail;
|
||||||
|
size_t _rxCount() const;
|
||||||
|
uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
size_t _txCount;
|
||||||
|
uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
|
||||||
|
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
|
||||||
|
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
|
||||||
|
BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)");
|
||||||
|
BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)");
|
||||||
|
|
||||||
|
void _received(const uint8_t* data, size_t size);
|
||||||
|
static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,198 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example was developed by the Hackerspace San Salvador to demonstrate
|
||||||
|
* the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice.
|
||||||
|
* To compile this example you'll need to add support for the NRF52 based
|
||||||
|
* following the instructions at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-nRF5
|
||||||
|
* Or adding the following URL to the board manager URLs on Arduino preferences:
|
||||||
|
* https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
|
||||||
|
* Then you can install the BLEPeripheral library avaiable at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-BLEPeripheral
|
||||||
|
* To test it, compile this example and use the UART module from the nRF
|
||||||
|
* Toolbox App for Android. Edit the interface and send the characters
|
||||||
|
* 'a' to 'i' to switch the animation.
|
||||||
|
* There is a no delay because this example does not block the threads execution
|
||||||
|
* so the change will be shown immediately and will not need to wait for the current
|
||||||
|
* animation to end.
|
||||||
|
* For more info write us at: info _at- teubi.co
|
||||||
|
*/
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
#include "BLESerial.h"
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
// define pins (varies per shield/board)
|
||||||
|
#define BLE_REQ 10
|
||||||
|
#define BLE_RDY 2
|
||||||
|
#define BLE_RST 9
|
||||||
|
|
||||||
|
// create ble serial instance, see pinouts above
|
||||||
|
BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST);
|
||||||
|
|
||||||
|
uint8_t current_state = 0;
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
BLESerial.setLocalName("UART_HS");
|
||||||
|
BLESerial.begin();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
//pinMode(PIN, OUTPUT);
|
||||||
|
//digitalWrite(PIN, LOW);
|
||||||
|
|
||||||
|
current_state = 'a';
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
while(BLESerial.available()) {
|
||||||
|
uint8_t character = BLESerial.read();
|
||||||
|
switch(character) {
|
||||||
|
case 'a':
|
||||||
|
case 'b':
|
||||||
|
case 'c':
|
||||||
|
case 'd':
|
||||||
|
case 'e':
|
||||||
|
case 'f':
|
||||||
|
case 'g':
|
||||||
|
case 'h':
|
||||||
|
current_state = character;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
switch(current_state) {
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some functions of our own for creating animated effects -----------------
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCurrent++; // Advance current pixel
|
||||||
|
if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED
|
||||||
|
pixelCurrent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i = 0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
for(int i=0; i < pixelNumber; i+3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current pixel
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop the pattern from the first LED
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait;
|
||||||
|
for(uint16_t i=0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop the cycle back to the begining
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights with rainbow effect
|
||||||
|
void theaterChaseRainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i=0; i < pixelNumber; i+3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
for(int i=0; i < pixelNumber; i+3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current queue
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input a value 0 to 255 to get a color value.
|
||||||
|
// The colours are a transition r - g - b - back to r.
|
||||||
|
uint32_t Wheel(byte WheelPos) {
|
||||||
|
WheelPos = 255 - WheelPos;
|
||||||
|
if(WheelPos < 85) {
|
||||||
|
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||||
|
}
|
||||||
|
if(WheelPos < 170) {
|
||||||
|
WheelPos -= 85;
|
||||||
|
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||||
|
}
|
||||||
|
WheelPos -= 170;
|
||||||
|
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||||
|
}
|
||||||
164
components/AdafruitNeoPixel/examples/buttoncycler/buttoncycler.ino
Executable file
164
components/AdafruitNeoPixel/examples/buttoncycler/buttoncycler.ino
Executable file
@ -0,0 +1,164 @@
|
|||||||
|
// Simple demonstration on using an input device to trigger changes on your
|
||||||
|
// NeoPixels. Wire a momentary push button to connect from ground to a
|
||||||
|
// digital IO pin. When the button is pressed it will change to a new pixel
|
||||||
|
// animation. Initial state has all pixels off -- press the button once to
|
||||||
|
// start the first animation. As written, the button does not interrupt an
|
||||||
|
// animation in-progress, it works only when idle.
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Digital IO pin connected to the button. This will be driven with a
|
||||||
|
// pull-up resistor so the switch pulls the pin to ground momentarily.
|
||||||
|
// On a high -> low transition the button press logic will execute.
|
||||||
|
#define BUTTON_PIN 2
|
||||||
|
|
||||||
|
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
|
||||||
|
|
||||||
|
#define PIXEL_COUNT 16 // Number of NeoPixels
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
boolean oldState = HIGH;
|
||||||
|
int mode = 0; // Currently-active animation mode, 0-9
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Initialize all pixels to 'off'
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Get current button state.
|
||||||
|
boolean newState = digitalRead(BUTTON_PIN);
|
||||||
|
|
||||||
|
// Check if state changed from high to low (button press).
|
||||||
|
if((newState == LOW) && (oldState == HIGH)) {
|
||||||
|
// Short delay to debounce button.
|
||||||
|
delay(20);
|
||||||
|
// Check if button is still low after debounce.
|
||||||
|
newState = digitalRead(BUTTON_PIN);
|
||||||
|
if(newState == LOW) { // Yes, still low
|
||||||
|
if(++mode > 8) mode = 0; // Advance to next mode, wrap around after #8
|
||||||
|
switch(mode) { // Start the new animation...
|
||||||
|
case 0:
|
||||||
|
colorWipe(strip.Color( 0, 0, 0), 50); // Black/off
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 50); // Green
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
theaterChase(strip.Color( 0, 0, 127), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
theaterChaseRainbow(50);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the last-read button state to the old state.
|
||||||
|
oldState = newState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
for(int a=0; a<10; a++) { // Repeat 10 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait) {
|
||||||
|
// Hue of first pixel runs 3 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 3*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 3*65536/256 = 768 passes through this outer loop:
|
||||||
|
for(long firstPixelHue = 0; firstPixelHue < 3*65536; firstPixelHue += 256) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait) {
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for(int a=0; a<30; a++) { // Repeat 30 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
0
components/AdafruitNeoPixel/examples/simple/.esp8266.test.skip
Executable file
0
components/AdafruitNeoPixel/examples/simple/.esp8266.test.skip
Executable file
50
components/AdafruitNeoPixel/examples/simple/simple.ino
Executable file
50
components/AdafruitNeoPixel/examples/simple/simple.ino
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
|
||||||
|
// Released under the GPLv3 license to match the rest of the
|
||||||
|
// Adafruit NeoPixel library
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define NUMPIXELS 16 // Popular NeoPixel ring size
|
||||||
|
|
||||||
|
// When setting up the NeoPixel library, we tell it how many pixels,
|
||||||
|
// and which pin to use to send signals. Note that for older NeoPixel
|
||||||
|
// strips you might need to change the third parameter -- see the
|
||||||
|
// strandtest example for more information on possible values.
|
||||||
|
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
pixels.clear(); // Set all pixel colors to 'off'
|
||||||
|
|
||||||
|
// The first NeoPixel in a strand is #0, second is 1, all the way up
|
||||||
|
// to the count of pixels minus one.
|
||||||
|
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
|
||||||
|
|
||||||
|
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
|
||||||
|
// Here we're using a moderately bright green color:
|
||||||
|
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
|
||||||
|
|
||||||
|
pixels.show(); // Send the updated pixel colors to the hardware.
|
||||||
|
|
||||||
|
delay(DELAYVAL); // Pause before next pass through loop
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
|
||||||
|
// Released under the GPLv3 license to match the rest of the
|
||||||
|
// Adafruit NeoPixel library
|
||||||
|
// This sketch shows use of the "new" operator with Adafruit_NeoPixel.
|
||||||
|
// It's helpful if you don't know NeoPixel settings at compile time or
|
||||||
|
// just want to store this settings in EEPROM or a file on an SD card.
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
int pin = 6; // On Trinket or Gemma, suggest changing this to 1
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
int numPixels = 16; // Popular NeoPixel ring size
|
||||||
|
|
||||||
|
// NeoPixel color format & data rate. See the strandtest example for
|
||||||
|
// information on possible values.
|
||||||
|
int pixelFormat = NEO_GRB + NEO_KHZ800;
|
||||||
|
|
||||||
|
// Rather than declaring the whole NeoPixel object here, we just create
|
||||||
|
// a pointer for one, which we'll then allocate later...
|
||||||
|
Adafruit_NeoPixel *pixels;
|
||||||
|
|
||||||
|
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
// Right about here is where we could read 'pin', 'numPixels' and/or
|
||||||
|
// 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple
|
||||||
|
// example and doesn't do that -- those variables are just set to fixed
|
||||||
|
// values at the top of this code -- but this is where it would happen.
|
||||||
|
|
||||||
|
// Then create a new NeoPixel object dynamically with these values:
|
||||||
|
pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat);
|
||||||
|
|
||||||
|
// Going forward from here, code works almost identically to any other
|
||||||
|
// NeoPixel example, but instead of the dot operator on function calls
|
||||||
|
// (e.g. pixels.begin()), we instead use pointer indirection (->) like so:
|
||||||
|
pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
// You'll see more of this in the loop() function below.
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
pixels->clear(); // Set all pixel colors to 'off'
|
||||||
|
|
||||||
|
// The first NeoPixel in a strand is #0, second is 1, all the way up
|
||||||
|
// to the count of pixels minus one.
|
||||||
|
for(int i=0; i<numPixels; i++) { // For each pixel...
|
||||||
|
|
||||||
|
// pixels->Color() takes RGB values, from 0,0,0 up to 255,255,255
|
||||||
|
// Here we're using a moderately bright green color:
|
||||||
|
pixels->setPixelColor(i, pixels->Color(0, 150, 0));
|
||||||
|
|
||||||
|
pixels->show(); // Send the updated pixel colors to the hardware.
|
||||||
|
|
||||||
|
delay(DELAYVAL); // Pause before next pass through loop
|
||||||
|
}
|
||||||
|
}
|
||||||
0
components/AdafruitNeoPixel/examples/strandtest/.esp8266.test.skip
Executable file
0
components/AdafruitNeoPixel/examples/strandtest/.esp8266.test.skip
Executable file
143
components/AdafruitNeoPixel/examples/strandtest/strandtest.ino
Executable file
143
components/AdafruitNeoPixel/examples/strandtest/strandtest.ino
Executable file
@ -0,0 +1,143 @@
|
|||||||
|
// A basic everyday NeoPixel strip test program.
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
// On a Trinket or Gemma we suggest changing this to 1:
|
||||||
|
#define LED_PIN 6
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define LED_COUNT 60
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
|
||||||
|
// setup() function -- runs once at startup --------------------------------
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// loop() function -- runs repeatedly as long as board is on ---------------
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Fill along the length of the strip in various colors...
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 50); // Green
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 50); // Blue
|
||||||
|
|
||||||
|
// Do a theater marquee effect in various colors...
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness
|
||||||
|
theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness
|
||||||
|
|
||||||
|
rainbow(10); // Flowing rainbow cycle along the whole strip
|
||||||
|
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Some functions of our own for creating animated effects -----------------
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
for(int a=0; a<10; a++) { // Repeat 10 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait) {
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this loop:
|
||||||
|
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
|
||||||
|
// strip.rainbow() can take a single argument (first pixel hue) or
|
||||||
|
// optionally a few extras: number of rainbow repetitions (default 1),
|
||||||
|
// saturation and value (brightness) (both 0-255, similar to the
|
||||||
|
// ColorHSV() function, default 255), and a true/false flag for whether
|
||||||
|
// to apply gamma correction to provide 'truer' colors (default true).
|
||||||
|
strip.rainbow(firstPixelHue);
|
||||||
|
// Above line is equivalent to:
|
||||||
|
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait) {
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for(int a=0; a<30; a++) { // Repeat 30 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
|
||||||
186
components/AdafruitNeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino
Executable file
186
components/AdafruitNeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino
Executable file
@ -0,0 +1,186 @@
|
|||||||
|
// A non-blocking everyday NeoPixel strip test program.
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
// On a Trinket or Gemma we suggest changing this to 1:
|
||||||
|
#ifdef ESP32
|
||||||
|
// Cannot use 6 as output for ESP. Pins 6-11 are connected to SPI flash. Use 16 instead.
|
||||||
|
#define LED_PIN 16
|
||||||
|
#else
|
||||||
|
#define LED_PIN 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define LED_COUNT 60
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
unsigned long pixelPrevious = 0; // Previous Pixel Millis
|
||||||
|
unsigned long patternPrevious = 0; // Previous Pattern Millis
|
||||||
|
int patternCurrent = 0; // Current Pattern Number
|
||||||
|
int patternInterval = 5000; // Pattern Interval (ms)
|
||||||
|
int pixelInterval = 50; // Pixel Interval (ms)
|
||||||
|
int pixelQueue = 0; // Pattern Pixel Queue
|
||||||
|
int pixelCycle = 0; // Pattern Pixel Cycle
|
||||||
|
uint16_t pixelCurrent = 0; // Pattern Current Pixel Number
|
||||||
|
uint16_t pixelNumber = LED_COUNT; // Total Number of Pixels
|
||||||
|
|
||||||
|
// setup() function -- runs once at startup --------------------------------
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop() function -- runs repeatedly as long as board is on ---------------
|
||||||
|
void loop() {
|
||||||
|
unsigned long currentMillis = millis(); // Update current time
|
||||||
|
if((currentMillis - patternPrevious) >= patternInterval) { // Check for expired time
|
||||||
|
patternPrevious = currentMillis;
|
||||||
|
patternCurrent++; // Advance to next pattern
|
||||||
|
if(patternCurrent >= 7)
|
||||||
|
patternCurrent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentMillis - pixelPrevious >= pixelInterval) { // Check for expired time
|
||||||
|
pixelPrevious = currentMillis; // Run current frame
|
||||||
|
switch (patternCurrent) {
|
||||||
|
case 7:
|
||||||
|
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
rainbow(10); // Flowing rainbow cycle along the whole strip
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
theaterChase(strip.Color(0, 0, 127), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 50); // Green
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some functions of our own for creating animated effects -----------------
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCurrent++; // Advance current pixel
|
||||||
|
if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED
|
||||||
|
pixelCurrent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i = 0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
for(int i=0; i < pixelNumber; i+=3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current pixel
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop the pattern from the first LED
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait;
|
||||||
|
for(uint16_t i=0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop the cycle back to the begining
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights with rainbow effect
|
||||||
|
void theaterChaseRainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i=0; i < pixelNumber; i+=3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
for(int i=0; i < pixelNumber; i+=3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current queue
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input a value 0 to 255 to get a color value.
|
||||||
|
// The colours are a transition r - g - b - back to r.
|
||||||
|
uint32_t Wheel(byte WheelPos) {
|
||||||
|
WheelPos = 255 - WheelPos;
|
||||||
|
if(WheelPos < 85) {
|
||||||
|
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||||
|
}
|
||||||
|
if(WheelPos < 170) {
|
||||||
|
WheelPos -= 85;
|
||||||
|
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||||
|
}
|
||||||
|
WheelPos -= 170;
|
||||||
|
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||||
|
}
|
||||||
0
components/AdafruitNeoPixel/examples/strandtest_wheel/.esp8266.test.skip
Executable file
0
components/AdafruitNeoPixel/examples/strandtest_wheel/.esp8266.test.skip
Executable file
134
components/AdafruitNeoPixel/examples/strandtest_wheel/strandtest_wheel.ino
Executable file
134
components/AdafruitNeoPixel/examples/strandtest_wheel/strandtest_wheel.ino
Executable file
@ -0,0 +1,134 @@
|
|||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PIN 6
|
||||||
|
|
||||||
|
// Parameter 1 = number of pixels in strip
|
||||||
|
// Parameter 2 = Arduino pin number (most are valid)
|
||||||
|
// Parameter 3 = 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)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
|
||||||
|
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
|
||||||
|
// and minimize distance between Arduino and first pixel. Avoid connecting
|
||||||
|
// on a live circuit...if you must, connect GND first.
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
|
||||||
|
#if defined (__AVR_ATtiny85__)
|
||||||
|
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// End of trinket special code
|
||||||
|
|
||||||
|
strip.begin();
|
||||||
|
strip.setBrightness(50);
|
||||||
|
strip.show(); // Initialize all pixels to 'off'
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Some example procedures showing how to display to the pixels:
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 50); // Green
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 50); // Blue
|
||||||
|
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
|
||||||
|
// Send a theater pixel chase in...
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||||
|
theaterChase(strip.Color(0, 0, 127), 50); // Blue
|
||||||
|
|
||||||
|
rainbow(20);
|
||||||
|
rainbowCycle(20);
|
||||||
|
theaterChaseRainbow(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill the dots one after the other with a color
|
||||||
|
void colorWipe(uint32_t c, uint8_t wait) {
|
||||||
|
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||||
|
strip.setPixelColor(i, c);
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rainbow(uint8_t wait) {
|
||||||
|
uint16_t i, j;
|
||||||
|
|
||||||
|
for(j=0; j<256; j++) {
|
||||||
|
for(i=0; i<strip.numPixels(); i++) {
|
||||||
|
strip.setPixelColor(i, Wheel((i+j) & 255));
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slightly different, this makes the rainbow equally distributed throughout
|
||||||
|
void rainbowCycle(uint8_t wait) {
|
||||||
|
uint16_t i, j;
|
||||||
|
|
||||||
|
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
|
||||||
|
for(i=0; i< strip.numPixels(); i++) {
|
||||||
|
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights.
|
||||||
|
void theaterChase(uint32_t c, uint8_t wait) {
|
||||||
|
for (int j=0; j<10; j++) { //do 10 cycles of chasing
|
||||||
|
for (int q=0; q < 3; q++) {
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, c); //turn every third pixel on
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
|
||||||
|
delay(wait);
|
||||||
|
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights with rainbow effect
|
||||||
|
void theaterChaseRainbow(uint8_t wait) {
|
||||||
|
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
|
||||||
|
for (int q=0; q < 3; q++) {
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
|
||||||
|
delay(wait);
|
||||||
|
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input a value 0 to 255 to get a color value.
|
||||||
|
// The colours are a transition r - g - b - back to r.
|
||||||
|
uint32_t Wheel(byte WheelPos) {
|
||||||
|
WheelPos = 255 - WheelPos;
|
||||||
|
if(WheelPos < 85) {
|
||||||
|
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||||
|
}
|
||||||
|
if(WheelPos < 170) {
|
||||||
|
WheelPos -= 85;
|
||||||
|
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||||
|
}
|
||||||
|
WheelPos -= 170;
|
||||||
|
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||||
|
}
|
||||||
74
components/AdafruitNeoPixel/kendyte_k210.c
Executable file
74
components/AdafruitNeoPixel/kendyte_k210.c
Executable file
@ -0,0 +1,74 @@
|
|||||||
|
// This is a mash-up of the Due show() code + insights from Michael Miller's
|
||||||
|
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
|
||||||
|
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.
|
||||||
|
#if defined(K210)
|
||||||
|
#define KENDRYTE_K210 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(KENDRYTE_K210)
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "sysctl.h"
|
||||||
|
|
||||||
|
void k210Show(
|
||||||
|
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz)
|
||||||
|
{
|
||||||
|
|
||||||
|
#define CYCLES_800_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2500000) // 0.4us
|
||||||
|
#define CYCLES_800_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1250000) // 0.8us
|
||||||
|
#define CYCLES_800 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 800000) // 1.25us per bit
|
||||||
|
#define CYCLES_400_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2000000) // 0.5uS
|
||||||
|
#define CYCLES_400_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 833333) // 1.2us
|
||||||
|
#define CYCLES_400 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 400000) // 2.5us per bit
|
||||||
|
|
||||||
|
uint8_t *p, *end, pix, mask;
|
||||||
|
uint32_t t, time0, time1, period, c, startTime;
|
||||||
|
|
||||||
|
p = pixels;
|
||||||
|
end = p + numBytes;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
startTime = 0;
|
||||||
|
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
if (is800KHz)
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
time0 = CYCLES_800_T0H;
|
||||||
|
time1 = CYCLES_800_T1H;
|
||||||
|
period = CYCLES_800;
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // 400 KHz bitstream
|
||||||
|
time0 = CYCLES_400_T0H;
|
||||||
|
time1 = CYCLES_400_T1H;
|
||||||
|
period = CYCLES_400;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (t = time0;; t = time0)
|
||||||
|
{
|
||||||
|
if (pix & mask)
|
||||||
|
t = time1; // Bit high duration
|
||||||
|
while (((c = read_cycle()) - startTime) < period)
|
||||||
|
; // Wait for bit start
|
||||||
|
digitalWrite(pin, HIGH);
|
||||||
|
startTime = c; // Save start time
|
||||||
|
while (((c = read_cycle()) - startTime) < t)
|
||||||
|
; // Wait high duration
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
|
||||||
|
if (!(mask >>= 1))
|
||||||
|
{ // Next bit/byte
|
||||||
|
if (p >= end)
|
||||||
|
break;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while ((read_cycle() - startTime) < period)
|
||||||
|
; // Wait for last bit
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // KENDRYTE_K210
|
||||||
72
components/AdafruitNeoPixel/keywords.txt
Executable file
72
components/AdafruitNeoPixel/keywords.txt
Executable file
@ -0,0 +1,72 @@
|
|||||||
|
#######################################
|
||||||
|
# Syntax Coloring Map For Adafruit_NeoPixel
|
||||||
|
#######################################
|
||||||
|
# Class
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
Adafruit_NeoPixel KEYWORD1
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Methods and Functions
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
begin KEYWORD2
|
||||||
|
show KEYWORD2
|
||||||
|
setPin KEYWORD2
|
||||||
|
setPixelColor KEYWORD2
|
||||||
|
fill KEYWORD2
|
||||||
|
setBrightness KEYWORD2
|
||||||
|
clear KEYWORD2
|
||||||
|
updateLength KEYWORD2
|
||||||
|
updateType KEYWORD2
|
||||||
|
canShow KEYWORD2
|
||||||
|
getPixels KEYWORD2
|
||||||
|
getBrightness KEYWORD2
|
||||||
|
getPin KEYWORD2
|
||||||
|
numPixels KEYWORD2
|
||||||
|
getPixelColor KEYWORD2
|
||||||
|
sine8 KEYWORD2
|
||||||
|
gamma8 KEYWORD2
|
||||||
|
Color KEYWORD2
|
||||||
|
ColorHSV KEYWORD2
|
||||||
|
gamma32 KEYWORD2
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Constants
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
NEO_COLMASK LITERAL1
|
||||||
|
NEO_SPDMASK LITERAL1
|
||||||
|
NEO_KHZ800 LITERAL1
|
||||||
|
NEO_KHZ400 LITERAL1
|
||||||
|
NEO_RGB LITERAL1
|
||||||
|
NEO_RBG LITERAL1
|
||||||
|
NEO_GRB LITERAL1
|
||||||
|
NEO_GBR LITERAL1
|
||||||
|
NEO_BRG LITERAL1
|
||||||
|
NEO_BGR LITERAL1
|
||||||
|
NEO_WRGB LITERAL1
|
||||||
|
NEO_WRBG LITERAL1
|
||||||
|
NEO_WGRB LITERAL1
|
||||||
|
NEO_WGBR LITERAL1
|
||||||
|
NEO_WBRG LITERAL1
|
||||||
|
NEO_WBGR LITERAL1
|
||||||
|
NEO_RWGB LITERAL1
|
||||||
|
NEO_RWBG LITERAL1
|
||||||
|
NEO_RGWB LITERAL1
|
||||||
|
NEO_RGBW LITERAL1
|
||||||
|
NEO_RBWG LITERAL1
|
||||||
|
NEO_RBGW LITERAL1
|
||||||
|
NEO_GWRB LITERAL1
|
||||||
|
NEO_GWBR LITERAL1
|
||||||
|
NEO_GRWB LITERAL1
|
||||||
|
NEO_GRBW LITERAL1
|
||||||
|
NEO_GBWR LITERAL1
|
||||||
|
NEO_GBRW LITERAL1
|
||||||
|
NEO_BWRG LITERAL1
|
||||||
|
NEO_BWGR LITERAL1
|
||||||
|
NEO_BRWG LITERAL1
|
||||||
|
NEO_BRGW LITERAL1
|
||||||
|
NEO_BGWR LITERAL1
|
||||||
|
NEO_BGRW LITERAL1
|
||||||
|
|
||||||
10
components/AdafruitNeoPixel/library.properties
Executable file
10
components/AdafruitNeoPixel/library.properties
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
name=Adafruit NeoPixel
|
||||||
|
version=1.12.0
|
||||||
|
author=Adafruit
|
||||||
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
|
sentence=Arduino library for controlling single-wire-based LED pixels and strip.
|
||||||
|
paragraph=Arduino library for controlling single-wire-based LED pixels and strip.
|
||||||
|
category=Display
|
||||||
|
url=https://github.com/adafruit/Adafruit_NeoPixel
|
||||||
|
architectures=*
|
||||||
|
includes=Adafruit_NeoPixel.h
|
||||||
63
components/AdafruitNeoPixel/rp2040_pio.h
Executable file
63
components/AdafruitNeoPixel/rp2040_pio.h
Executable file
@ -0,0 +1,63 @@
|
|||||||
|
// -------------------------------------------------- //
|
||||||
|
// This file is autogenerated by pioasm; do not edit! //
|
||||||
|
// -------------------------------------------------- //
|
||||||
|
|
||||||
|
// Unless you know what you are doing...
|
||||||
|
// Lines 47 and 52 have been edited to set transmit bit count
|
||||||
|
|
||||||
|
#if !PICO_NO_HARDWARE
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ------ //
|
||||||
|
// ws2812 //
|
||||||
|
// ------ //
|
||||||
|
|
||||||
|
#define ws2812_wrap_target 0
|
||||||
|
#define ws2812_wrap 3
|
||||||
|
|
||||||
|
#define ws2812_T1 2
|
||||||
|
#define ws2812_T2 5
|
||||||
|
#define ws2812_T3 3
|
||||||
|
|
||||||
|
static const uint16_t ws2812_program_instructions[] = {
|
||||||
|
// .wrap_target
|
||||||
|
0x6221, // 0: out x, 1 side 0 [2]
|
||||||
|
0x1123, // 1: jmp !x, 3 side 1 [1]
|
||||||
|
0x1400, // 2: jmp 0 side 1 [4]
|
||||||
|
0xa442, // 3: nop side 0 [4]
|
||||||
|
// .wrap
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !PICO_NO_HARDWARE
|
||||||
|
static const struct pio_program ws2812_program = {
|
||||||
|
.instructions = ws2812_program_instructions,
|
||||||
|
.length = 4,
|
||||||
|
.origin = -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline pio_sm_config ws2812_program_get_default_config(uint offset) {
|
||||||
|
pio_sm_config c = pio_get_default_sm_config();
|
||||||
|
sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap);
|
||||||
|
sm_config_set_sideset(&c, 1, false, false);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "hardware/clocks.h"
|
||||||
|
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin,
|
||||||
|
float freq, uint bits) {
|
||||||
|
pio_gpio_init(pio, pin);
|
||||||
|
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
|
||||||
|
pio_sm_config c = ws2812_program_get_default_config(offset);
|
||||||
|
sm_config_set_sideset_pins(&c, pin);
|
||||||
|
sm_config_set_out_shift(&c, false, true,
|
||||||
|
bits); // <----<<< Length changed to "bits"
|
||||||
|
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
|
||||||
|
int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
|
||||||
|
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
|
||||||
|
sm_config_set_clkdiv(&c, div);
|
||||||
|
pio_sm_init(pio, sm, offset, &c);
|
||||||
|
pio_sm_set_enabled(pio, sm, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
9
dependencies.lock
Normal file
9
dependencies.lock
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
dependencies:
|
||||||
|
idf:
|
||||||
|
component_hash: null
|
||||||
|
source:
|
||||||
|
type: idf
|
||||||
|
version: 4.4.6
|
||||||
|
manifest_hash: 1a2cef3f89e1214fd08290dd62d573b5790529294a07b46b6e1f760dbcf477f0
|
||||||
|
target: esp32
|
||||||
|
version: 1.0.0
|
||||||
42
main/App.cpp
Normal file
42
main/App.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#include "App.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#define LED_PIN 26
|
||||||
|
|
||||||
|
App::App()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::init()
|
||||||
|
{
|
||||||
|
m_led = new Led(LED_PIN);
|
||||||
|
m_led->setBrightness(SETTINGS.led.brightness);
|
||||||
|
m_wifi = new Wifi();
|
||||||
|
|
||||||
|
m_led->setPulse(0, 127, 0);
|
||||||
|
m_wifi->connect();
|
||||||
|
m_led->setColor(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::start()
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::readSensors()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::reportSensors()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
26
main/App.h
Normal file
26
main/App.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __APP_H__
|
||||||
|
#define __APP_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "Settings.h"
|
||||||
|
#include "Led.h"
|
||||||
|
#include "Wifi.h"
|
||||||
|
|
||||||
|
class App
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Led * m_led = nullptr;
|
||||||
|
Wifi * m_wifi = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
App();
|
||||||
|
void init();
|
||||||
|
void start();
|
||||||
|
void readSensors();
|
||||||
|
void reportSensors();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
16
main/CMakeLists.txt
Normal file
16
main/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
idf_component_register(SRCS main.cpp App.cpp Settings.cpp Led.cpp TaskFactory.cpp Wifi.cpp utilities.cpp
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
# EMBED_TXTFILES ../private.txt ../public.txt
|
||||||
|
)
|
||||||
|
|
||||||
|
#message(FATAL_ERROR "error ${ROLE}")
|
||||||
|
#if(ROLE EQUAL 1)
|
||||||
|
|
||||||
|
target_compile_options(${COMPONENT_LIB} PRIVATE -frtti)
|
||||||
|
|
||||||
|
#if("${ROLE}" STREQUAL "SENDER")
|
||||||
|
# add_compile_definitions(ROLE_SENDER)
|
||||||
|
#else()
|
||||||
|
# add_compile_definitions(ROLE_RECEIVER)
|
||||||
|
#endif()
|
||||||
|
|
||||||
125
main/Led.cpp
Normal file
125
main/Led.cpp
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#include "Led.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static const uint8_t led_sin_256[] = {
|
||||||
|
0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 6, 6, 8, 9, 10, 11, 12, 14, 15, 17, 18, 20, 22, 23, 25, 27, 29, 31, 33, 35, 38,
|
||||||
|
40, 42, 45, 47, 49, 52, 54, 57, 60, 62, 65, 68, 71, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 113, 116,
|
||||||
|
119, 122, 125, 128, 131, 135, 138, 141, 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186,
|
||||||
|
189, 191, 194, 197, 199, 202, 204, 207, 209, 212, 214, 216, 218, 221, 223, 225, 227, 229, 231, 232, 234, 236, 238,
|
||||||
|
239, 241, 242, 243, 245, 246, 247, 248, 249, 250, 251, 252, 252, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255,
|
||||||
|
255, 255, 254, 254, 253, 253, 252, 252, 251, 250, 249, 248, 247, 246, 245, 243, 242, 241, 239, 238, 236, 234, 232, 231,
|
||||||
|
229, 227, 225, 223, 221, 218, 216, 214, 212, 209, 207, 204, 202, 199, 197, 194, 191, 189, 186, 183, 180, 177, 174,
|
||||||
|
171, 168, 165, 162, 159, 156, 153, 150, 147, 144, 141, 138, 135, 131, 128, 125, 122, 119, 116, 113, 109, 106, 103,
|
||||||
|
100, 97, 94, 91, 88, 85, 82, 79, 76, 73, 71, 68, 65, 62, 60, 57, 54, 52, 49, 47, 45, 42, 40, 38, 35, 33, 31, 29, 27,
|
||||||
|
25, 23, 22, 20, 18, 17, 15, 14, 12, 11, 10, 9, 8, 6, 6, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t led_sin_127[] = {
|
||||||
|
0, 0, 1, 1, 2, 4, 6, 8, 10, 12, 15, 18, 22, 25, 29, 34, 38, 42, 47, 52, 57, 63, 68, 74, 80, 86, 92, 98, 104, 110, 116,
|
||||||
|
123, 129, 135, 142, 148, 154, 160, 166, 172, 178, 184, 189, 195, 200, 205, 210, 215, 219, 224, 228, 231, 235, 238,
|
||||||
|
241, 244, 246, 248, 250, 252, 253, 254, 255, 255, 255, 255, 254, 253, 252, 250, 248, 246, 244, 241, 238, 235, 231,
|
||||||
|
228, 224, 219, 215, 210, 205, 200, 195, 189, 184, 178, 172, 166, 160, 154, 148, 142, 135, 129, 123, 116, 110, 104,
|
||||||
|
98, 92, 86, 80, 74, 68, 63, 57, 52, 47, 42, 38, 34, 29, 25, 22, 18, 15, 12, 10, 8, 6, 4, 2, 1, 1, 0, 0
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const uint8_t led_sin_64[]{
|
||||||
|
0, 1, 2, 5, 10, 15, 21, 29, 37, 47, 57, 67, 79, 90, 103, 115, 127, 140, 152, 165, 176, 188, 198, 208, 218, 226, 234,
|
||||||
|
240, 245, 250, 253, 254, 255, 254, 253, 250, 245, 240, 234, 226, 218, 208, 198, 188, 176, 165, 152, 140, 128, 115,
|
||||||
|
103, 90, 79, 67, 57, 47, 37, 29, 21, 15, 10, 5, 2, 1, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
void Led::steady(uint8_t r, uint8_t g, uint8_t b, uint8_t d)
|
||||||
|
{
|
||||||
|
int r_s, g_s, b_s;
|
||||||
|
uint32_t val = m_strip->getPixelColor(0);
|
||||||
|
b_s = val & 0xff;
|
||||||
|
g_s = (val>>8) & 0xff;
|
||||||
|
r_s = (val>>16) & 0xff;
|
||||||
|
|
||||||
|
for(int n=0; n<17; n++)
|
||||||
|
{
|
||||||
|
int r_ = r_s + ((int)r-r_s)*n/16;
|
||||||
|
int g_ = g_s + ((int)g-g_s)*n/16;
|
||||||
|
int b_ = b_s + ((int)b-b_s)*n/16;
|
||||||
|
m_strip->setPixelColor(0, r_, g_, b_);
|
||||||
|
m_strip->show();
|
||||||
|
delay(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Led::run()
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
vTaskSuspend(NULL);
|
||||||
|
|
||||||
|
if(m_program == PROGRAM::STEADY)
|
||||||
|
{
|
||||||
|
steady(m_r, m_g, m_b, 30);
|
||||||
|
}
|
||||||
|
else if(m_program == PROGRAM::PULSATING)
|
||||||
|
{
|
||||||
|
// turn off
|
||||||
|
steady(0, 0, 0, 10);
|
||||||
|
|
||||||
|
while(m_program == PROGRAM::PULSATING)
|
||||||
|
{
|
||||||
|
for(int n=0; n<sizeof(led_sin_64); n++)
|
||||||
|
{
|
||||||
|
uint8_t m = led_sin_64[n];
|
||||||
|
m_strip->setPixelColor(0, m_r*m/255, m_g*m/255, m_b*m/255);
|
||||||
|
m_strip->show();
|
||||||
|
delay(30);
|
||||||
|
}
|
||||||
|
delay(60);
|
||||||
|
}
|
||||||
|
steady(m_r, m_g, m_b, 30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Led::Led(uint32_t pin)
|
||||||
|
{
|
||||||
|
m_strip = new Adafruit_NeoPixel(1, pin, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
m_strip->begin();
|
||||||
|
m_strip->setPixelColor(0, 0, 0, 0);
|
||||||
|
m_strip->show();
|
||||||
|
|
||||||
|
// create the led task
|
||||||
|
m_task = TASK_FACTORY.createTask(std::bind(&Led::run, this), "led task", 4096, 5, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Led::~Led()
|
||||||
|
{
|
||||||
|
vTaskSuspend(m_task);
|
||||||
|
vTaskDelete(m_task);
|
||||||
|
delete m_strip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Sets led strip color
|
||||||
|
/// @param r red value 0-255
|
||||||
|
/// @param g green value 0-255
|
||||||
|
/// @param b blue value 0-255
|
||||||
|
/// @param brightness brightness 0-100 (%). Default is 100%
|
||||||
|
void Led::setColor(uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
m_program = PROGRAM::STEADY;
|
||||||
|
m_r = (uint8_t)((uint32_t)r*m_brightness/100); m_g = (uint8_t)((uint32_t)g*m_brightness/100); m_b = (uint8_t)((uint32_t)b*m_brightness/100);
|
||||||
|
vTaskResume(m_task);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Led::setPulse(uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
m_program = PROGRAM::PULSATING;
|
||||||
|
m_r = (uint8_t)((uint32_t)r*m_brightness/100); m_g = (uint8_t)((uint32_t)g*m_brightness/100); m_b = (uint8_t)((uint32_t)b*m_brightness/100);
|
||||||
|
vTaskResume(m_task);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Led::setBrightness(uint8_t brightness)
|
||||||
|
{
|
||||||
|
m_brightness = brightness;
|
||||||
|
}
|
||||||
40
main/Led.h
Normal file
40
main/Led.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __LED_H__
|
||||||
|
#define __LED_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#include "TaskFactory.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Led
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum PROGRAM{
|
||||||
|
STEADY,
|
||||||
|
PULSATING
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Adafruit_NeoPixel *m_strip;
|
||||||
|
TaskHandle_t m_task = nullptr;
|
||||||
|
PROGRAM m_program;
|
||||||
|
uint8_t m_r, m_g, m_b;
|
||||||
|
uint8_t m_brightness = 100;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void run();
|
||||||
|
void steady(uint8_t r, uint8_t g, uint8_t b, uint8_t delay);
|
||||||
|
|
||||||
|
public:
|
||||||
|
Led(uint32_t led_pin);
|
||||||
|
virtual ~Led();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setBrightness(uint8_t brightness);
|
||||||
|
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
void setPulse(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
95
main/Settings.cpp
Normal file
95
main/Settings.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#include <nvs_flash.h>
|
||||||
|
#include <nvs.h>
|
||||||
|
#include <esp_partition.h>
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
#include "Settings.h"
|
||||||
|
#include "errors.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static const char *TAG = "Settings";
|
||||||
|
|
||||||
|
Settings & Settings::getInstance()
|
||||||
|
{
|
||||||
|
static Settings instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::Settings()
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Starting settings...");
|
||||||
|
loadData();
|
||||||
|
if(m_data.version != SETTINGS_VERSION)
|
||||||
|
setDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Settings::loadData()
|
||||||
|
{
|
||||||
|
esp_err_t err = nvs_flash_init();
|
||||||
|
|
||||||
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
||||||
|
{
|
||||||
|
// NVS partition was truncated and needs to be erased
|
||||||
|
// Retry nvs_flash_init
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_init());
|
||||||
|
}
|
||||||
|
|
||||||
|
nvs_handle handle;
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(nvs_open(m_namespace, NVS_READWRITE, &handle));
|
||||||
|
|
||||||
|
size_t key_size = 0;
|
||||||
|
err = nvs_get_blob(handle, m_dataname, NULL, &key_size);
|
||||||
|
|
||||||
|
if(err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "Unable to read NVS key: (%d) %s", err, esp_err_to_name(err));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key_size != sizeof(m_data))
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Stored len (%d) doesn't match expected (%d), using default settings",
|
||||||
|
key_size, sizeof(m_data));
|
||||||
|
setDefaults();
|
||||||
|
ESP_ERROR_CHECK(nvs_set_blob(handle, m_dataname, &m_data, sizeof(m_data)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "reading blob");
|
||||||
|
ESP_ERROR_CHECK(nvs_get_blob(handle, m_dataname, &m_data, &key_size));
|
||||||
|
}
|
||||||
|
|
||||||
|
nvs_close(handle);
|
||||||
|
|
||||||
|
return WH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Settings::saveData()
|
||||||
|
{
|
||||||
|
nvs_handle handle;
|
||||||
|
ESP_ERROR_CHECK(nvs_open(m_namespace, NVS_READWRITE, &handle));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_blob(handle, m_dataname, &m_data, sizeof(m_data)));
|
||||||
|
nvs_close(handle);
|
||||||
|
return WH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setDefaults()
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Setting defaults");
|
||||||
|
memset(&m_data, 0, sizeof(m_data));
|
||||||
|
m_data.version = SETTINGS_VERSION;
|
||||||
|
|
||||||
|
m_data.led.brightness = 25; // 25 %
|
||||||
|
|
||||||
|
strcpy(m_data.wifi.entry[0].ssid, "gumball");
|
||||||
|
strcpy(m_data.wifi.entry[0].pwd, "mikelememb");
|
||||||
|
strcpy(m_data.wifi.entry[1].ssid, "miro");
|
||||||
|
strcpy(m_data.wifi.entry[1].pwd, "mikelemembe");
|
||||||
|
|
||||||
|
m_data.wifi.num = 2;
|
||||||
|
m_data.wifi.selected = 0xff;
|
||||||
|
}
|
||||||
130
main/Settings.h
Normal file
130
main/Settings.h
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __SETTINGS_H__
|
||||||
|
#define __SETTINGS_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
|
struct SETTINGS_LEGACY
|
||||||
|
{
|
||||||
|
char WIFI_SSID[32];
|
||||||
|
char WIFI_PASS[32];
|
||||||
|
uint8_t ID[3];
|
||||||
|
uint16_t GROUP_ID;
|
||||||
|
uint16_t THR_UP_PRESSURE;
|
||||||
|
uint16_t THR_UP_RADAR;
|
||||||
|
uint16_t THR_UP_LIGHT;
|
||||||
|
uint16_t THR_UP_TEMPERATURE;
|
||||||
|
uint16_t THR_UP_HUMIMDITY;
|
||||||
|
uint16_t THR_UP_CO2;
|
||||||
|
uint16_t THR_UP_VOC;
|
||||||
|
uint16_t THR_DN_PRESSURE;
|
||||||
|
uint16_t THR_DN_RADAR;
|
||||||
|
uint16_t THR_DN_LIGHT;
|
||||||
|
uint16_t THR_DN_TEMPERATURE;
|
||||||
|
uint16_t THR_DN_HUMIMDITY;
|
||||||
|
uint16_t THR_DN_CO2;
|
||||||
|
uint16_t THR_DN_VOC;
|
||||||
|
uint8_t LPF_PRESSURE;
|
||||||
|
uint8_t LPF_RADAR;
|
||||||
|
uint8_t LPF_LIGHT;
|
||||||
|
uint8_t LPF_TEMPERATURE;
|
||||||
|
uint8_t LPF_HUMIMDITY;
|
||||||
|
uint8_t LPF_CO2;
|
||||||
|
uint8_t LPF_VOC;
|
||||||
|
uint8_t KLPRN_PRESSURE;
|
||||||
|
uint8_t KLPRN_RADAR;
|
||||||
|
uint8_t KLPRN_LIGHT;
|
||||||
|
uint8_t KLPRN_TEMPERATURE;
|
||||||
|
uint8_t KLPRN_HUMIMDITY;
|
||||||
|
uint8_t KLPRN_CO2;
|
||||||
|
uint8_t KLPRN_VOC;
|
||||||
|
uint8_t KLSN_PRESSURE;
|
||||||
|
uint8_t KLSN_RADAR;
|
||||||
|
uint8_t KLSN_LIGHT;
|
||||||
|
uint8_t KLSN_TEMPERATURE;
|
||||||
|
uint8_t KLSN_HUMIMDITY;
|
||||||
|
uint8_t KLSN_CO2;
|
||||||
|
uint8_t KLSN_VOC;
|
||||||
|
uint8_t KLEE_PRESSURE;
|
||||||
|
uint8_t KLEE_RADAR;
|
||||||
|
uint8_t KLEE_LIGHT;
|
||||||
|
uint8_t KLEE_TEMPERATURE;
|
||||||
|
uint8_t KLEE_HUMIMDITY;
|
||||||
|
uint8_t KLEE_CO2;
|
||||||
|
uint8_t KLEE_VOC;
|
||||||
|
uint8_t FS_RATIO;
|
||||||
|
uint8_t NC_REP_PERIOD;
|
||||||
|
uint16_t BT_SCN_EVERY;
|
||||||
|
uint8_t BT_SCN_TIME_LENGTH;
|
||||||
|
uint8_t ENC_KEY[16];
|
||||||
|
uint8_t LED_SCHEMA[10];
|
||||||
|
uint8_t MQTT_ADDR[4];
|
||||||
|
uint16_t MQTT_PORT;
|
||||||
|
uint8_t REPORTING_PERIOD;
|
||||||
|
uint8_t QUEUE[512];
|
||||||
|
char WIFI_SSID2[32];
|
||||||
|
char WIFI_PASS2[32];
|
||||||
|
uint32_t TEMP_OFFSET;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SETTINGS_VERSION 2 // cannot be 0
|
||||||
|
#define SETTINGS_NUM_WIFI_ENTRIES 8
|
||||||
|
|
||||||
|
// wifi definitions
|
||||||
|
|
||||||
|
struct WIFI_ENTRY
|
||||||
|
{
|
||||||
|
char ssid[33];
|
||||||
|
char pwd[33];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WIFI
|
||||||
|
{
|
||||||
|
uint8_t num;
|
||||||
|
uint8_t always_scan_before_connect;
|
||||||
|
struct WIFI_ENTRY entry[SETTINGS_NUM_WIFI_ENTRIES];
|
||||||
|
uint8_t selected;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
struct LED
|
||||||
|
{
|
||||||
|
uint8_t brightness;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NV_DATA
|
||||||
|
{
|
||||||
|
uint32_t version;
|
||||||
|
struct LED led;
|
||||||
|
struct WIFI wifi;
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
const char * m_namespace = "nv_data";
|
||||||
|
const char * m_dataname = "data_01";
|
||||||
|
|
||||||
|
struct NV_DATA m_data;
|
||||||
|
void setDefaults();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Settings();
|
||||||
|
public:
|
||||||
|
static Settings & getInstance();
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline struct NV_DATA & data() {return m_data;};
|
||||||
|
uint32_t loadData();
|
||||||
|
uint32_t saveData();
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SETTINGS Settings::getInstance().data()
|
||||||
|
|
||||||
|
#endif
|
||||||
31
main/TaskFactory.cpp
Normal file
31
main/TaskFactory.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#include "TaskFactory.h"
|
||||||
|
|
||||||
|
TaskFactory::TaskFactory()
|
||||||
|
{
|
||||||
|
m_xMutex = xSemaphoreCreateMutex();
|
||||||
|
assert(m_xMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskFactory::~TaskFactory()
|
||||||
|
{
|
||||||
|
if(m_xMutex != NULL)
|
||||||
|
vSemaphoreDelete(m_xMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskHandle_t TaskFactory::createTask(TASK_FUNCTION task_function, const char *name, uint32_t stack_size, UBaseType_t priority, BaseType_t core)
|
||||||
|
{
|
||||||
|
TaskHandle_t task_handle = nullptr;
|
||||||
|
|
||||||
|
if (xSemaphoreTake(m_xMutex, portMAX_DELAY))
|
||||||
|
{
|
||||||
|
m_task_function = task_function;
|
||||||
|
xTaskCreatePinnedToCore(taskStarter, name, stack_size, this, priority, &task_handle, core);
|
||||||
|
xSemaphoreGive(m_xMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return task_handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskFactory TASK_FACTORY;
|
||||||
42
main/TaskFactory.h
Normal file
42
main/TaskFactory.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __TASK_FACTORY_H__
|
||||||
|
#define __TASK_FACTORY_H__
|
||||||
|
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
#include <freertos/semphr.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <esp_err.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
typedef std::function<void()> TASK_FUNCTION;
|
||||||
|
|
||||||
|
class TaskFactory
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
SemaphoreHandle_t m_xMutex = NULL;
|
||||||
|
TASK_FUNCTION m_task_function = nullptr;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void taskStarter(void * ptr) {
|
||||||
|
(static_cast<TaskFactory*>(ptr)->run());
|
||||||
|
}
|
||||||
|
void run(){
|
||||||
|
m_task_function();
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
TaskHandle_t createTask(TASK_FUNCTION task_function, const char *name, uint32_t stack_size, UBaseType_t priority, BaseType_t core);
|
||||||
|
|
||||||
|
static uint32_t getStackHighWaterMark(TaskHandle_t task){
|
||||||
|
return (uint32_t)uxTaskGetStackHighWaterMark(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskFactory();
|
||||||
|
~TaskFactory();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern TaskFactory TASK_FACTORY;
|
||||||
|
|
||||||
|
#endif
|
||||||
124
main/Wifi.cpp
Normal file
124
main/Wifi.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
#include "Wifi.h"
|
||||||
|
#include "errors.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <functional>
|
||||||
|
#include "utilities.h"
|
||||||
|
|
||||||
|
static const char *TAG = "Wifi";
|
||||||
|
#define IGNORE_SSID_MINS 10
|
||||||
|
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
|
||||||
|
Wifi::Wifi()
|
||||||
|
{
|
||||||
|
esp_log_level_set("wifi", ESP_LOG_WARN);
|
||||||
|
esp_log_level_set("wifi_init", ESP_LOG_INFO);
|
||||||
|
|
||||||
|
memset(m_ignored, 0, SETTINGS_NUM_WIFI_ENTRIES);
|
||||||
|
WiFi.onEvent(std::bind(&Wifi::wifi_event, this, _1, _2));
|
||||||
|
|
||||||
|
esp_timer_create_args_t timer;
|
||||||
|
timer.arg = this;
|
||||||
|
timer.callback = &timerCallback;
|
||||||
|
timer.dispatch_method = ESP_TIMER_TASK;
|
||||||
|
timer.skip_unhandled_events = true;
|
||||||
|
timer.name = "wifi countdown timer";
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_timer_create(&timer, &m_timer));
|
||||||
|
ESP_ERROR_CHECK(esp_timer_start_periodic(m_timer, 60000000)); // 1 min
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wifi::timerCallback(void* arg)
|
||||||
|
{
|
||||||
|
for(int n = 0; n < SETTINGS_NUM_WIFI_ENTRIES; n++)
|
||||||
|
{
|
||||||
|
if(((Wifi*)arg)->m_ignored[n] > 0)
|
||||||
|
((Wifi*)arg)->m_ignored[n]--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wifi::wifi_event(arduino_event_id_t event, arduino_event_info_t info)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "event: %s (%d)", WiFi.eventName(event), (int)event);
|
||||||
|
if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED)
|
||||||
|
{
|
||||||
|
wifi_err_reason_t reason = (wifi_err_reason_t)info.wifi_sta_disconnected.reason;
|
||||||
|
ESP_LOGI(TAG, "reason: %s", WiFi.disconnectReasonName(reason));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Wifi::connect()
|
||||||
|
{
|
||||||
|
if(SETTINGS.wifi.num == 0)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "Not provisioned!");
|
||||||
|
return WH_ERR_WIFI_NOT_PROVISIONED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(WiFi.isConnected())
|
||||||
|
return WH_OK;
|
||||||
|
|
||||||
|
int ssid_ix = SETTINGS.wifi.selected;
|
||||||
|
|
||||||
|
if((SETTINGS.wifi.always_scan_before_connect && SETTINGS.wifi.num > 1) || SETTINGS.wifi.selected >= SETTINGS_NUM_WIFI_ENTRIES)
|
||||||
|
ssid_ix = scan();
|
||||||
|
|
||||||
|
if(ssid_ix < 0)
|
||||||
|
{
|
||||||
|
// ESP_LOGE(TAG, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Connecting to %s...", SETTINGS.wifi.entry[ssid_ix].ssid);
|
||||||
|
WiFi.begin(SETTINGS.wifi.entry[ssid_ix].ssid, SETTINGS.wifi.entry[ssid_ix].pwd);
|
||||||
|
int status = WiFi.waitForConnectResult(15000);
|
||||||
|
|
||||||
|
if(status == WL_CONNECTED)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Connected");
|
||||||
|
return WH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
WiFi.disconnect();
|
||||||
|
m_ignored[ssid_ix] = IGNORE_SSID_MINS;
|
||||||
|
SETTINGS.wifi.selected = 0xff;
|
||||||
|
|
||||||
|
ESP_LOGE(TAG, "connect %d", status);
|
||||||
|
return WH_ERR_WIFI_NOT_CONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Wifi::scan()
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Scanning wifi networks...");
|
||||||
|
|
||||||
|
int num_networks = WiFi.scanNetworks(false, false, false, 500);
|
||||||
|
ESP_LOGI(TAG, "found %d networks", num_networks);
|
||||||
|
|
||||||
|
int rssi = -500;
|
||||||
|
int selected_index = -1;
|
||||||
|
|
||||||
|
// crossref scanned and saved networks
|
||||||
|
for(int n = 0; n < num_networks; n++)
|
||||||
|
{
|
||||||
|
for(int p = 0; p < SETTINGS.wifi.num; p++)
|
||||||
|
{
|
||||||
|
if(strcmp(SETTINGS.wifi.entry[p].ssid, WiFi.SSID(n).c_str()) == 0)
|
||||||
|
{
|
||||||
|
// found saved network
|
||||||
|
ESP_LOGI(TAG, "Found provisioned network '%s' with RSSI %d dBm", SETTINGS.wifi.entry[p].ssid, WiFi.RSSI(n));
|
||||||
|
if(WiFi.RSSI(n) > rssi && m_ignored[p] == 0)
|
||||||
|
{
|
||||||
|
rssi = WiFi.RSSI(n);
|
||||||
|
selected_index = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Chosen network: '%s' based on RSSI", SETTINGS.wifi.entry[selected_index].ssid);
|
||||||
|
|
||||||
|
return selected_index;
|
||||||
|
}
|
||||||
29
main/Wifi.h
Normal file
29
main/Wifi.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __WIFI_H__
|
||||||
|
#define __WIFI_H__
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <esp_timer.h>
|
||||||
|
#include "Settings.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Wifi
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
uint8_t m_ignored[SETTINGS_NUM_WIFI_ENTRIES];
|
||||||
|
esp_timer_handle_t m_timer;
|
||||||
|
static void timerCallback(void* arg);
|
||||||
|
|
||||||
|
public:
|
||||||
|
Wifi();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void wifi_event(arduino_event_id_t event, arduino_event_info_t info);
|
||||||
|
|
||||||
|
public:
|
||||||
|
uint32_t connect();
|
||||||
|
int scan();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
10
main/errors.h
Normal file
10
main/errors.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __ERRORS_H__
|
||||||
|
#define __ERRORS_H__
|
||||||
|
|
||||||
|
#define WH_OK 0
|
||||||
|
#define WH_ERR_WIFI_NOT_PROVISIONED 1
|
||||||
|
#define WH_ERR_WIFI_NOT_CONNECTED 2
|
||||||
|
|
||||||
|
#endif
|
||||||
27
main/main.cpp
Normal file
27
main/main.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "bootloader_random.h"
|
||||||
|
#include <esp_log.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include "esp_task_wdt.h"
|
||||||
|
|
||||||
|
#include "App.h"
|
||||||
|
|
||||||
|
static const char * TAG = "main";
|
||||||
|
|
||||||
|
extern "C" void app_main(void)
|
||||||
|
{
|
||||||
|
bootloader_random_enable();
|
||||||
|
initArduino();
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_task_wdt_init(15, false));
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Starting app...");
|
||||||
|
|
||||||
|
App * app = new App();
|
||||||
|
app->init();
|
||||||
|
app->start();
|
||||||
|
}
|
||||||
29
main/utilities.cpp
Normal file
29
main/utilities.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
static const char *TAG = "utils";
|
||||||
|
|
||||||
|
void dump_bytes(const void *data, uint32_t len)
|
||||||
|
{
|
||||||
|
char c[128] = {0};
|
||||||
|
char b[32];
|
||||||
|
|
||||||
|
uint8_t *pt = (uint8_t*)data;
|
||||||
|
bool hasMore = false;
|
||||||
|
for (int n = 0; n < len; n++)
|
||||||
|
{
|
||||||
|
sprintf(b, "%02x ", *pt++);
|
||||||
|
strcat(c, b);
|
||||||
|
hasMore = true;
|
||||||
|
if ((n + 1) % 8 == 0)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "%s", c);
|
||||||
|
c[0] = 0;
|
||||||
|
hasMore = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasMore)
|
||||||
|
ESP_LOGI(TAG, "%s", c);
|
||||||
|
}
|
||||||
10
main/utilities.h
Normal file
10
main/utilities.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __UTILITIES_H__
|
||||||
|
#define __UTILITIES_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void dump_bytes(const void *data, uint32_t len);
|
||||||
|
|
||||||
|
#endif
|
||||||
17
make.sh
Executable file
17
make.sh
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# first device connected
|
||||||
|
|
||||||
|
idf.py -DROLE=SENDER build
|
||||||
|
|
||||||
|
ret_val=$?
|
||||||
|
|
||||||
|
if (($ret_val != 0)); then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [$1 == '']; then
|
||||||
|
idf.py -p /dev/ttyUSB1 -b 2000000 flash && idf.py -p /dev/ttyUSB1 monitor -B 450000
|
||||||
|
else
|
||||||
|
idf.py -p $1 flash && idf.py -p $1 monitor -B 450000
|
||||||
|
fi
|
||||||
3
monitor.sh
Executable file
3
monitor.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
idf.py -p /dev/ttyUSB1 monitor -B 450000
|
||||||
9
partitions.csv
Normal file
9
partitions.csv
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||||
|
nvs,data,nvs,0x9000,0x5000
|
||||||
|
otadata,data,ota,0xe000,0x2000
|
||||||
|
app0,app,ota_0,0x10000,0x1E0000
|
||||||
|
app1,app,ota_1,0x1F0000,0x1E0000
|
||||||
|
#eeprom,data,0x99,0x3F0000,0x1000
|
||||||
|
spiffs,data,spiffs,0x3F1000,0xF000
|
||||||
|
|
||||||
|
1361
sdkconfig.old
Normal file
1361
sdkconfig.old
Normal file
File diff suppressed because it is too large
Load Diff
19
sender.sh
Executable file
19
sender.sh
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# first device connected
|
||||||
|
|
||||||
|
idf.py -DROLE=SENDER build
|
||||||
|
|
||||||
|
ret_val=$?
|
||||||
|
|
||||||
|
if (($ret_val != 0)); then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [$1 == '']; then
|
||||||
|
idf.py flash -p /dev/ttyUSB0
|
||||||
|
idf.py -p /dev/ttyUSB0 monitor -B 450000
|
||||||
|
else
|
||||||
|
idf.py flash -p $1
|
||||||
|
idf.py -p $1 monitor -B 450000
|
||||||
|
fi
|
||||||
2
setup_source.sh
Normal file
2
setup_source.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
. $HOME/esp/esp-idf/export.sh
|
||||||
|
|
||||||
17
test.sh
Executable file
17
test.sh
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# first device connected
|
||||||
|
|
||||||
|
idf.py -DROLE=SENDER build
|
||||||
|
|
||||||
|
ret_val=$?
|
||||||
|
|
||||||
|
if (($ret_val != 0)); then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [$1 == '']; then
|
||||||
|
idf.py -p /dev/ttyUSB0 flash && idf.py -p /dev/ttyUSB0 monitor -B 450000
|
||||||
|
else
|
||||||
|
idf.py -p $1 flash && idf.py -p $1 monitor -B 450000
|
||||||
|
fi
|
||||||
Loading…
x
Reference in New Issue
Block a user