mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[NeoPixel] Update to latest Adafruit Neopixel library
To fix support for NeoPixel in ESP32/ESP32-s2
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
name: Arduino Library CI
|
||||
|
||||
on: [pull_request, push, repository_dispatch]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
repository: adafruit/ci-arduino
|
||||
path: ci
|
||||
|
||||
- name: pre-install
|
||||
run: bash ci/actions_install.sh
|
||||
|
||||
- name: test platforms
|
||||
run: python3 ci/build_platform.py main_platforms
|
||||
|
||||
- name: doxygen
|
||||
env:
|
||||
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||
PRETTYNAME : "Adafruit NeoPixel Library"
|
||||
run: bash ci/doxy_gen_and_deploy.sh
|
||||
@@ -0,0 +1,4 @@
|
||||
# Our handy .gitignore for automation ease
|
||||
Doxyfile*
|
||||
doxygen_sqlite3.db
|
||||
html
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,105 +1,129 @@
|
||||
/*--------------------------------------------------------------------
|
||||
This file is part of the Adafruit NeoPixel library.
|
||||
|
||||
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.
|
||||
|
||||
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/>.
|
||||
--------------------------------------------------------------------*/
|
||||
/*!
|
||||
* @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
|
||||
|
||||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#include <pins_arduino.h>
|
||||
#ifdef ARDUINO
|
||||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#include <pins_arduino.h>
|
||||
#endif
|
||||
#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
|
||||
// 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.
|
||||
#ifdef TARGET_LPC1768
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
// 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.
|
||||
// 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))
|
||||
#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
// 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))
|
||||
#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2))
|
||||
#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3))
|
||||
#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2))
|
||||
#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1))
|
||||
#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1))
|
||||
#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))
|
||||
#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2))
|
||||
#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3))
|
||||
#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2))
|
||||
#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1))
|
||||
#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
#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))
|
||||
#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3))
|
||||
#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1))
|
||||
#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
#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))
|
||||
#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0))
|
||||
#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0))
|
||||
#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
#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.
|
||||
// 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 datastream
|
||||
#define NEO_KHZ800 0x0000 ///< 800 KHz data transmission
|
||||
#ifndef __AVR_ATtiny85__
|
||||
#define NEO_KHZ400 0x0100 // 400 KHz datastream
|
||||
#define NEO_KHZ400 0x0100 ///< 400 KHz data transmission
|
||||
#endif
|
||||
|
||||
// If 400 KHz support is enabled, the third parameter to the constructor
|
||||
@@ -108,74 +132,251 @@
|
||||
// is sufficient to encode pixel color order, saving some space.
|
||||
|
||||
#ifdef NEO_KHZ400
|
||||
typedef uint16_t neoPixelType;
|
||||
typedef uint16_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor
|
||||
#else
|
||||
typedef uint8_t neoPixelType;
|
||||
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, uint8_t p=6, neoPixelType t=NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_NeoPixel(uint16_t n, int16_t pin=6,
|
||||
neoPixelType type=NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_NeoPixel(void);
|
||||
~Adafruit_NeoPixel();
|
||||
|
||||
void
|
||||
begin(void),
|
||||
show(void),
|
||||
setPin(uint8_t p),
|
||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
|
||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w),
|
||||
setPixelColor(uint16_t n, uint32_t c),
|
||||
setBrightness(uint8_t),
|
||||
clear(),
|
||||
updateLength(uint16_t n),
|
||||
updateType(neoPixelType t);
|
||||
uint8_t
|
||||
*getPixels(void) const,
|
||||
getBrightness(void) const;
|
||||
int8_t
|
||||
getPin(void) { return pin; };
|
||||
uint16_t
|
||||
numPixels(void) const;
|
||||
static uint32_t
|
||||
Color(uint8_t r, uint8_t g, uint8_t b),
|
||||
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
uint32_t
|
||||
getPixelColor(uint16_t n) const;
|
||||
inline bool
|
||||
canShow(void) { return (micros() - endTime) >= 50L; }
|
||||
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);
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
boolean
|
||||
#ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled...
|
||||
is800KHz, // ...true if 800 KHz pixels
|
||||
bool is800KHz; ///< true if 800 KHz pixels
|
||||
#endif
|
||||
begun; // true if begin() previously called
|
||||
uint16_t
|
||||
numLEDs, // Number of RGB LEDs in strip
|
||||
numBytes; // Size of 'pixels' buffer below (3 or 4 bytes/pixel)
|
||||
int8_t
|
||||
pin; // Output pin number (-1 if not yet set)
|
||||
uint8_t
|
||||
brightness,
|
||||
*pixels, // Holds LED color values (3 or 4 bytes each)
|
||||
rOffset, // Index of red byte within each 3- or 4-byte pixel
|
||||
gOffset, // Index of green byte
|
||||
bOffset, // Index of blue byte
|
||||
wOffset; // Index of white byte (same as rOffset if no white)
|
||||
uint32_t
|
||||
endTime; // Latch timing reference
|
||||
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
|
||||
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
|
||||
|
||||
};
|
||||
|
||||
#endif // ADAFRUIT_NEOPIXEL_H
|
||||
|
||||
@@ -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
|
||||
@@ -1,11 +1,153 @@
|
||||
# Adafruit NeoPixel Library [](https://travis-ci.org/adafruit/Adafruit_NeoPixel)
|
||||
# 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)
|
||||
|
||||
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. (Exception for first item in wishlist below.)
|
||||
|
||||
Things I'd Like To Do But There's No Official Timeline So Please Don't Count On Any Of This Ever Being Canonical:
|
||||
|
||||
- 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/)
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
// 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>
|
||||
#include "driver/rmt.h"
|
||||
|
||||
#if defined(ESP_IDF_VERSION)
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
|
||||
#define HAS_ESP_IDF_4
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 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
|
||||
@@ -2,10 +2,12 @@
|
||||
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
|
||||
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.
|
||||
|
||||
#ifdef ESP8266
|
||||
#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) {
|
||||
@@ -14,20 +16,29 @@ static inline uint32_t _getCycleCount(void) {
|
||||
return ccount;
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR espShow(
|
||||
#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 / 2500000) // 0.4us
|
||||
#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us
|
||||
#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit
|
||||
#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, pinMask;
|
||||
uint32_t t, time0, time1, period, c, startTime;
|
||||
|
||||
#ifdef ESP8266
|
||||
uint32_t pinMask;
|
||||
pinMask = _BV(pin);
|
||||
#endif
|
||||
|
||||
p = pixels;
|
||||
end = p + numBytes;
|
||||
pix = *p++;
|
||||
@@ -51,10 +62,18 @@ void ICACHE_RAM_ATTR espShow(
|
||||
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++;
|
||||
|
||||
@@ -1,263 +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>
|
||||
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||
#endif
|
||||
|
||||
#define PIN 6
|
||||
// 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
|
||||
|
||||
#define NUM_LEDS 60
|
||||
// How many NeoPixels are attached to the Arduino?
|
||||
#define LED_COUNT 60
|
||||
|
||||
#define BRIGHTNESS 50
|
||||
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);
|
||||
|
||||
int gamma[] = {
|
||||
0, 0, 0, 0, 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, 1, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
|
||||
5, 6, 6, 6, 6, 7, 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, 32, 32, 33, 34, 35, 35, 36,
|
||||
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
|
||||
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
|
||||
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
|
||||
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
|
||||
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
|
||||
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
|
||||
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
|
||||
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
|
||||
// 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() {
|
||||
Serial.begin(115200);
|
||||
// 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
|
||||
// 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);
|
||||
strip.begin();
|
||||
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
|
||||
// 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(20,75,5);
|
||||
|
||||
pulseWhite(5);
|
||||
|
||||
// fullWhite();
|
||||
// delay(2000);
|
||||
|
||||
rainbowFade2White(3,3,1);
|
||||
whiteOverRainbow(75, 5);
|
||||
|
||||
pulseWhite(5);
|
||||
|
||||
rainbowFade2White(3, 3, 1);
|
||||
}
|
||||
|
||||
// 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);
|
||||
// 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++){
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
|
||||
}
|
||||
delay(wait);
|
||||
strip.show();
|
||||
}
|
||||
|
||||
for(int j = 255; j >= 0 ; j--){
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
|
||||
}
|
||||
delay(wait);
|
||||
strip.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops) {
|
||||
float fadeMax = 100.0;
|
||||
int fadeVal = 0;
|
||||
uint32_t wheelVal;
|
||||
int redVal, greenVal, blueVal;
|
||||
|
||||
for(int k = 0 ; k < rainbowLoops ; k ++){
|
||||
|
||||
for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel
|
||||
|
||||
for(int i=0; i< strip.numPixels(); i++) {
|
||||
|
||||
wheelVal = Wheel(((i * 256 / strip.numPixels()) + j) & 255);
|
||||
|
||||
redVal = red(wheelVal) * float(fadeVal/fadeMax);
|
||||
greenVal = green(wheelVal) * float(fadeVal/fadeMax);
|
||||
blueVal = blue(wheelVal) * float(fadeVal/fadeMax);
|
||||
|
||||
strip.setPixelColor( i, strip.Color( redVal, greenVal, blueVal ) );
|
||||
|
||||
}
|
||||
|
||||
//First loop, fade in!
|
||||
if(k == 0 && fadeVal < fadeMax-1) {
|
||||
fadeVal++;
|
||||
}
|
||||
|
||||
//Last loop, fade out!
|
||||
else if(k == rainbowLoops - 1 && j > 255 - fadeMax ){
|
||||
fadeVal--;
|
||||
}
|
||||
|
||||
strip.show();
|
||||
delay(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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
delay(500);
|
||||
|
||||
|
||||
for(int k = 0 ; k < whiteLoops ; k ++){
|
||||
|
||||
for(int j = 0; j < 256 ; j++){
|
||||
|
||||
for(uint16_t i=0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
for(int j = 255; j >= 0 ; j--){
|
||||
|
||||
for(uint16_t i=0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, strip.Color(0,0,0, gamma[j] ) );
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
delay(500);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void whiteOverRainbow(uint8_t wait, uint8_t whiteSpeed, uint8_t whiteLength ) {
|
||||
|
||||
if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
|
||||
void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
|
||||
int fadeVal=0, fadeMax=100;
|
||||
|
||||
int head = whiteLength - 1;
|
||||
int tail = 0;
|
||||
// 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) {
|
||||
|
||||
int loops = 3;
|
||||
int loopNum = 0;
|
||||
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||
|
||||
static unsigned long lastTime = 0;
|
||||
// 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)));
|
||||
}
|
||||
|
||||
while(true){
|
||||
for(int j=0; j<256; j++) {
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||
if((i >= tail && i <= head) || (tail > head && i >= tail) || (tail > head && i <= head) ){
|
||||
strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
|
||||
}
|
||||
else{
|
||||
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
|
||||
}
|
||||
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
|
||||
if(millis() - lastTime > whiteSpeed) {
|
||||
head++;
|
||||
tail++;
|
||||
if(head == strip.numPixels()){
|
||||
loopNum++;
|
||||
}
|
||||
lastTime = millis();
|
||||
}
|
||||
|
||||
if(loopNum == loops) return;
|
||||
|
||||
head%=strip.numPixels();
|
||||
tail%=strip.numPixels();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void fullWhite() {
|
||||
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
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();
|
||||
}
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
}
|
||||
|
||||
// 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,0);
|
||||
}
|
||||
if(WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
|
||||
}
|
||||
WheelPos -= 170;
|
||||
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
|
||||
delay(500); // Pause 1/2 second
|
||||
}
|
||||
|
||||
uint8_t red(uint32_t c) {
|
||||
return (c >> 8);
|
||||
}
|
||||
uint8_t green(uint32_t c) {
|
||||
return (c >> 16);
|
||||
}
|
||||
uint8_t blue(uint32_t c) {
|
||||
return (c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
+239
@@ -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,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());
|
||||
}
|
||||
@@ -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,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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,165 +1,164 @@
|
||||
// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
|
||||
// You should wire a momentary push button to connect from ground to a digital IO pin. When you
|
||||
// press the button it will change to a new pixel animation. Note that you need to press the
|
||||
// button once to start the first animation!
|
||||
// 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
|
||||
|
||||
#define BUTTON_PIN 2 // Digital IO pin connected to the button. This will be
|
||||
// driven with a pull-up resistor so the switch should
|
||||
// pull the pin to ground momentarily. On a high -> low
|
||||
// transition the button press logic will execute.
|
||||
// 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_PIN 6 // Digital IO pin connected to the NeoPixels.
|
||||
|
||||
#define PIXEL_COUNT 16
|
||||
#define PIXEL_COUNT 16 // Number of NeoPixels
|
||||
|
||||
// Parameter 1 = number of pixels in strip, neopixel stick has 8
|
||||
// Parameter 2 = pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_RGB Pixels are wired for RGB bitstream
|
||||
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
|
||||
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
|
||||
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
|
||||
// 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)
|
||||
|
||||
bool oldState = HIGH;
|
||||
int showType = 0;
|
||||
boolean oldState = HIGH;
|
||||
int mode = 0; // Currently-active animation mode, 0-9
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
strip.begin();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Get current button state.
|
||||
bool newState = digitalRead(BUTTON_PIN);
|
||||
boolean newState = digitalRead(BUTTON_PIN);
|
||||
|
||||
// Check if state changed from high to low (button press).
|
||||
if (newState == LOW && oldState == HIGH) {
|
||||
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) {
|
||||
showType++;
|
||||
if (showType > 9)
|
||||
showType=0;
|
||||
startShow(showType);
|
||||
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 button state to the old state.
|
||||
// Set the last-read button state to the old state.
|
||||
oldState = newState;
|
||||
}
|
||||
|
||||
void startShow(int i) {
|
||||
switch(i){
|
||||
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(20);
|
||||
break;
|
||||
case 8: rainbowCycle(20);
|
||||
break;
|
||||
case 9: theaterChaseRainbow(50);
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (int i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, c); //turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (int i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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 (int i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
|
||||
}
|
||||
strip.show();
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (int i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -1,47 +1,50 @@
|
||||
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
|
||||
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
|
||||
// Released under the GPLv3 license to match the rest of the
|
||||
// Adafruit NeoPixel library
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#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 PIN 6
|
||||
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
|
||||
|
||||
// How many NeoPixels are attached to the Arduino?
|
||||
#define NUMPIXELS 16
|
||||
#define NUMPIXELS 16 // Popular NeoPixel ring size
|
||||
|
||||
// When we setup 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 = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
// 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);
|
||||
|
||||
int delayval = 500; // delay for half a second
|
||||
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
|
||||
|
||||
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);
|
||||
// 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 special code
|
||||
// END of Trinket-specific code.
|
||||
|
||||
pixels.begin(); // This initializes the NeoPixel library.
|
||||
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
pixels.clear(); // Set all pixel colors to 'off'
|
||||
|
||||
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
|
||||
// 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...
|
||||
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
// 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.Color takes RGB values, from 0,0,0 up to 255,255,255
|
||||
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
|
||||
|
||||
pixels.show(); // This sends the updated pixel color to the hardware.
|
||||
|
||||
delay(delayval); // Delay for a period of time (in milliseconds).
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,134 +1,147 @@
|
||||
// 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>
|
||||
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||
#endif
|
||||
|
||||
#define PIN 6
|
||||
// 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
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// 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)
|
||||
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.
|
||||
|
||||
// setup() function -- runs once at startup --------------------------------
|
||||
|
||||
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
|
||||
// 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();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
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() {
|
||||
// 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
|
||||
// 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
|
||||
|
||||
rainbow(20);
|
||||
rainbowCycle(20);
|
||||
theaterChaseRainbow(50);
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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();
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
delay(wait);
|
||||
|
||||
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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,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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -1,29 +1,72 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Adafruit_NeoPixel
|
||||
#######################################
|
||||
#######################################
|
||||
# Class
|
||||
#######################################
|
||||
|
||||
Adafruit_NeoPixel KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions
|
||||
# Methods and Functions
|
||||
#######################################
|
||||
|
||||
setPixelColor KEYWORD2
|
||||
begin KEYWORD2
|
||||
show KEYWORD2
|
||||
setPin KEYWORD2
|
||||
setBrightness 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
|
||||
getPixelColor KEYWORD2
|
||||
sine8 KEYWORD2
|
||||
gamma8 KEYWORD2
|
||||
Color KEYWORD2
|
||||
ColorHSV KEYWORD2
|
||||
gamma32 KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants
|
||||
#######################################
|
||||
|
||||
NEO_GRB LITERAL1
|
||||
|
||||
NEO_COLMASK LITERAL1
|
||||
NEO_KHZ800 LITERAL1
|
||||
NEO_SPDMASK LITERAL1
|
||||
NEO_RGB 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
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=Adafruit NeoPixel
|
||||
version=1.0.6
|
||||
version=1.8.7
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for controlling single-wire-based LED pixels and strip.
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// This sketch is based on the SDK example here:
|
||||
// https://github.com/raspberrypi/pico-examples/tree/master/pio/ws2812
|
||||
|
||||
/**
|
||||
Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_RP2040)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "hardware/pio.h"
|
||||
#include "hardware/clocks.h"
|
||||
|
||||
#include "rp2040_pio.h"
|
||||
|
||||
void rp2040Init(uint8_t pin, bool is800KHz)
|
||||
{
|
||||
// todo get free sm
|
||||
PIO pio = pio0;
|
||||
int sm = 0;
|
||||
uint offset = pio_add_program(pio, &ws2812_program);
|
||||
|
||||
if (is800KHz)
|
||||
{
|
||||
// 800kHz, 8 bit transfers
|
||||
ws2812_program_init(pio, sm, offset, pin, 800000, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 400kHz, 8 bit transfers
|
||||
ws2812_program_init(pio, sm, offset, pin, 400000, 8);
|
||||
}
|
||||
}
|
||||
|
||||
void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz)
|
||||
{
|
||||
static bool init = true;
|
||||
|
||||
if (init)
|
||||
{
|
||||
// On first pass through initialise the PIO
|
||||
rp2040Init(pin, is800KHz);
|
||||
init = false;
|
||||
}
|
||||
|
||||
while(numBytes--)
|
||||
// Bits for transmission must be shifted to top 8 bits
|
||||
pio_sm_put_blocking(pio0, 0, ((uint32_t)*pixels++)<< 24);
|
||||
}
|
||||
|
||||
#endif // KENDRYTE_K210
|
||||
@@ -0,0 +1,61 @@
|
||||
// -------------------------------------------------- //
|
||||
// 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
|
||||
Reference in New Issue
Block a user