Skip to content

Commit 4115c3a

Browse files
committed
* Version 2.0
-UPDATES: * Arduino will now read a full string of characters rather than a single byte from Serial. * Add Arduino function clr() for custom color (in this version it has special code to compensate for differing strips on the same data pin.) * Add CUSTOM COLOR option to ArduinoCommander, clicking it will spawn a color pallet, once you select the color it will send it to the arduino. - DEBUG FEATURES: * ArduinoCommander will now read from Serial port and output to the debug console (this may result in slightly lower performance but better data accuracy and debugging for custom functions and communication) * Expand Serial Output from Arduino.
1 parent dba7007 commit 4115c3a

4 files changed

Lines changed: 330 additions & 186 deletions

File tree

Script For Arduino/DemoReel100/DemoReel100.ino

Lines changed: 116 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,38 @@ FASTLED_USING_NAMESPACE
1414
//#define CLK_PIN 4
1515
#define LED_TYPE TM1803
1616
#define COLOR_ORDER GBR
17-
#define NUM_LEDS 10
17+
#define NUM_LEDS 20
1818
CRGB leds[NUM_LEDS];
1919

2020
#define BRIGHTNESS 96
2121
#define FRAMES_PER_SECOND 120
2222

23-
byte incomingByte;
24-
uint16_t gCurrentBrightness = 96;
2523

24+
// COOLING: How much does the air cool as it rises?
25+
// Less cooling = taller flames. More cooling = shorter flames.
26+
// Default 50, suggested range 20-100
27+
#define COOLING 55
28+
29+
// SPARKING: What chance (out of 255) is there that a new spark will be lit?
30+
// Higher chance = more roaring fire. Lower chance = more flickery fire.
31+
// Default 120, suggested range 50-200.
32+
#define SPARKING 120
33+
34+
char incomingString[50];
35+
char hh[6];
36+
String incomingStr;
37+
char ccc[50];
38+
uint16_t gCurrentBrightness = 255;
39+
unsigned long hexo = 0x0;
40+
unsigned long hexor = 0x0;
2641
void setup() {
2742
delay(3000); // 3 second delay for recovery
2843

2944
// tell FastLED about the LED strip configuration
3045
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
46+
//FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, 0, 10).setCorrection(TypicalLEDStrip);
47+
48+
//FastLED.addLeds<LED_TYPE,DATA_PIN,RBG>(leds, NUM_LEDS, NUM_LEDS).setCorrection(TypicalLEDStrip);
3149
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
3250

3351
// set master brightness control
@@ -39,83 +57,114 @@ void setup() {
3957

4058
// List of patterns to cycle through. Each is defined as a separate function below.
4159
typedef void (*SimplePatternList[])();
42-
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
60+
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm, fire, clr };
4361

4462
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
4563
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
4664

4765
bool on = true;
4866
bool cycle = false;
4967

68+
69+
70+
5071
void loop()
5172
{
73+
random16_add_entropy( random());
5274
if (Serial.available() > 0) {
53-
incomingByte = Serial.read();
54-
if (incomingByte == '*') {
75+
incomingStr = Serial.readString();
76+
incomingStr.toCharArray(incomingString,50);
77+
returnSignal(incomingString);
78+
if (incomingString[0]== '*') {
5579
nextPattern();
5680
}
57-
if (incomingByte == '-') {
81+
if (incomingString[0] == '-') {
5882
if (on){
5983
on = false;
6084
FastLED.setBrightness(0);
6185
FastLED.show();
62-
returnSignal('b');
86+
returnSignal("b");
6387
}
6488
else{
6589
on = true;
6690
FastLED.setBrightness(gCurrentBrightness);
67-
returnSignal('a');
91+
returnSignal("a");
6892
}
6993
}
70-
if (incomingByte == '1') {
94+
if (incomingString[0] == '1') {
7195
gCurrentPatternNumber = 0;
7296
}
73-
if (incomingByte == '2') {
97+
if (incomingString[0] == '2') {
7498
gCurrentPatternNumber = 1;
7599
}
76-
if (incomingByte == '3') {
100+
if (incomingString[0] == '3') {
77101
gCurrentPatternNumber = 2;
78102
}
79-
if (incomingByte == '4') {
103+
if (incomingString[0] == '4') {
80104
gCurrentPatternNumber = 3;
81105
}
82-
if (incomingByte == '5') {
106+
if (incomingString[0] == '5') {
83107
gCurrentPatternNumber = 4;
84108
}
85-
if (incomingByte == '6') {
109+
if (incomingString[0] == '6') {
86110
gCurrentPatternNumber = 5;
87111
}
88-
if (incomingByte == 'B') {
112+
if (incomingString[0] == '7') {
113+
gCurrentPatternNumber = 6;
114+
}
115+
if (incomingString[0] == 'B') {
89116
gCurrentBrightness = (gCurrentBrightness + 10);
90117
if (gCurrentBrightness > 255)
91118
{
92119
gCurrentBrightness = 255;
93120
}
94121
FastLED.setBrightness(gCurrentBrightness);
95122
}
96-
if (incomingByte == 'D') {
123+
if (incomingString[0] == 'D') {
97124
gCurrentBrightness = (gCurrentBrightness - 10);
98125
if (gCurrentBrightness < 0)
99126
{
100127
gCurrentBrightness = 0;
101128
}
102129
FastLED.setBrightness(gCurrentBrightness);
103130
}
104-
if (incomingByte == 'C'){
131+
if (incomingString[0] == 'C'){
105132

106133
if (cycle){
107134
feedbackFlash();
108135
feedbackFlash();
109136
cycle = false;
110-
returnSignal('d');
137+
returnSignal("d");
111138
}
112139
else{
113140
feedbackFlash();
114141
cycle = true;
115-
returnSignal('c');
142+
returnSignal("c");
116143
}
117144

118145
}
146+
if (incomingString[0] == 'R'){
147+
char n[8], m[8];
148+
char *p, *q;
149+
n[0] = incomingString[4];
150+
n[1] = incomingString[5];
151+
n[2] = incomingString[6];
152+
n[3] = incomingString[7];
153+
n[4] = incomingString[8];
154+
n[5] = incomingString[9];
155+
156+
m[0] = incomingString[6];
157+
m[1] = incomingString[7];
158+
m[2] = incomingString[4];
159+
m[3] = incomingString[5];
160+
m[4] = incomingString[8];
161+
m[5] = incomingString[9];
162+
returnSignal(n);
163+
hexo = strtoul(n, &p, 16);
164+
hexor = strtoul(m, &q, 16);
165+
returnSignal2(hexo);
166+
gCurrentPatternNumber = 7;
167+
}
119168
}
120169
// Call the current pattern function once, updating the 'leds' array
121170
gPatterns[gCurrentPatternNumber]();
@@ -135,6 +184,44 @@ void loop()
135184

136185
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
137186

187+
void clr()
188+
{
189+
for( int i = 0; i < 20; i++) {
190+
leds[i]= hexo;
191+
}
192+
for( int i = 10; i < 20; i++) {
193+
leds[i]= hexor;
194+
195+
}
196+
FastLED.show();
197+
}
198+
void fire()
199+
{
200+
// Array of temperature readings at each simulation cell
201+
static byte heat[NUM_LEDS];
202+
203+
// Step 1. Cool down every cell a little
204+
for( int i = 0; i < NUM_LEDS; i++) {
205+
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
206+
}
207+
208+
// Step 2. Heat from each cell drifts 'up' and diffuses a little
209+
for( int k= NUM_LEDS - 1; k >= 2; k--) {
210+
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
211+
}
212+
213+
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
214+
if( random8() < SPARKING ) {
215+
int y = random8(7);
216+
heat[y] = qadd8( heat[y], random8(160,255) );
217+
}
218+
219+
// Step 4. Map from heat cells to LED colors
220+
for( int j = 0; j < NUM_LEDS; j++) {
221+
leds[j] = HeatColor( heat[j]);
222+
}
223+
}
224+
138225
void nextPattern()
139226
{
140227
// add one to the current pattern number, and wrap around at the end
@@ -198,10 +285,16 @@ void juggle() {
198285
}
199286
}
200287

201-
void returnSignal(byte sig){
202-
Serial.write(sig);
288+
void returnSignal(char* sig){
289+
char out[50];
290+
sprintf(out, "rcv: %s", sig);
291+
Serial.write(out);
292+
}
293+
void returnSignal2(unsigned long sig){
294+
char out[50];
295+
sprintf(out, "rcv: %x", sig);
296+
Serial.println(out);
203297
}
204-
205298
void feedbackFlash() {
206299
FastLED.setBrightness(255);
207300
fill_solid(leds, NUM_LEDS, CRGB::White);

0 commit comments

Comments
 (0)