forked from marmilicious/FastLED_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemmove8_example.ino
101 lines (77 loc) · 3.21 KB
/
memmove8_example.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//***************************************************************
// Example of using memmove8 to transfer pixel data around.
//
// A temp CRGB array is filled with a rainbow. That color data is
// then copied from temp to leds every two seconds, alternating
// between a straight copy, and copying seperate sections of
// temp to different pixel locations in leds.
//
// The snytax for memmove8 is:
// memmove8( &destination[start position], &source[start position], size of pixel data )
//
// The above is written as "size of pixel data" instead of "number
// of pixels" because in this case it would be the number of
// pixels x 3. Three because our current CRGB has data for three
// color channels: RGB.
// In code we can write that as: pixels * sizeof(CRGB).
//
// Marc Miller, April 2018
//***************************************************************
#include "FastLED.h"
#define LED_TYPE LPD8806
#define DATA_PIN 11
#define CLOCK_PIN 13
#define COLOR_ORDER GRB
#define BRIGHTNESS 50
#define NUM_LEDS 32
CRGB leds[NUM_LEDS];
CRGB temp[NUM_LEDS];
boolean shuffle = true;
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(2000); // Startup delay
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
Serial.println("Setup done. \n");
}
//---------------------------------------------------------------
void loop() {
// Fill temp with some color data which will be tranfered to leds.
fill_rainbow(temp, NUM_LEDS, millis()/300, 256/NUM_LEDS);
EVERY_N_SECONDS(2) {
shuffle = !shuffle; //toggle true or false
Serial.print("shuffle = "); Serial.print(shuffle);
if (shuffle) {
ShufflePixels(); //copy from temp to leds with shuffling
Serial.println(" Pixels shuffled.");
} else {
CopyPixels(); //straight copy of temp to leds, no shuffling
Serial.println(" No change.");
}
FastLED.show(); //display leds
}//end EVERY_N
}//end_main_loop
//---------------------------------------------------------------
void CopyPixels() {
// Straight transfer of all temp pixel data to leds.
// This results in leds being exactly the same as temp.
memmove8( &leds, &temp, (NUM_LEDS)*sizeof(CRGB) );
}//end_CopyPixels
//---------------------------------------------------------------
void ShufflePixels() {
// Move pixel data from temp (specifing start position) to
// destination leds (specifing starting position), moving the
// data for X number of pixels.
// memmove8( &destination[start position], &source[start position], size of pixel data );
// move pixel data from temp 24-31 to leds 0-7.
memmove8( &leds[0], &temp[NUM_LEDS/4*3], (NUM_LEDS)*sizeof(CRGB)/4 );
// move pixel data from temp 16-23 to leds 8-15.
memmove8( &leds[NUM_LEDS/4], &temp[NUM_LEDS/4*2], (NUM_LEDS)*sizeof(CRGB)/4 );
// move pixel data from temp 8-15 to leds 16-23.
memmove8( &leds[NUM_LEDS/4*2], &temp[NUM_LEDS/4], (NUM_LEDS)*sizeof(CRGB)/4 );
// move pixel data from temp 0-7 to leds 24-31.
memmove8( &leds[NUM_LEDS/4*3], &temp[0], (NUM_LEDS)*sizeof(CRGB)/4 );
}//end_ShufflePixels