-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathdouble_up_pixels_example.ino
109 lines (92 loc) · 3.8 KB
/
double_up_pixels_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
101
102
103
104
105
106
107
108
109
//***************************************************************
// double up pixels for DMX example
// Once running, open the serial monitor to see what's happening.
//
// Marc Miller, 2015
//***************************************************************
#include "FastLED.h"
#define LED_TYPE NEOPIXEL
#define DATA_PIN 6 // Update for your pin number
#define NUM_LEDS 12 // Update to number of pixels in your LED strip
CRGB leds[NUM_LEDS];
// For DMX, the R,G,B for each pixel will be assigned a channel number, thus:
uint16_t DMXchan = 3*NUM_LEDS; // Number of DMX channels.
// Actually, the above would only need to be half of 3*NUM_LEDS since we are
// doubling pixels up for this test, but I'm not worrying about that.
uint16_t pixel = 0; // for storing a pixel number
uint16_t chanR = 0; // for storing the Red channel value
uint16_t chanG = 0; // for storing the Green channel value
uint16_t chanB = 0; // for storing the Blue channel value
//---------------------------------------------------------------
void setup(){
delay(1000); // Power-up delay
Serial.begin(57600); // Allows serial monitor output (check baud rate)
FastLED.addLeds<LED_TYPE,DATA_PIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
}
//---------------------------------------------------------------
void loop(){
Serial.println("...........................................................");
for (pixel = 0; pixel < NUM_LEDS; pixel++){
if ((pixel & 0x01) == 0){ // Checks least significant bit to determine if even or odd
// pixel number is an even
Serial.print(" pixel "); Serial.print(pixel); Serial.print(" assigned: ");
for (uint8_t c = 0; c < 3; c++){
DMXchan = 3*((pixel+2)/2)-2+c;
Serial.print(" chan="); Serial.print(DMXchan);
}
delay(50);
} else {
// pixel number is odd number
Serial.print(" pixel "); Serial.print(pixel); Serial.print(" assigned: ");
for (uint8_t c = 0; c < 3; c++){
DMXchan = 3*((pixel+1)/2)-2+c;
Serial.print(" chan="); Serial.print(DMXchan);
}
delay(50);
Serial.println(" ");
}
Serial.println(" ");
}
delay(200);
//================================================================
// Read incoming serial DMX data.
// Figure out pixel number based on incomming DMX channel number.
//================================================================
Serial.println("******[SIMULATING RECEIVING CHANNELS, EACH WITH VALUE 255]******");
int count = 0; // Using count to switch between R,G, and B LEDs in each pixel.
// Starting chan at 1, and adding +1 to DMXchan since DMX protocol has channels start at 1.
for (uint16_t chan = 1; chan < DMXchan+1; chan++){
pixel = ((chan+2)/3*2)-2; // Calculate what pixel the incoming channel belongs to.
Serial.print(" DMXChan "); Serial.print(chan);
Serial.print(" goes to pixel "); Serial.print(pixel);
if (count == 0){
Serial.print(" Adding R value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" ");
chanR = 255;
chanG = 0;
chanB = 0;
}
if (count == 1){
Serial.print(" Adding G value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" ");
chanG = 255;
}
if (count == 2){
Serial.print(" Adding B value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" ");
chanB = 255;
}
count++;
leds[pixel] = CRGB(chanR,chanG,chanB);
FastLED.show();
delay(200);
leds[pixel+1] = CRGB(chanR,chanG,chanB); // Dublicate color to next pixel
FastLED.show();
delay(700);
if (count == 3){
leds[pixel] = CRGB::Black;
leds[pixel+1] = CRGB::Black;
FastLED.show();
}
if (count > 2){count = 0;}
}
delay(500);
Serial.println(" ");
} // ----End main loop----