(leds, NUM_LEDS).setCorrection( TypicalSMD5050 );
83 | FastLED.setBrightness( BRIGHTNESS );
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/android/app/src/debug/java/com/bleexample/ReactNativeFlipper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the LICENSE file in the root
5 | * directory of this source tree.
6 | */
7 | package com.bleexample;
8 |
9 | import android.content.Context;
10 | import com.facebook.flipper.android.AndroidFlipperClient;
11 | import com.facebook.flipper.android.utils.FlipperUtils;
12 | import com.facebook.flipper.core.FlipperClient;
13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping;
17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22 | import com.facebook.react.ReactInstanceManager;
23 | import com.facebook.react.bridge.ReactContext;
24 | import com.facebook.react.modules.network.NetworkingModule;
25 | import okhttp3.OkHttpClient;
26 |
27 | public class ReactNativeFlipper {
28 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
29 | if (FlipperUtils.shouldEnableFlipper(context)) {
30 | final FlipperClient client = AndroidFlipperClient.getInstance(context);
31 |
32 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
33 | client.addPlugin(new ReactFlipperPlugin());
34 | client.addPlugin(new DatabasesFlipperPlugin(context));
35 | client.addPlugin(new SharedPreferencesFlipperPlugin(context));
36 | client.addPlugin(CrashReporterPlugin.getInstance());
37 |
38 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
39 | NetworkingModule.setCustomClientBuilder(
40 | new NetworkingModule.CustomClientBuilder() {
41 | @Override
42 | public void apply(OkHttpClient.Builder builder) {
43 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
44 | }
45 | });
46 | client.addPlugin(networkFlipperPlugin);
47 | client.start();
48 |
49 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
50 | // Hence we run if after all native modules have been initialized
51 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
52 | if (reactContext == null) {
53 | reactInstanceManager.addReactInstanceEventListener(
54 | new ReactInstanceManager.ReactInstanceEventListener() {
55 | @Override
56 | public void onReactContextInitialized(ReactContext reactContext) {
57 | reactInstanceManager.removeReactInstanceEventListener(this);
58 | reactContext.runOnNativeModulesQueueThread(
59 | new Runnable() {
60 | @Override
61 | public void run() {
62 | client.addPlugin(new FrescoFlipperPlugin());
63 | }
64 | });
65 | }
66 | });
67 | } else {
68 | client.addPlugin(new FrescoFlipperPlugin());
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/fastspi_ref.h:
--------------------------------------------------------------------------------
1 | #ifndef __INC_FASTSPI_ARM_SAM_H
2 | #define __INC_FASTSPI_ARM_SAM_H
3 |
4 | #if 0 // guard against the arduino ide idiotically including every header file
5 | #include "FastLED.h"
6 |
7 | FASTLED_NAMESPACE_BEGIN
8 |
9 | // A skeletal implementation of hardware SPI support. Fill in the necessary code for init, waiting, and writing. The rest of
10 | // the method implementations should provide a starting point, even if not hte most efficient to start with
11 | template
12 | class REFHardwareSPIOutput {
13 | Selectable *m_pSelect;
14 | public:
15 | SAMHardwareSPIOutput() { m_pSelect = NULL; }
16 | SAMHArdwareSPIOutput(Selectable *pSelect) { m_pSelect = pSelect; }
17 |
18 | // set the object representing the selectable
19 | void setSelect(Selectable *pSelect) { /* TODO */ }
20 |
21 | // initialize the SPI subssytem
22 | void init() { /* TODO */ }
23 |
24 | // latch the CS select
25 | void inline select() __attribute__((always_inline)) { if(m_pSelect != NULL) { m_pSelect->select(); } }
26 |
27 | // release the CS select
28 | void inline release() __attribute__((always_inline)) { if(m_pSelect != NULL) { m_pSelect->release(); } }
29 |
30 | // wait until all queued up data has been written
31 | static void waitFully() { /* TODO */ }
32 |
33 | // write a byte out via SPI (returns immediately on writing register)
34 | static void writeByte(uint8_t b) { /* TODO */ }
35 |
36 | // write a word out via SPI (returns immediately on writing register)
37 | static void writeWord(uint16_t w) { /* TODO */ }
38 |
39 | // A raw set of writing byte values, assumes setup/init/waiting done elsewhere
40 | static void writeBytesValueRaw(uint8_t value, int len) {
41 | while(len--) { writeByte(value); }
42 | }
43 |
44 | // A full cycle of writing a value for len bytes, including select, release, and waiting
45 | void writeBytesValue(uint8_t value, int len) {
46 | select(); writeBytesValueRaw(value, len); release();
47 | }
48 |
49 | // A full cycle of writing a value for len bytes, including select, release, and waiting
50 | template void writeBytes(register uint8_t *data, int len) {
51 | uint8_t *end = data + len;
52 | select();
53 | // could be optimized to write 16bit words out instead of 8bit bytes
54 | while(data != end) {
55 | writeByte(D::adjust(*data++));
56 | }
57 | D::postBlock(len);
58 | waitFully();
59 | release();
60 | }
61 |
62 | // A full cycle of writing a value for len bytes, including select, release, and waiting
63 | void writeBytes(register uint8_t *data, int len) { writeBytes(data, len); }
64 |
65 | // write a single bit out, which bit from the passed in byte is determined by template parameter
66 | template inline static void writeBit(uint8_t b) { /* TODO */ }
67 |
68 | // write a block of uint8_ts out in groups of three. len is the total number of uint8_ts to write out. The template
69 | // parameters indicate how many uint8_ts to skip at the beginning and/or end of each grouping
70 | template void writePixels(PixelController pixels) {
71 | select();
72 | while(data != end) {
73 | if(FLAGS & FLAG_START_BIT) {
74 | writeBit<0>(1);
75 | }
76 | writeByte(D::adjust(pixels.loadAndScale0()));
77 | writeByte(D::adjust(pixels.loadAndScale1()));
78 | writeByte(D::adjust(pixels.loadAndScale2()));
79 |
80 | pixels.advanceData();
81 | pixels.stepDithering();
82 | data += (3+skip);
83 | }
84 | D::postBlock(len);
85 | release();
86 | }
87 |
88 | };
89 |
90 | FASTLED_NAMESPACE_END
91 |
92 | #endif
93 |
94 | #endif
95 |
96 |
--------------------------------------------------------------------------------
/ios/BleExample.xcodeproj/xcshareddata/xcschemes/BleExample.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
53 |
55 |
61 |
62 |
63 |
64 |
70 |
72 |
78 |
79 |
80 |
81 |
83 |
84 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/examples/Noise/Noise.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //
4 | // Mark's xy coordinate mapping code. See the XYMatrix for more information on it.
5 | //
6 |
7 | // Params for width and height
8 | const uint8_t kMatrixWidth = 16;
9 | const uint8_t kMatrixHeight = 16;
10 | #define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
11 | #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
12 | // Param for different pixel layouts
13 | const bool kMatrixSerpentineLayout = true;
14 |
15 |
16 | uint16_t XY( uint8_t x, uint8_t y)
17 | {
18 | uint16_t i;
19 |
20 | if( kMatrixSerpentineLayout == false) {
21 | i = (y * kMatrixWidth) + x;
22 | }
23 |
24 | if( kMatrixSerpentineLayout == true) {
25 | if( y & 0x01) {
26 | // Odd rows run backwards
27 | uint8_t reverseX = (kMatrixWidth - 1) - x;
28 | i = (y * kMatrixWidth) + reverseX;
29 | } else {
30 | // Even rows run forwards
31 | i = (y * kMatrixWidth) + x;
32 | }
33 | }
34 |
35 | return i;
36 | }
37 |
38 | // The leds
39 | CRGB leds[kMatrixWidth * kMatrixHeight];
40 |
41 | // The 32bit version of our coordinates
42 | static uint16_t x;
43 | static uint16_t y;
44 | static uint16_t z;
45 |
46 | // We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
47 | // use the z-axis for "time". speed determines how fast time moves forward. Try
48 | // 1 for a very slow moving effect, or 60 for something that ends up looking like
49 | // water.
50 | // uint16_t speed = 1; // almost looks like a painting, moves very slowly
51 | uint16_t speed = 20; // a nice starting speed, mixes well with a scale of 100
52 | // uint16_t speed = 33;
53 | // uint16_t speed = 100; // wicked fast!
54 |
55 | // Scale determines how far apart the pixels in our noise matrix are. Try
56 | // changing these values around to see how it affects the motion of the display. The
57 | // higher the value of scale, the more "zoomed out" the noise iwll be. A value
58 | // of 1 will be so zoomed in, you'll mostly see solid colors.
59 |
60 | // uint16_t scale = 1; // mostly just solid colors
61 | // uint16_t scale = 4011; // very zoomed out and shimmery
62 | uint16_t scale = 311;
63 |
64 | // This is the array that we keep our computed noise values in
65 | uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
66 |
67 | void setup() {
68 | // uncomment the following lines if you want to see FPS count information
69 | // Serial.begin(38400);
70 | // Serial.println("resetting!");
71 | delay(3000);
72 | LEDS.addLeds(leds,NUM_LEDS);
73 | LEDS.setBrightness(96);
74 |
75 | // Initialize our coordinates to some random values
76 | x = random16();
77 | y = random16();
78 | z = random16();
79 | }
80 |
81 | // Fill the x/y array of 8-bit noise values using the inoise8 function.
82 | void fillnoise8() {
83 | for(int i = 0; i < MAX_DIMENSION; i++) {
84 | int ioffset = scale * i;
85 | for(int j = 0; j < MAX_DIMENSION; j++) {
86 | int joffset = scale * j;
87 | noise[i][j] = inoise8(x + ioffset,y + joffset,z);
88 | }
89 | }
90 | z += speed;
91 | }
92 |
93 |
94 | void loop() {
95 | static uint8_t ihue=0;
96 | fillnoise8();
97 | for(int i = 0; i < kMatrixWidth; i++) {
98 | for(int j = 0; j < kMatrixHeight; j++) {
99 | // We use the value at the (i,j) coordinate in the noise
100 | // array for our brightness, and the flipped value from (j,i)
101 | // for our pixel's hue.
102 | leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
103 |
104 | // You can also explore other ways to constrain the hue used, like below
105 | // leds[XY(i,j)] = CHSV(ihue + (noise[j][i]>>2),255,noise[i][j]);
106 | }
107 | }
108 | ihue+=1;
109 |
110 | LEDS.show();
111 | // delay(10);
112 | }
113 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/examples/Fire2012/Fire2012.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define LED_PIN 5
4 | #define COLOR_ORDER GRB
5 | #define CHIPSET WS2811
6 | #define NUM_LEDS 30
7 |
8 | #define BRIGHTNESS 200
9 | #define FRAMES_PER_SECOND 60
10 |
11 | bool gReverseDirection = false;
12 |
13 | CRGB leds[NUM_LEDS];
14 |
15 | void setup() {
16 | delay(3000); // sanity delay
17 | FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
18 | FastLED.setBrightness( BRIGHTNESS );
19 | }
20 |
21 | void loop()
22 | {
23 | // Add entropy to random number generator; we use a lot of it.
24 | // random16_add_entropy( random());
25 |
26 | Fire2012(); // run simulation frame
27 |
28 | FastLED.show(); // display this frame
29 | FastLED.delay(1000 / FRAMES_PER_SECOND);
30 | }
31 |
32 |
33 | // Fire2012 by Mark Kriegsman, July 2012
34 | // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
35 | ////
36 | // This basic one-dimensional 'fire' simulation works roughly as follows:
37 | // There's a underlying array of 'heat' cells, that model the temperature
38 | // at each point along the line. Every cycle through the simulation,
39 | // four steps are performed:
40 | // 1) All cells cool down a little bit, losing heat to the air
41 | // 2) The heat from each cell drifts 'up' and diffuses a little
42 | // 3) Sometimes randomly new 'sparks' of heat are added at the bottom
43 | // 4) The heat from each cell is rendered as a color into the leds array
44 | // The heat-to-color mapping uses a black-body radiation approximation.
45 | //
46 | // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
47 | //
48 | // This simulation scales it self a bit depending on NUM_LEDS; it should look
49 | // "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
50 | //
51 | // I recommend running this simulation at anywhere from 30-100 frames per second,
52 | // meaning an interframe delay of about 10-35 milliseconds.
53 | //
54 | // Looks best on a high-density LED setup (60+ pixels/meter).
55 | //
56 | //
57 | // There are two main parameters you can play with to control the look and
58 | // feel of your fire: COOLING (used in step 1 above), and SPARKING (used
59 | // in step 3 above).
60 | //
61 | // COOLING: How much does the air cool as it rises?
62 | // Less cooling = taller flames. More cooling = shorter flames.
63 | // Default 50, suggested range 20-100
64 | #define COOLING 55
65 |
66 | // SPARKING: What chance (out of 255) is there that a new spark will be lit?
67 | // Higher chance = more roaring fire. Lower chance = more flickery fire.
68 | // Default 120, suggested range 50-200.
69 | #define SPARKING 120
70 |
71 |
72 | void Fire2012()
73 | {
74 | // Array of temperature readings at each simulation cell
75 | static byte heat[NUM_LEDS];
76 |
77 | // Step 1. Cool down every cell a little
78 | for( int i = 0; i < NUM_LEDS; i++) {
79 | heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
80 | }
81 |
82 | // Step 2. Heat from each cell drifts 'up' and diffuses a little
83 | for( int k= NUM_LEDS - 1; k >= 2; k--) {
84 | heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
85 | }
86 |
87 | // Step 3. Randomly ignite new 'sparks' of heat near the bottom
88 | if( random8() < SPARKING ) {
89 | int y = random8(7);
90 | heat[y] = qadd8( heat[y], random8(160,255) );
91 | }
92 |
93 | // Step 4. Map from heat cells to LED colors
94 | for( int j = 0; j < NUM_LEDS; j++) {
95 | CRGB color = HeatColor( heat[j]);
96 | int pixelnumber;
97 | if( gReverseDirection ) {
98 | pixelnumber = (NUM_LEDS-1) - j;
99 | } else {
100 | pixelnumber = j;
101 | }
102 | leds[pixelnumber] = color;
103 | }
104 | }
105 |
106 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/examples/Blink/Blink.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // How many leds in your strip?
4 | #define NUM_LEDS 1
5 |
6 | // For led chips like WS2812, which have a data line, ground, and power, you just
7 | // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
8 | // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
9 | // Clock pin only needed for SPI based chipsets when not using hardware SPI
10 | #define DATA_PIN 3
11 | #define CLOCK_PIN 13
12 |
13 | // Define the array of leds
14 | CRGB leds[NUM_LEDS];
15 |
16 | void setup() {
17 | // Uncomment/edit one of the following lines for your leds arrangement.
18 | // ## Clockless types ##
19 | FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is assumed
20 | // FastLED.addLeds(leds, NUM_LEDS);
21 | // FastLED.addLeds(leds, NUM_LEDS);
22 | // FastLED.addLeds(leds, NUM_LEDS);
23 | // FastLED.addLeds(leds, NUM_LEDS);
24 | // FastLED.addLeds(leds, NUM_LEDS);
25 | // FastLED.addLeds(leds, NUM_LEDS);
26 | // FastLED.addLeds(leds, NUM_LEDS);
27 | // FastLED.addLeds(leds, NUM_LEDS);
28 | // FastLED.addLeds(leds, NUM_LEDS);
29 | // FastLED.addLeds(leds, NUM_LEDS);
30 | // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical
31 | // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical
32 | // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical
33 | // FastLED.addLeds(leds, NUM_LEDS);
34 | // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical
35 | // FastLED.addLeds(leds, NUM_LEDS);
36 | // FastLED.addLeds(leds, NUM_LEDS);
37 | // FastLED.addLeds(leds, NUM_LEDS);
38 | // FastLED.addLeds(leds, NUM_LEDS);
39 | // FastLED.addLeds(leds, NUM_LEDS);
40 | // FastLED.addLeds(leds, NUM_LEDS);
41 | // FastLED.addLeds(leds, NUM_LEDS);
42 | // FastLED.addLeds(leds, NUM_LEDS);
43 | // FastLED.addLeds(leds, NUM_LEDS);
44 | // FastLED.addLeds(leds, NUM_LEDS);
45 | // FastLED.addLeds(leds, NUM_LEDS);
46 | // FastLED.addLeds(leds, NUM_LEDS);
47 | // FastLED.addLeds(leds, NUM_LEDS);
48 | // ## Clocked (SPI) types ##
49 | // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical
50 | // FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical
51 | // FastLED.addLeds(leds, NUM_LEDS);
52 | // FastLED.addLeds(leds, NUM_LEDS);
53 | // FastLED.addLeds(leds, NUM_LEDS);
54 | // FastLED.addLeds(leds, NUM_LEDS); // BGR ordering is typical
55 | // FastLED.addLeds(leds, NUM_LEDS); // BGR ordering is typical
56 | // FastLED.addLeds(leds, NUM_LEDS); // BGR ordering is typical
57 | // FastLED.addLeds(leds, NUM_LEDS); // BGR ordering is typical
58 | }
59 |
60 | void loop() {
61 | // Turn the LED on, then pause
62 | leds[0] = CRGB::Red;
63 | FastLED.show();
64 | delay(500);
65 | // Now turn the LED off, then pause
66 | leds[0] = CRGB::Black;
67 | FastLED.show();
68 | delay(500);
69 | }
70 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/fastled_config.h:
--------------------------------------------------------------------------------
1 | #ifndef __INC_FASTLED_CONFIG_H
2 | #define __INC_FASTLED_CONFIG_H
3 |
4 | #include "FastLED.h"
5 |
6 | ///@file fastled_config.h
7 | /// contains definitions that can be used to configure FastLED at compile time
8 |
9 | // Use this option only for debugging pin access and forcing software pin access. Note that
10 | // software pin access only works in Arduino based environments. Forces use of digitalWrite
11 | // methods for pin access vs. direct hardware port access
12 | // #define FASTLED_FORCE_SOFTWARE_PINS
13 |
14 | // Use this option only for debugging bitbang'd spi access or to work around bugs in hardware
15 | // spi access. Forces use of bit-banged spi, even on pins that has hardware SPI available.
16 | // #define FASTLED_FORCE_SOFTWARE_SPI
17 |
18 | // Use this to force FastLED to allow interrupts in the clockless chipsets (or to force it to
19 | // disallow), overriding the default on platforms that support this. Set the value to 1 to
20 | // allow interrupts or 0 to disallow them.
21 | // #define FASTLED_ALLOW_INTERRUPTS 1
22 | // #define FASTLED_ALLOW_INTERRUPTS 0
23 |
24 | // Use this to allow some integer overflows/underflows in the inoise functions.
25 | // The original implementions allowed this, and had some discontinuties in the noise
26 | // output. It's technically an implementation bug, and was fixed, but you may wish
27 | // to preserve the old look and feel of the inoise functions in your existing animations.
28 | // The default is 0: NO overflow, and 'continuous' noise output, aka the fixed way.
29 | // #define FASTLED_NOISE_ALLOW_AVERAGE_TO_OVERFLOW 0
30 | // #define FASTLED_NOISE_ALLOW_AVERAGE_TO_OVERFLOW 1
31 |
32 | // Use this toggle whether or not to use the 'fixed' FastLED scale8. The initial scale8
33 | // had a problem where scale8(255,255) would give you 254. This is now fixed, and that
34 | // fix is enabled by default. However, if for some reason you have code that is not
35 | // working right as a result of this (e.g. code that was expecting the old scale8 behavior)
36 | // you can disable it here.
37 | #define FASTLED_SCALE8_FIXED 1
38 | // #define FASTLED_SCALE8_FIXED 0
39 |
40 | // Use this toggle whether to use 'fixed' FastLED pixel blending, including ColorFromPalette.
41 | // The prior pixel blend functions had integer-rounding math errors that led to
42 | // small errors being inadvertently added to the low bits of blended colors, including colors
43 | // retrieved from color palettes using LINEAR_BLEND. This is now fixed, and the
44 | // fix is enabled by default. However, if for some reason you wish to run with the old
45 | // blending, including the integer rounding and color errors, you can disable the bugfix here.
46 | #define FASTLED_BLEND_FIXED 1
47 | // #define FASTLED_BLEND_FIXED 0
48 |
49 | // Use this toggle whether to use 'fixed' FastLED 8- and 16-bit noise functions.
50 | // The prior noise functions had some math errors that led to 'discontinuities' in the
51 | // output, which by definition should be smooth and continuous. The bug led to
52 | // noise function output that had 'edges' and glitches in it. This is now fixed, and the
53 | // fix is enabled by default. However, if for some reason you wish to run with the old
54 | // noise code, including the glitches, you can disable the bugfix here.
55 | #define FASTLED_NOISE_FIXED 1
56 | //#define FASTLED_NOISE_FIXED 0
57 |
58 | // Use this to determine how many times FastLED will attempt to re-transmit a frame if interrupted
59 | // for too long by interrupts.
60 | #ifndef FASTLED_INTERRUPT_RETRY_COUNT
61 | #define FASTLED_INTERRUPT_RETRY_COUNT 2
62 | #endif
63 |
64 | // Use this toggle to enable global brightness in contollers that support is (ADA102 and SK9822).
65 | // It changes how color scaling works and uses global brightness before scaling down color values.
66 | // This enable much more accurate color control on low brightness settings.
67 | //#define FASTLED_USE_GLOBAL_BRIGHTNESS 1
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/platforms/esp/32/fastpin_esp32.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | FASTLED_NAMESPACE_BEGIN
4 |
5 | template class _ESPPIN {
6 |
7 | public:
8 | typedef volatile uint32_t * port_ptr_t;
9 | typedef uint32_t port_t;
10 |
11 | inline static void setOutput() { pinMode(PIN, OUTPUT); }
12 | inline static void setInput() { pinMode(PIN, INPUT); }
13 |
14 | inline static void hi() __attribute__ ((always_inline)) {
15 | if (PIN < 32) GPIO.out_w1ts = MASK;
16 | else GPIO.out1_w1ts.val = MASK;
17 | }
18 |
19 | inline static void lo() __attribute__ ((always_inline)) {
20 | if (PIN < 32) GPIO.out_w1tc = MASK;
21 | else GPIO.out1_w1tc.val = MASK;
22 | }
23 |
24 | inline static void set(register port_t val) __attribute__ ((always_inline)) {
25 | if (PIN < 32) GPIO.out = val;
26 | else GPIO.out1.val = val;
27 | }
28 |
29 | inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); }
30 |
31 | inline static void toggle() __attribute__ ((always_inline)) {
32 | if(PIN < 32) { GPIO.out ^= MASK; }
33 | else { GPIO.out1.val ^=MASK; }
34 | }
35 |
36 | inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { hi(); }
37 | inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { lo(); }
38 | inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; }
39 |
40 | inline static port_t hival() __attribute__ ((always_inline)) {
41 | if (PIN < 32) return GPIO.out | MASK;
42 | else return GPIO.out1.val | MASK;
43 | }
44 |
45 | inline static port_t loval() __attribute__ ((always_inline)) {
46 | if (PIN < 32) return GPIO.out & ~MASK;
47 | else return GPIO.out1.val & ~MASK;
48 | }
49 |
50 | inline static port_ptr_t port() __attribute__ ((always_inline)) {
51 | if (PIN < 32) return &GPIO.out;
52 | else return &GPIO.out1.val;
53 | }
54 |
55 | inline static port_ptr_t sport() __attribute__ ((always_inline)) {
56 | if (PIN < 32) return &GPIO.out_w1ts;
57 | else return &GPIO.out1_w1ts.val;
58 | }
59 |
60 | inline static port_ptr_t cport() __attribute__ ((always_inline)) {
61 | if (PIN < 32) return &GPIO.out_w1tc;
62 | else return &GPIO.out1_w1tc.val;
63 | }
64 |
65 | inline static port_t mask() __attribute__ ((always_inline)) { return MASK; }
66 |
67 | inline static bool isset() __attribute__ ((always_inline)) {
68 | if (PIN < 32) return GPIO.out & MASK;
69 | else return GPIO.out1.val & MASK;
70 | }
71 | };
72 |
73 | #define _FL_DEFPIN(PIN) template<> class FastPin : public _ESPPIN {};
74 |
75 | _FL_DEFPIN(0);
76 | _FL_DEFPIN(1); // WARNING: Using TX causes flashiness when uploading
77 | _FL_DEFPIN(2);
78 | _FL_DEFPIN(3); // WARNING: Using RX causes flashiness when uploading
79 | _FL_DEFPIN(4);
80 | _FL_DEFPIN(5);
81 |
82 | // -- These pins are not safe to use:
83 | // _FL_DEFPIN(6,6); _FL_DEFPIN(7,7); _FL_DEFPIN(8,8);
84 | // _FL_DEFPIN(9,9); _FL_DEFPIN(10,10); _FL_DEFPIN(11,11);
85 |
86 | _FL_DEFPIN(12);
87 | _FL_DEFPIN(13);
88 | _FL_DEFPIN(14);
89 | _FL_DEFPIN(15);
90 | _FL_DEFPIN(16);
91 | _FL_DEFPIN(17);
92 | _FL_DEFPIN(18);
93 | _FL_DEFPIN(19);
94 |
95 | // No pin 20 : _FL_DEFPIN(20,20);
96 |
97 | _FL_DEFPIN(21); // Works, but note that GPIO21 is I2C SDA
98 | _FL_DEFPIN(22); // Works, but note that GPIO22 is I2C SCL
99 | _FL_DEFPIN(23);
100 |
101 | // No pin 24 : _FL_DEFPIN(24,24);
102 |
103 | _FL_DEFPIN(25);
104 | _FL_DEFPIN(26);
105 | _FL_DEFPIN(27);
106 |
107 | // No pin 28-31: _FL_DEFPIN(28,28); _FL_DEFPIN(29,29); _FL_DEFPIN(30,30); _FL_DEFPIN(31,31);
108 |
109 | // Need special handling for pins > 31
110 | _FL_DEFPIN(32);
111 | _FL_DEFPIN(33);
112 |
113 | #define HAS_HARDWARE_PIN_SUPPORT
114 |
115 | FASTLED_NAMESPACE_END
116 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/hsv2rgb.h:
--------------------------------------------------------------------------------
1 | #ifndef __INC_HSV2RGB_H
2 | #define __INC_HSV2RGB_H
3 |
4 | #include "FastLED.h"
5 |
6 | #include "pixeltypes.h"
7 |
8 | FASTLED_NAMESPACE_BEGIN
9 |
10 | // hsv2rgb_rainbow - convert a hue, saturation, and value to RGB
11 | // using a visually balanced rainbow (vs a straight
12 | // mathematical spectrum).
13 | // This 'rainbow' yields better yellow and orange
14 | // than a straight 'spectrum'.
15 | //
16 | // NOTE: here hue is 0-255, not just 0-191
17 |
18 | void hsv2rgb_rainbow( const struct CHSV& hsv, struct CRGB& rgb);
19 | void hsv2rgb_rainbow( const struct CHSV* phsv, struct CRGB * prgb, int numLeds);
20 | #define HUE_MAX_RAINBOW 255
21 |
22 |
23 | // hsv2rgb_spectrum - convert a hue, saturation, and value to RGB
24 | // using a mathematically straight spectrum (vs
25 | // a visually balanced rainbow).
26 | // This 'spectrum' will have more green & blue
27 | // than a 'rainbow', and less yellow and orange.
28 | //
29 | // NOTE: here hue is 0-255, not just 0-191
30 |
31 | void hsv2rgb_spectrum( const struct CHSV& hsv, struct CRGB& rgb);
32 | void hsv2rgb_spectrum( const struct CHSV* phsv, struct CRGB * prgb, int numLeds);
33 | #define HUE_MAX_SPECTRUM 255
34 |
35 |
36 | // hsv2rgb_raw - convert hue, saturation, and value to RGB.
37 | // This 'spectrum' conversion will be more green & blue
38 | // than a real 'rainbow', and the hue is specified just
39 | // in the range 0-191. Together, these result in a
40 | // slightly faster conversion speed, at the expense of
41 | // color balance.
42 | //
43 | // NOTE: Hue is 0-191 only!
44 | // Saturation & value are 0-255 each.
45 | //
46 |
47 | void hsv2rgb_raw(const struct CHSV& hsv, struct CRGB & rgb);
48 | void hsv2rgb_raw(const struct CHSV* phsv, struct CRGB * prgb, int numLeds);
49 | #define HUE_MAX 191
50 |
51 |
52 | // rgb2hsv_approximate - recover _approximate_ HSV values from RGB.
53 | //
54 | // NOTE 1: This function is a long-term work in process; expect
55 | // results to change slightly over time as this function is
56 | // refined and improved.
57 | //
58 | // NOTE 2: This function is most accurate when the input is an
59 | // RGB color that came from a fully-saturated HSV color to start
60 | // with. E.g. CHSV( hue, 255, 255) -> CRGB -> CHSV will give
61 | // best results.
62 | //
63 | // NOTE 3: This function is not nearly as fast as HSV-to-RGB.
64 | // It is provided for those situations when the need for this
65 | // function cannot be avoided, or when extremely high performance
66 | // is not needed.
67 | //
68 | // NOTE 4: Why is this 'only' an "approximation"?
69 | // Not all RGB colors have HSV equivalents! For example, there
70 | // is no HSV value that will ever convert to RGB(255,255,0) using
71 | // the code provided in this library. So if you try to
72 | // convert RGB(255,255,0) 'back' to HSV, you'll necessarily get
73 | // only an approximation. Emphasis has been placed on getting
74 | // the 'hue' as close as usefully possible, but even that's a bit
75 | // of a challenge. The 8-bit HSV and 8-bit RGB color spaces
76 | // are not a "bijection".
77 | //
78 | // Nevertheless, this function does a pretty good job, particularly
79 | // at recovering the 'hue' from fully saturated RGB colors that
80 | // originally came from HSV rainbow colors. So if you start
81 | // with CHSV(hue_in,255,255), and convert that to RGB, and then
82 | // convert it back to HSV using this function, the resulting output
83 | // hue will either exactly the same, or very close (+/-1).
84 | // The more desaturated the original RGB color is, the rougher the
85 | // approximation, and the less accurate the results.
86 | //
87 | CHSV rgb2hsv_approximate( const CRGB& rgb);
88 |
89 | FASTLED_NAMESPACE_END
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/power_mgt.h:
--------------------------------------------------------------------------------
1 | #ifndef POWER_MGT_H
2 | #define POWER_MGT_H
3 |
4 | #include "FastLED.h"
5 |
6 | #include "pixeltypes.h"
7 |
8 | FASTLED_NAMESPACE_BEGIN
9 |
10 | ///@defgroup Power Power management functions
11 | /// functions used to limit the amount of power used by FastLED
12 | ///@{
13 |
14 | // Power Control setup functions
15 | //
16 | // Example:
17 | // set_max_power_in_volts_and_milliamps( 5, 400);
18 | //
19 |
20 | /// Set the maximum power used in milliamps for a given voltage
21 | /// @deprecated - use FastLED.setMaxPowerInVoltsAndMilliamps()
22 | void set_max_power_in_volts_and_milliamps( uint8_t volts, uint32_t milliamps);
23 | /// Set the maximum power used in watts
24 | /// @deprecated - use FastLED.setMaxPowerInMilliWatts
25 | void set_max_power_in_milliwatts( uint32_t powerInmW);
26 |
27 | /// Select a pin with an led that will be flashed to indicate that power management
28 | /// is pulling down the brightness
29 | void set_max_power_indicator_LED( uint8_t pinNumber); // zero = no indicator LED
30 |
31 |
32 | // Power Control 'show' and 'delay' functions
33 | //
34 | // These are drop-in replacements for FastLED.show() and FastLED.delay()
35 | // In order to use these, you have to actually replace your calls to
36 | // FastLED.show() and FastLED.delay() with these two functions.
37 | //
38 | // Example:
39 | // // was: FastLED.show();
40 | // // now is:
41 | // show_at_max_brightness_for_power();
42 | //
43 |
44 | /// Similar to FastLED.show, but pre-adjusts brightness to keep below the power
45 | /// threshold.
46 | /// @deprecated this has now been moved to FastLED.show();
47 | void show_at_max_brightness_for_power();
48 | /// Similar to FastLED.delay, but pre-adjusts brightness to keep below the power
49 | /// threshold.
50 | /// @deprecated this has now been rolled into FastLED.delay();
51 | void delay_at_max_brightness_for_power( uint16_t ms);
52 |
53 |
54 | // Power Control internal helper functions
55 |
56 | /// calculate_unscaled_power_mW tells you how many milliwatts the current
57 | /// LED data would draw at brightness = 255.
58 | ///
59 | uint32_t calculate_unscaled_power_mW( const CRGB* ledbuffer, uint16_t numLeds);
60 |
61 | /// calculate_max_brightness_for_power_mW tells you the highest brightness
62 | /// level you can use and still stay under the specified power budget for
63 | /// a given set of leds. It takes a pointer to an array of CRGB objects, a
64 | /// count, a 'target brightness' which is the brightness you'd ideally like
65 | /// to use, and the max power draw desired in milliwatts. The result from
66 | /// this function will be no higher than the target_brightess you supply, but may be lower.
67 | uint8_t calculate_max_brightness_for_power_mW(const CRGB* ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_mW);
68 |
69 | /// calculate_max_brightness_for_power_mW tells you the highest brightness
70 | /// level you can use and still stay under the specified power budget for
71 | /// a given set of leds. It takes a pointer to an array of CRGB objects, a
72 | /// count, a 'target brightness' which is the brightness you'd ideally like
73 | /// to use, and the max power in volts and milliamps. The result from this
74 | /// function will be no higher than the target_brightess you supply, but may be lower.
75 | uint8_t calculate_max_brightness_for_power_vmA(const CRGB* ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_V, uint32_t max_power_mA);
76 |
77 | /// calculate_max_brightness_for_power_mW tells you the highest brightness
78 | /// level you can use and still stay under the specified power budget. It
79 | /// takes a 'target brightness' which is the brightness you'd ideally like
80 | /// to use. The result from this function will be no higher than the
81 | /// target_brightess you supply, but may be lower.
82 | uint8_t calculate_max_brightness_for_power_mW( uint8_t target_brightness, uint32_t max_power_mW);
83 |
84 | FASTLED_NAMESPACE_END
85 | ///@}
86 | // POWER_MGT_H
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/platforms/esp/8266/clockless_esp8266.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | FASTLED_NAMESPACE_BEGIN
4 |
5 | #ifdef FASTLED_DEBUG_COUNT_FRAME_RETRIES
6 | extern uint32_t _frame_cnt;
7 | extern uint32_t _retry_cnt;
8 | #endif
9 |
10 | // Info on reading cycle counter from https://github.com/kbeckmann/nodemcu-firmware/blob/ws2812-dual/app/modules/ws2812.c
11 | __attribute__ ((always_inline)) inline static uint32_t __clock_cycles() {
12 | uint32_t cyc;
13 | __asm__ __volatile__ ("rsr %0,ccount":"=a" (cyc));
14 | return cyc;
15 | }
16 |
17 | #define FASTLED_HAS_CLOCKLESS 1
18 |
19 | template
20 | class ClocklessController : public CPixelLEDController {
21 | typedef typename FastPin::port_ptr_t data_ptr_t;
22 | typedef typename FastPin::port_t data_t;
23 |
24 | data_t mPinMask;
25 | data_ptr_t mPort;
26 | CMinWait mWait;
27 | public:
28 | virtual void init() {
29 | FastPin::setOutput();
30 | mPinMask = FastPin::mask();
31 | mPort = FastPin::port();
32 | }
33 |
34 | virtual uint16_t getMaxRefreshRate() const { return 400; }
35 |
36 | protected:
37 |
38 | virtual void showPixels(PixelController & pixels) {
39 | // mWait.wait();
40 | int cnt = FASTLED_INTERRUPT_RETRY_COUNT;
41 | while((showRGBInternal(pixels)==0) && cnt--) {
42 | #ifdef FASTLED_DEBUG_COUNT_FRAME_RETRIES
43 | _retry_cnt++;
44 | #endif
45 | os_intr_unlock();
46 | delayMicroseconds(WAIT_TIME);
47 | os_intr_lock();
48 | }
49 | // mWait.mark();
50 | }
51 |
52 | #define _ESP_ADJ (0)
53 | #define _ESP_ADJ2 (0)
54 |
55 | template __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & last_mark, register uint32_t b) {
56 | b <<= 24; b = ~b;
57 | for(register uint32_t i = BITS; i > 0; i--) {
58 | while((__clock_cycles() - last_mark) < (T1+T2+T3));
59 | last_mark = __clock_cycles();
60 | FastPin::hi();
61 |
62 | while((__clock_cycles() - last_mark) < T1);
63 | if(b & 0x80000000L) { FastPin::lo(); }
64 | b <<= 1;
65 |
66 | while((__clock_cycles() - last_mark) < (T1+T2));
67 | FastPin::lo();
68 | }
69 | }
70 |
71 | // This method is made static to force making register Y available to use for data on AVR - if the method is non-static, then
72 | // gcc will use register Y for the this pointer.
73 | static uint32_t ICACHE_RAM_ATTR showRGBInternal(PixelController pixels) {
74 | // Setup the pixel controller and load/scale the first byte
75 | pixels.preStepFirstByteDithering();
76 | register uint32_t b = pixels.loadAndScale0();
77 | pixels.preStepFirstByteDithering();
78 | os_intr_lock();
79 | uint32_t start = __clock_cycles();
80 | uint32_t last_mark = start;
81 | while(pixels.has(1)) {
82 | // Write first byte, read next byte
83 | writeBits<8+XTRA0>(last_mark, b);
84 | b = pixels.loadAndScale1();
85 |
86 | // Write second byte, read 3rd byte
87 | writeBits<8+XTRA0>(last_mark, b);
88 | b = pixels.loadAndScale2();
89 |
90 | // Write third byte, read 1st byte of next pixel
91 | writeBits<8+XTRA0>(last_mark, b);
92 | b = pixels.advanceAndLoadAndScale0();
93 |
94 | #if (FASTLED_ALLOW_INTERRUPTS == 1)
95 | os_intr_unlock();
96 | #endif
97 |
98 | pixels.stepDithering();
99 |
100 | #if (FASTLED_ALLOW_INTERRUPTS == 1)
101 | os_intr_lock();
102 | // if interrupts took longer than 45µs, punt on the current frame
103 | if((int32_t)(__clock_cycles()-last_mark) > 0) {
104 | if((int32_t)(__clock_cycles()-last_mark) > (T1+T2+T3+((WAIT_TIME-INTERRUPT_THRESHOLD)*CLKS_PER_US))) { sei(); return 0; }
105 | }
106 | #endif
107 | };
108 |
109 | os_intr_unlock();
110 | #ifdef FASTLED_DEBUG_COUNT_FRAME_RETRIES
111 | _frame_cnt++;
112 | #endif
113 | return __clock_cycles() - start;
114 | }
115 | };
116 |
117 | FASTLED_NAMESPACE_END
118 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/examples/DemoReel100/DemoReel100.ino:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | FASTLED_USING_NAMESPACE
4 |
5 | // FastLED "100-lines-of-code" demo reel, showing just a few
6 | // of the kinds of animation patterns you can quickly and easily
7 | // compose using FastLED.
8 | //
9 | // This example also shows one easy way to define multiple
10 | // animations patterns and have them automatically rotate.
11 | //
12 | // -Mark Kriegsman, December 2014
13 |
14 | #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
15 | #warning "Requires FastLED 3.1 or later; check github for latest code."
16 | #endif
17 |
18 | #define DATA_PIN 3
19 | //#define CLK_PIN 4
20 | #define LED_TYPE WS2811
21 | #define COLOR_ORDER GRB
22 | #define NUM_LEDS 64
23 | CRGB leds[NUM_LEDS];
24 |
25 | #define BRIGHTNESS 96
26 | #define FRAMES_PER_SECOND 120
27 |
28 | void setup() {
29 | delay(3000); // 3 second delay for recovery
30 |
31 | // tell FastLED about the LED strip configuration
32 | FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
33 | //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
34 |
35 | // set master brightness control
36 | FastLED.setBrightness(BRIGHTNESS);
37 | }
38 |
39 |
40 | // List of patterns to cycle through. Each is defined as a separate function below.
41 | typedef void (*SimplePatternList[])();
42 | SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
43 |
44 | uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
45 | uint8_t gHue = 0; // rotating "base color" used by many of the patterns
46 |
47 | void loop()
48 | {
49 | // Call the current pattern function once, updating the 'leds' array
50 | gPatterns[gCurrentPatternNumber]();
51 |
52 | // send the 'leds' array out to the actual LED strip
53 | FastLED.show();
54 | // insert a delay to keep the framerate modest
55 | FastLED.delay(1000/FRAMES_PER_SECOND);
56 |
57 | // do some periodic updates
58 | EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
59 | EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
60 | }
61 |
62 | #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
63 |
64 | void nextPattern()
65 | {
66 | // add one to the current pattern number, and wrap around at the end
67 | gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
68 | }
69 |
70 | void rainbow()
71 | {
72 | // FastLED's built-in rainbow generator
73 | fill_rainbow( leds, NUM_LEDS, gHue, 7);
74 | }
75 |
76 | void rainbowWithGlitter()
77 | {
78 | // built-in FastLED rainbow, plus some random sparkly glitter
79 | rainbow();
80 | addGlitter(80);
81 | }
82 |
83 | void addGlitter( fract8 chanceOfGlitter)
84 | {
85 | if( random8() < chanceOfGlitter) {
86 | leds[ random16(NUM_LEDS) ] += CRGB::White;
87 | }
88 | }
89 |
90 | void confetti()
91 | {
92 | // random colored speckles that blink in and fade smoothly
93 | fadeToBlackBy( leds, NUM_LEDS, 10);
94 | int pos = random16(NUM_LEDS);
95 | leds[pos] += CHSV( gHue + random8(64), 200, 255);
96 | }
97 |
98 | void sinelon()
99 | {
100 | // a colored dot sweeping back and forth, with fading trails
101 | fadeToBlackBy( leds, NUM_LEDS, 20);
102 | int pos = beatsin16( 13, 0, NUM_LEDS-1 );
103 | leds[pos] += CHSV( gHue, 255, 192);
104 | }
105 |
106 | void bpm()
107 | {
108 | // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
109 | uint8_t BeatsPerMinute = 62;
110 | CRGBPalette16 palette = PartyColors_p;
111 | uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
112 | for( int i = 0; i < NUM_LEDS; i++) { //9948
113 | leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
114 | }
115 | }
116 |
117 | void juggle() {
118 | // eight colored dots, weaving in and out of sync with each other
119 | fadeToBlackBy( leds, NUM_LEDS, 20);
120 | byte dothue = 0;
121 | for( int i = 0; i < 8; i++) {
122 | leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
123 | dothue += 32;
124 | }
125 | }
126 |
127 |
--------------------------------------------------------------------------------
/Arduino/lib/FastLED-master/examples/SmartMatrix/SmartMatrix.ino:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define kMatrixWidth 32
5 | #define kMatrixHeight 32
6 | const bool kMatrixSerpentineLayout = false;
7 |
8 | #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
9 |
10 | CRGB leds[kMatrixWidth * kMatrixHeight];
11 |
12 |
13 | uint16_t XY( uint8_t x, uint8_t y)
14 | {
15 | uint16_t i;
16 |
17 | if( kMatrixSerpentineLayout == false) {
18 | i = (y * kMatrixWidth) + x;
19 | }
20 |
21 | if( kMatrixSerpentineLayout == true) {
22 | if( y & 0x01) {
23 | // Odd rows run backwards
24 | uint8_t reverseX = (kMatrixWidth - 1) - x;
25 | i = (y * kMatrixWidth) + reverseX;
26 | } else {
27 | // Even rows run forwards
28 | i = (y * kMatrixWidth) + x;
29 | }
30 | }
31 |
32 | return i;
33 | }
34 |
35 | // The 32bit version of our coordinates
36 | static uint16_t x;
37 | static uint16_t y;
38 | static uint16_t z;
39 |
40 | // We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
41 | // use the z-axis for "time". speed determines how fast time moves forward. Try
42 | // 1 for a very slow moving effect, or 60 for something that ends up looking like
43 | // water.
44 | // uint16_t speed = 1; // almost looks like a painting, moves very slowly
45 | uint16_t speed = 20; // a nice starting speed, mixes well with a scale of 100
46 | // uint16_t speed = 33;
47 | // uint16_t speed = 100; // wicked fast!
48 |
49 | // Scale determines how far apart the pixels in our noise matrix are. Try
50 | // changing these values around to see how it affects the motion of the display. The
51 | // higher the value of scale, the more "zoomed out" the noise iwll be. A value
52 | // of 1 will be so zoomed in, you'll mostly see solid colors.
53 |
54 | // uint16_t scale = 1; // mostly just solid colors
55 | // uint16_t scale = 4011; // very zoomed out and shimmery
56 | uint16_t scale = 31;
57 |
58 | // This is the array that we keep our computed noise values in
59 | uint8_t noise[kMatrixWidth][kMatrixHeight];
60 |
61 | void setup() {
62 | // uncomment the following lines if you want to see FPS count information
63 | // Serial.begin(38400);
64 | // Serial.println("resetting!");
65 | delay(3000);
66 | LEDS.addLeds(leds,NUM_LEDS);
67 | LEDS.setBrightness(96);
68 |
69 | // Initialize our coordinates to some random values
70 | x = random16();
71 | y = random16();
72 | z = random16();
73 |
74 | // Show off smart matrix scrolling text
75 | pSmartMatrix->setScrollMode(wrapForward);
76 | pSmartMatrix->setScrollColor({0xff, 0xff, 0xff});
77 | pSmartMatrix->setScrollSpeed(15);
78 | pSmartMatrix->setScrollFont(font6x10);
79 | pSmartMatrix->scrollText("Smart Matrix & FastLED", -1);
80 | pSmartMatrix->setScrollOffsetFromEdge(10);
81 | }
82 |
83 | // Fill the x/y array of 8-bit noise values using the inoise8 function.
84 | void fillnoise8() {
85 | for(int i = 0; i < kMatrixWidth; i++) {
86 | int ioffset = scale * i;
87 | for(int j = 0; j < kMatrixHeight; j++) {
88 | int joffset = scale * j;
89 | noise[i][j] = inoise8(x + ioffset,y + joffset,z);
90 | }
91 | }
92 | z += speed;
93 | }
94 |
95 |
96 | void loop() {
97 | static uint8_t circlex = 0;
98 | static uint8_t circley = 0;
99 |
100 | static uint8_t ihue=0;
101 | fillnoise8();
102 | for(int i = 0; i < kMatrixWidth; i++) {
103 | for(int j = 0; j < kMatrixHeight; j++) {
104 | // We use the value at the (i,j) coordinate in the noise
105 | // array for our brightness, and the flipped value from (j,i)
106 | // for our pixel's hue.
107 | leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
108 |
109 | // You can also explore other ways to constrain the hue used, like below
110 | // leds[XY(i,j)] = CHSV(ihue + (noise[j][i]>>2),255,noise[i][j]);
111 | }
112 | }
113 | ihue+=1;
114 |
115 | // N.B. this requires SmartMatrix modified w/triple buffering support
116 | pSmartMatrix->fillCircle(circlex % 32,circley % 32,6,CRGB(CHSV(ihue+128,255,255)));
117 | circlex += random16(2);
118 | circley += random16(2);
119 | LEDS.show();
120 | // delay(10);
121 | }
122 |
--------------------------------------------------------------------------------