31 fPreviousEffect(~fDisplayEffect),
38 fPrevEffectSeqCount(0),
39 fEffectLengthMillis(0),
40 fEffectStartMillis(0),
43 fLC.setAllPower(
true);
76 fStatusMillis = millis();
88 fDisplayEffectVal = inputNum;
110 if (*cmd++ ==
'M' && *cmd++ ==
'P')
112 long int cmdvalue = 0;
114 while (*c >=
'0' && *c <=
'9')
116 cmdvalue = cmdvalue * 10 + (*c++ -
'0');
127 selectEffect((
long int)seq * 10000L + (
long int)speedScale * 100 + numSeconds);
135 bool timerExpired =
false;
136 unsigned long currentMillis = millis();
137 if (currentMillis - fStatusMillis >= fStatusDelay)
140 fStatusMillis = currentMillis;
141 fFlipFlop = !fFlipFlop;
142 fEffectSeqCount += fEffectSeqDir;
143 randomSeed(analogRead(A0));
146 int selectSequence = (fDisplayEffectVal % 1000000) / 10000;
148 int selectSpeed = (fDisplayEffectVal % 10000) / 100;
149 int selectLength = (fDisplayEffectVal % 100);
150 int defaultSpeed = 200;
152 switch (selectSequence)
182 fDisplayEffect = selectSequence;
183 if (fPreviousEffect != fDisplayEffect)
188 switch (selectSequence)
195 fEffectSeqCount = 0x7FFF;
198 fPrevEffectSeqCount = 0;
199 fStatusDelay = (selectSpeed) ? 100 * (selectSpeed) : defaultSpeed;
200 fEffectStartMillis = currentMillis;
201 fEffectLengthMillis = selectLength * 1000;
202 fLC.clearAllDisplays();
204 unsigned int effectMillis = currentMillis - fEffectStartMillis;
207 switch (fDisplayEffect)
214 if (fPreviousEffect != fDisplayEffect)
216 for (
int i = 0; i < 8; i++)
217 setRow(i, B11111111);
224 for (i = 0; i < 4; i++)
225 setRow(i, (!fFlipFlop) ? B11111111 : B00000000);
227 setRow(i, (!fFlipFlop) ? B00000000 : B11111111);
234 for (
int i = 0; i < 8; i++)
235 setRow(i, B11111111);
239 for (
int i = 0; i < 8; i++)
240 setRow(i, B00000000);
246 if (fPrevEffectSeqCount != fEffectSeqCount)
247 setCol(fPrevEffectSeqCount, 0);
248 if (fEffectSeqCount > 7)
251 fEffectSeqCount += fEffectSeqDir;
253 else if (fEffectSeqCount < 0)
256 fEffectSeqCount += fEffectSeqDir;
258 setCol(fEffectSeqCount, 1);
263 if (fPrevEffectSeqCount != fEffectSeqCount)
264 setRow(fPrevEffectSeqCount, B00000000);
265 if (fEffectSeqCount > 7)
268 fEffectSeqCount += fEffectSeqDir;
270 else if (fEffectSeqCount < 0)
273 fEffectSeqCount += fEffectSeqDir;
275 setRow(fEffectSeqCount, B11111111);
280 if (fPreviousEffect != fDisplayEffect)
282 for (
int i = 0; i < 8; i++)
283 setRow(i, random(255));
287 for (
int y = 0; y < 8; y++)
301 setPixel(random(8), random(8), 1);
308 const byte* ptr = getFrame_ExpandSolid(fEffectSeqCount, fEffectSeqDir);
309 for (
int i = 0; i < 8; i++, ptr++)
311 setRow(i, pgm_read_byte(ptr));
318 const byte* ptr = getFrame_ExpandHollow(fEffectSeqCount, fEffectSeqDir);
319 for (
int i = 0; i < 8; i++, ptr++)
321 setRow(i, pgm_read_byte(ptr));
328 const byte* ptr = getFrame_Q(fEffectSeqCount, fEffectSeqDir);
329 for (
int i = 0; i < 8; i++, ptr++)
331 setRow(i, pgm_read_byte(ptr));
337 unsigned count = fEffectSeqCount;
338 unsigned thousands = count / 1000;
339 count -= thousands*1000;
340 unsigned hundreds = count / 100;
341 count -= hundreds*100;
342 unsigned tens = count / 10;
344 unsigned ones = count;
350 memset(frame,
'\0',
sizeof(frame));
353 const byte* ptr = getFrame_Cistercian(thousands*1000);
354 for (
int i = 0; i < 8; i++, ptr++)
356 frame[i] |= pgm_read_byte(ptr);
361 const byte* ptr = getFrame_Cistercian(hundreds*100);
362 for (
int i = 0; i < 8; i++, ptr++)
364 frame[i] |= pgm_read_byte(ptr);
369 const byte* ptr = getFrame_Cistercian(tens*10);
370 for (
int i = 0; i < 8; i++, ptr++)
372 frame[i] |= pgm_read_byte(ptr);
377 const byte* ptr = getFrame_Cistercian(ones);
378 for (
int i = 0; i < 8; i++, ptr++)
380 frame[i] |= pgm_read_byte(ptr);
383 for (
int i = 0; i < 8; i++)
390 fPrevEffectSeqCount = fEffectSeqCount;
392 if (fEffectLengthMillis > 0 && fEffectLengthMillis < effectMillis)
396 fPreviousEffect = fDisplayEffect;
401 unsigned long fDisplayEffect;
402 unsigned long fPreviousEffect;
405 unsigned long fStatusDelay;
406 unsigned long fStatusMillis;
409 int fPrevEffectSeqCount;
410 unsigned int fEffectLengthMillis;
411 unsigned long fEffectStartMillis;
412 unsigned long fDisplayEffectVal;
414 void setRow(
int row, uint8_t bits)
417 byte device = (row / 8);
419 fLC.setRow(device, row, (
byte)((bits >> 4) << 4));
420 fLC.setRow(device, row+1, (
byte)(bits & 0XF));
426 byte device = (y / 8);
428 return fLC.getRow(device, y) |
429 fLC.getRow(device, y+1);
432 byte getPixel(
int x,
int y)
435 byte device = (y / 8);
439 byte bits = fLC.getRow(device, y) >> 4;
440 return ((bits & (1<<(3-x))) != 0);
444 byte bits = fLC.getRow(device, y+1);
445 return ((bits & (1<<(7-x))) != 0);
449 void setPixel(
int x,
int y, uint8_t set)
452 byte device = (y / 8);
456 byte bits = fLC.getRow(device, y) >> 4;
457 bits = (set) ? (bits | (1<<(3-x))) : (bits & ~(1<<(3-x)));
459 fLC.setRow(device, y, (
byte)((bits >> 4) << 4));
463 byte bits = fLC.getRow(device, y+1);
464 bits = (set) ? (bits | (1<<(7-x))) : (bits & ~(1<<(7-x)));
465 fLC.setRow(device, y+1, (
byte)(bits & 0XF));
469 void setCol(
int col, uint8_t bit)
471 for (
int y = 0; y < 8; y++)
473 setPixel(col, y, bit);
477 static const byte* getFrame_Cistercian(
unsigned number)
479 static const byte sFrameData[] PROGMEM = {
805 unsigned ln = log10(number);
810 return &sFrameData[((number-1)+ln*9)*8];
813 static const byte* getFrame_ExpandSolid(
int &frameIndex,
int direction)
815 static const byte sFrameData[] PROGMEM = {
852 unsigned frameCount =
sizeof(sFrameData) / 8;
853 if (
unsigned(frameIndex) >= frameCount)
854 frameIndex = (direction > 0) ? 0 : frameCount-1;
855 return &sFrameData[frameIndex*8];
858 static const byte* getFrame_ExpandHollow(
int &frameIndex,
int direction)
860 static const byte sFrameData[] PROGMEM = {
906 unsigned frameCount =
sizeof(sFrameData) / 8;
907 if (
unsigned(frameIndex) >= frameCount)
908 frameIndex = (direction > 0) ? 0 : frameCount-1;
909 return &sFrameData[frameIndex*8];
912 static const byte* getFrame_Q(
int &frameIndex,
int direction)
914 static const byte sFrameData[] PROGMEM = {
933 unsigned frameCount =
sizeof(sFrameData) / 8;
934 if (
unsigned(frameIndex) >= frameCount)
935 frameIndex = (direction > 0) ? 0 : frameCount-1;
936 return &sFrameData[frameIndex*8];
939 static inline int wrap(
int i,
int a)
952 for (
int y = 0; y < 8; y++)
955 for (
int x = 0; x < 8; x++)
958 for (
int k = -1; k <= 1; k++)
960 for (
int l = -1; l <= 1; l++)
964 a += getPixel(wrap(x, k), wrap(y, l));
968 if (a == 2) newbits[y] |= (getPixel(x, y)<<(7-x));
969 if (a == 3) newbits[y] |= (1<<(7-x));
972 for (
int y = 0; y < 8; y++)
974 setRow(y, newbits[y]);