From 032ca3cdea7e6e2ecf0a615298db1442ea051ff1 Mon Sep 17 00:00:00 2001 From: macegr Date: Wed, 24 Jun 2015 15:40:00 -0700 Subject: [PATCH 01/11] Reduced number of brightness steps to 5 --- RGBShades.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGBShades.ino b/RGBShades.ino index 2f8b115..ae444b7 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -96,7 +96,7 @@ void loop() switch(buttonStatus(1)) { case BTNRELEASED: // button was pressed and released quickly - currentBrightness += 16; // increase the brightness (wraps to lowest) + currentBrightness += 51; // increase the brightness (wraps to lowest) FastLED.setBrightness(scale8(currentBrightness,MAXBRIGHTNESS)); drawMeter(currentBrightness/16); break; From 4312123997ba91773ad33b76528143cd97000496 Mon Sep 17 00:00:00 2001 From: Garrett Mace Date: Sat, 12 Sep 2015 13:35:10 -0700 Subject: [PATCH 02/11] Updated comments to address new bootloader --- RGBShades.ino | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/RGBShades.ino b/RGBShades.ino index ae444b7..b4ddd31 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -7,7 +7,16 @@ // ZIP file https://github.com/FastLED/FastLED/archive/master.zip // // Use Arduino IDE 1.0 or later -// Select device "Arduino Pro or Pro Mini (5V, 16MHz) w/ATmega328 +// +// If your RGB Shades were purchased before July 2015: +// This version has the standard Arduino bootloader. R9 and R10 near the control buttons will be present. +// Select the “Arduino Pro or Pro Mini” option. +// Then, go back into the Tools menu and find the Processor option and select “ATmega328 (5V, 16MHz)”. +// +// If your RGB Shades were purchased after July 2015: +// This version has the Optiboot bootloader. R9 and 10 near the control buttons will be missing. +// Select the “Arduino Mini” option. +// Then, go back into the Tools menu and find the Processor option and select “ATmega328”. // // [Press] the SW1 button to cycle through available effects // Effects will also automatically cycle at startup From 30bf46541852bc0e64fee1301995d54f3d6eba12 Mon Sep 17 00:00:00 2001 From: Garrett Mace Date: Sat, 12 Sep 2015 13:36:02 -0700 Subject: [PATCH 03/11] Added info about selecting correct board type --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 6e4a2ea..47c3b6f 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,11 @@ RGB Shades described here: https://www.kickstarter.com/projects/macetech/rgb-led When downloading ZIP file, remove "-master" at the end of the folder name before attempting to open in the Arduino IDE + +If your RGB Shades were purchased before July 2015: +This version has the standard Arduino bootloader. R9 and R10 near the control buttons will be present. +Select the “Arduino Pro or Pro Mini” option. Then, go back into the Tools menu and find the Processor option and select “ATmega328 (5V, 16MHz)”. + +If your RGB Shades were purchased after July 2015: +This version has the Optiboot bootloader. R9 and 10 near the control buttons will be missing. +Select the “Arduino Mini” option. Then, go back into the Tools menu and find the Processor option and select “ATmega328”. From 32dbe1e39df9dca79a55fc3f42bad98e4690d359 Mon Sep 17 00:00:00 2001 From: macegr Date: Mon, 21 Sep 2015 13:12:41 -0700 Subject: [PATCH 04/11] Added scrolling text message features --- RGBShades.ino | 6 ++ effects.h | 169 +++++++++++++++++++++++++++++++++++++------------- font.h | 74 ++++++++++++++++++++++ messages.h | 13 ++++ utils.h | 31 +++++++++ 5 files changed, 249 insertions(+), 44 deletions(-) create mode 100644 font.h create mode 100644 messages.h diff --git a/RGBShades.ino b/RGBShades.ino index b4ddd31..af3e8a3 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -42,11 +42,14 @@ byte currentBrightness = STARTBRIGHTNESS; // 0-255 will be scaled to 0-MAXBRIGHT // Include FastLED library and other useful files #include +#include "messages.h" +#include "font.h" #include "XYmap.h" #include "utils.h" #include "effects.h" #include "buttons.h" + // Runs one time at the start of the program (power up or reset) void setup() { @@ -65,11 +68,14 @@ void setup() { // list of functions that will be displayed functionList effectList[] = {threeSine, threeDee, + scrollTextZero, plasma, confetti, rider, + scrollTextOne, glitter, slantBars, + scrollTextTwo, colorFill, sideRain, shadesOutline, diff --git a/effects.h b/effects.h index f966704..c42911c 100644 --- a/effects.h +++ b/effects.h @@ -9,7 +9,7 @@ // Triple Sine Waves byte sineOffset = 0; // counter for current position of sine waves void threeSine() { - + // startup tasks if (effectInit == false) { effectInit = true; @@ -22,14 +22,14 @@ void threeSine() { // Calculate "sine" waves with varying periods // sin8 is used for speed; cos8, quadwave8, or triwave8 would also work here - byte sinDistanceR = qmul8(abs(y*(255/kMatrixHeight) - sin8(sineOffset*9+x*16)),2); - byte sinDistanceG = qmul8(abs(y*(255/kMatrixHeight) - sin8(sineOffset*10+x*16)),2); - byte sinDistanceB = qmul8(abs(y*(255/kMatrixHeight) - sin8(sineOffset*11+x*16)),2); + byte sinDistanceR = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 9 + x * 16)), 2); + byte sinDistanceG = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 10 + x * 16)), 2); + byte sinDistanceB = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 11 + x * 16)), 2); - leds[XY(x,y)] = CRGB(255-sinDistanceR, 255-sinDistanceG, 255-sinDistanceB); + leds[XY(x, y)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB); } } - + sineOffset++; // byte will wrap from 255 to 0, matching sin8 0-255 cycle } @@ -50,15 +50,15 @@ void plasma() { } // Calculate current center of plasma pattern (can be offscreen) - int xOffset = cos8(plasVector/256); - int yOffset = sin8(plasVector/256); + int xOffset = cos8(plasVector / 256); + int yOffset = sin8(plasVector / 256); // Draw one frame of the animation into the LED array for (int x = 0; x < kMatrixWidth; x++) { for (int y = 0; y < kMatrixHeight; y++) { - byte color = sin8(sqrt(sq(((float)x-7.5)*10+xOffset-127)+sq(((float)y-2)*10+yOffset-127))+offset); - leds[XY(x,y)] = CHSV(color, 255, 255); - } + byte color = sin8(sqrt(sq(((float)x - 7.5) * 10 + xOffset - 127) + sq(((float)y - 2) * 10 + yOffset - 127)) + offset); + leds[XY(x, y)] = CHSV(color, 255, 255); + } } offset++; // wraps at 255 for sin8 @@ -70,7 +70,7 @@ void plasma() { // Scanning pattern left/right, uses global hue cycle byte riderPos = 0; void rider() { - + // startup tasks if (effectInit == false) { effectInit = true; @@ -80,12 +80,12 @@ void rider() { // Draw one frame of the animation into the LED array for (byte x = 0; x < kMatrixWidth; x++) { - int brightness = abs(x*(256/kMatrixWidth) - triwave8(riderPos)*2 + 127)*3; + int brightness = abs(x * (256 / kMatrixWidth) - triwave8(riderPos) * 2 + 127) * 3; if (brightness > 255) brightness = 255; brightness = 255 - brightness; CRGB riderColor = CHSV(cycleHue, 255, brightness); for (byte y = 0; y < kMatrixHeight; y++) { - leds[XY(x,y)] = riderColor; + leds[XY(x, y)] = riderColor; } } @@ -106,8 +106,8 @@ void glitter() { // Draw one frame of the animation into the LED array for (int x = 0; x < kMatrixWidth; x++) { - for (int y = 0; y = kMatrixHeight) || ((currentDirection & 1) && currentRow >= kMatrixWidth)) { currentRow = 0; - currentColor += random8(3,6); + currentColor += random8(3, 6); if (currentColor > 15) currentColor -= 16; currentDirection++; if (currentDirection > 3) currentDirection = 0; @@ -173,21 +173,21 @@ void threeDee() { effectInit = true; effectDelay = 50; } - - for (byte x = 0; x < kMatrixWidth; x++) { - for (byte y = 0; y < kMatrixHeight; y++) { - if (x < 7) { - leds[XY(x,y)] = CRGB::Blue; - } else if (x > 8) { - leds[XY(x,y)] = CRGB::Red; - } else { - leds[XY(x,y)] = CRGB::Black; - } - } - } - - leds[XY(6,0)] = CRGB::Black; - leds[XY(9,0)] = CRGB::Black; + + for (byte x = 0; x < kMatrixWidth; x++) { + for (byte y = 0; y < kMatrixHeight; y++) { + if (x < 7) { + leds[XY(x, y)] = CRGB::Blue; + } else if (x > 8) { + leds[XY(x, y)] = CRGB::Red; + } else { + leds[XY(x, y)] = CRGB::Black; + } + } + } + + leds[XY(6, 0)] = CRGB::Black; + leds[XY(9, 0)] = CRGB::Black; } @@ -200,11 +200,11 @@ void sideRain() { effectInit = true; effectDelay = 30; } - + scrollArray(rainDir); byte randPixel = random8(kMatrixHeight); - for (byte y = 0; y < kMatrixHeight; y++) leds[XY((kMatrixWidth-1) * rainDir,y)] = CRGB::Black; - leds[XY((kMatrixWidth-1)*rainDir, randPixel)] = CHSV(cycleHue, 255, 255); + for (byte y = 0; y < kMatrixHeight; y++) leds[XY((kMatrixWidth - 1) * rainDir, y)] = CRGB::Black; + leds[XY((kMatrixWidth - 1)*rainDir, randPixel)] = CHSV(cycleHue, 255, 255); } @@ -221,10 +221,10 @@ void confetti() { // scatter random colored pixels at several random coordinates for (byte i = 0; i < 4; i++) { - leds[XY(random16(kMatrixWidth),random16(kMatrixHeight))] = ColorFromPalette(currentPalette, random16(255), 255);//CHSV(random16(255), 255, 255); + leds[XY(random16(kMatrixWidth), random16(kMatrixHeight))] = ColorFromPalette(currentPalette, random16(255), 255); //CHSV(random16(255), 255, 255); random16_add_entropy(1); } - + } @@ -240,12 +240,93 @@ void slantBars() { for (byte x = 0; x < kMatrixWidth; x++) { for (byte y = 0; y < kMatrixHeight; y++) { - leds[XY(x,y)] = CHSV(cycleHue, 255, quadwave8(x*32+y*32+slantPos)); + leds[XY(x, y)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos)); } } - slantPos-=4; + slantPos -= 4; + +} + + +#define NORMAL 0 +#define RAINBOW 1 +#define charSpacing 2 +// Scroll a text string +void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { + static byte currentMessageChar = 0; + static byte currentCharColumn = 0; + static byte paletteCycle = 0; + static CRGB currentColor; + static byte bitBuffer[16] = {0}; + static byte bitBufferPointer = 0; + + + // startup tasks + if (effectInit == false) { + effectInit = true; + effectDelay = 35; + currentMessageChar = 0; + currentCharColumn = 0; + selectFlashString(message); + loadCharBuffer(loadStringChar(message, currentMessageChar)); + currentPalette = RainbowColors_p; + for (byte i = 0; i < kMatrixWidth; i++) bitBuffer[i] = 0; + } + + + paletteCycle += 15; + + if (currentCharColumn < 5) { + bitBuffer[(bitBufferPointer + kMatrixWidth - 1) % kMatrixWidth] = charBuffer[currentCharColumn]; // character + } else { + bitBuffer[(bitBufferPointer + kMatrixWidth - 1) % kMatrixWidth] = 0; // space + } + + CRGB pixelColor; + for (byte x = 0; x < kMatrixWidth; x++) { + for (byte y = 0; y < 5; y++) { + if (bitRead(bitBuffer[(bitBufferPointer + x) % kMatrixWidth], y) == 1) { + if (style == RAINBOW) { + pixelColor = ColorFromPalette(currentPalette, paletteCycle+y*16, 255); + } else { + pixelColor = fgColor; + } + } else { + pixelColor = bgColor; + } + leds[XY(x, y)] = pixelColor; + } + } + + currentCharColumn++; + if (currentCharColumn > (4 + charSpacing)) { + currentCharColumn = 0; + currentMessageChar++; + char nextChar = loadStringChar(message, currentMessageChar); + if (nextChar == 0) { // null character at end of strong + currentMessageChar = 0; + nextChar = loadStringChar(message, currentMessageChar); + } + loadCharBuffer(nextChar); + } + + bitBufferPointer++; + if (bitBufferPointer > 15) bitBufferPointer = 0; + +} + + +void scrollTextZero() { + scrollText(0, NORMAL, CRGB::Red, CRGB::Black); +} + +void scrollTextOne() { + scrollText(1, RAINBOW, 0, CRGB::Black); +} +void scrollTextTwo() { + scrollText(2, NORMAL, CRGB::Green, CRGB(0,0,8)); } //leds run around the periphery of the shades, changing color every go 'round boolean erase = false; diff --git a/font.h b/font.h new file mode 100644 index 0000000..f359146 --- /dev/null +++ b/font.h @@ -0,0 +1,74 @@ +// 5 x 5 pixel font (no lowercase) + +const char Font[][5] PROGMEM = { +{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 32 +{0b00000000, 0b00000000, 0b00010111, 0b00000000, 0b00000000}, // 33 ! +{0b00000000, 0b00000011, 0b00000000, 0b00000011, 0b00000000}, // 34 " +{0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010}, // 35 # +{0b00010010, 0b00010101, 0b00011111, 0b00010101, 0b00001001}, // 36 $ +{0b00010001, 0b00001000, 0b00000100, 0b00000010, 0b00010001}, // 37 % +{0b00001010, 0b00010101, 0b00001010, 0b00010000, 0b00000000}, // 38 & +{0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000}, // 39 ' +{0b00000000, 0b00000000, 0b00001110, 0b00010001, 0b00000000}, // 40 ( +{0b00000000, 0b00010001, 0b00001110, 0b00000000, 0b00000000}, // 41 ) +{0b00010001, 0b00001010, 0b00011111, 0b00001010, 0b00010001}, // 42 * +{0b00000100, 0b00000100, 0b00011111, 0b00000100, 0b00000100}, // 43 + +{0b00000000, 0b00010000, 0b00001000, 0b00000000, 0b00000000}, // 44 , +{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100}, // 45 - +{0b00000000, 0b00011000, 0b00011000, 0b00000000, 0b00000000}, // 46 . +{0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000001}, // 47 / +{0b00001110, 0b00010001, 0b00010101, 0b00010001, 0b00001110}, // 48 0 +{0b00000000, 0b00010010, 0b00011111, 0b00010000, 0b00000000}, // 49 1 +{0b00010010, 0b00011001, 0b00010101, 0b00010101, 0b00010010}, // 50 2 +{0b00010101, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 51 3 +{0b00000111, 0b00000100, 0b00000100, 0b00011111, 0b00000100}, // 52 4 +{0b00010111, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 53 5 +{0b00001110, 0b00010101, 0b00010101, 0b00010101, 0b00001000}, // 54 6 +{0b00000001, 0b00000001, 0b00011001, 0b00000101, 0b00000011}, // 55 7 +{0b00001010, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 56 8 +{0b00000010, 0b00010101, 0b00010101, 0b00010101, 0b00001110}, // 57 9 +{0b00000000, 0b00000000, 0b00001010, 0b00000000, 0b00000000}, // 58 : +{0b00000000, 0b00010000, 0b00001010, 0b00000000, 0b00000000}, // 59 ; +{0b00000000, 0b00000100, 0b00001010, 0b00010001, 0b00000000}, // 60 < +{0b00001010, 0b00001010, 0b00001010, 0b00001010, 0b00001010}, // 61 = +{0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00000000}, // 62 > +{0b00000010, 0b00000001, 0b00010101, 0b00000101, 0b00000010}, // 63 ? +{0b00011111, 0b00010001, 0b00010101, 0b00010101, 0b00010111}, // 64 @ +{0b00011110, 0b00000101, 0b00000101, 0b00000101, 0b00011110}, // 65 A +{0b00011111, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 66 B +{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001}, // 67 C +{0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 68 D +{0b00011111, 0b00010101, 0b00010101, 0b00010001, 0b00010001}, // 69 E +{0b00011111, 0b00000101, 0b00000101, 0b00000001, 0b00000001}, // 70 F +{0b00001110, 0b00010001, 0b00010101, 0b00010101, 0b00001101}, // 71 G +{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00011111}, // 72 H +{0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001}, // 73 I +{0b00001000, 0b00010000, 0b00010000, 0b00010001, 0b00001111}, // 74 J +{0b00011111, 0b00000100, 0b00001010, 0b00010001, 0b00010001}, // 75 K +{0b00011111, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 76 L +{0b00011111, 0b00000010, 0b00000100, 0b00000010, 0b00011111}, // 77 M +{0b00011111, 0b00000010, 0b00000100, 0b00001000, 0b00011111}, // 78 N +{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 79 O +{0b00011111, 0b00000101, 0b00000101, 0b00000101, 0b00000010}, // 80 P +{0b00001110, 0b00010001, 0b00010001, 0b00001001, 0b00010110}, // 81 Q +{0b00011111, 0b00000101, 0b00000101, 0b00001101, 0b00010010}, // 82 R +{0b00010010, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 83 S +{0b00000001, 0b00000001, 0b00011111, 0b00000001, 0b00000001}, // 84 T +{0b00001111, 0b00010000, 0b00010000, 0b00010000, 0b00001111}, // 85 U +{0b00000011, 0b00001100, 0b00010000, 0b00001100, 0b00000011}, // 86 V +{0b00000111, 0b00011000, 0b00000110, 0b00011000, 0b00000111}, // 87 W +{0b00010001, 0b00001010, 0b00000100, 0b00001010, 0b00010001}, // 88 X +{0b00000001, 0b00000010, 0b00011100, 0b00000010, 0b00000001}, // 89 Y +{0b00010001, 0b00011001, 0b00010101, 0b00010011, 0b00010001}, // 90 Z +{0b00000000, 0b00000000, 0b00011111, 0b00010001, 0b00010001}, // 91 [ +{0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 92 \ +{0b00010001, 0b00010001, 0b00011111, 0b00000000, 0b00000000}, // 93 ] +{0b00000100, 0b00000010, 0b00000001, 0b00000010, 0b00000100}, // 94 ^ +{0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 95 _ +{0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00011111}}; // 96 + + + + + + diff --git a/messages.h b/messages.h new file mode 100644 index 0000000..54b91a9 --- /dev/null +++ b/messages.h @@ -0,0 +1,13 @@ +// Scrolling messages + +const char string0[] PROGMEM = "HELLO WORLD "; +const char string1[] PROGMEM = "RAINBOW TEXT! "; +const char string2[] PROGMEM = "macetech.com "; +//char string3[] PROGMEM = " "; + +const char * const stringArray[] PROGMEM = { + string0, + string1, + string2 + //string3 +}; diff --git a/utils.h b/utils.h index e2f3444..aa2a686 100644 --- a/utils.h +++ b/utils.h @@ -57,6 +57,7 @@ void scrollArray(byte scrollDir) { } + // Pick a random palette from a list void selectRandomPalette() { @@ -135,5 +136,35 @@ void confirmBlink() { FastLED.delay(200); } +} + + + +// Determine flash address of text string +unsigned int currentStringAddress = 0; +void selectFlashString(byte string) { + currentStringAddress = pgm_read_word(&stringArray[string]); +} + +// Fetch font character bitmap from flash +byte charBuffer[5] = {0}; +void loadCharBuffer(byte character) { + byte mappedCharacter = character; + if (mappedCharacter >= 32 && mappedCharacter <= 95) { + mappedCharacter -= 32; // subtract font array offset + } else if (mappedCharacter >= 97 && mappedCharacter <= 122) { + mappedCharacter -= 64; // subtract font array offset and convert lowercase to uppercase + } else { + mappedCharacter = 96; // unknown character block + } + + for (byte i = 0; i < 5; i++) { + charBuffer[i] = pgm_read_byte(Font[mappedCharacter]+i); + } +} +// Fetch a character value from a text string in flash +char loadStringChar(byte string, byte character) { + return (char) pgm_read_byte(currentStringAddress + character); +; } From a5dd42b007f9b892a55dcfb559fe49cffa2b53b4 Mon Sep 17 00:00:00 2001 From: macegr Date: Mon, 21 Sep 2015 13:20:02 -0700 Subject: [PATCH 05/11] Minor cleanup --- effects.h | 7 ++----- utils.h | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/effects.h b/effects.h index c42911c..151750e 100644 --- a/effects.h +++ b/effects.h @@ -35,9 +35,6 @@ void threeSine() { } - - - // RGB Plasma byte offset = 0; // counter for radial color wave motion int plasVector = 0; // counter for orbiting plasma center @@ -277,7 +274,7 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { paletteCycle += 15; - if (currentCharColumn < 5) { + if (currentCharColumn < 5) { // characters are 5 pixels wide bitBuffer[(bitBufferPointer + kMatrixWidth - 1) % kMatrixWidth] = charBuffer[currentCharColumn]; // character } else { bitBuffer[(bitBufferPointer + kMatrixWidth - 1) % kMatrixWidth] = 0; // space @@ -285,7 +282,7 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { CRGB pixelColor; for (byte x = 0; x < kMatrixWidth; x++) { - for (byte y = 0; y < 5; y++) { + for (byte y = 0; y < 5; y++) { // characters are 5 pixels tall if (bitRead(bitBuffer[(bitBufferPointer + x) % kMatrixWidth], y) == 1) { if (style == RAINBOW) { pixelColor = ColorFromPalette(currentPalette, paletteCycle+y*16, 255); diff --git a/utils.h b/utils.h index aa2a686..6e7123a 100644 --- a/utils.h +++ b/utils.h @@ -91,7 +91,6 @@ void selectRandomPalette() { break; } - } void drawMeter(int step){ @@ -138,8 +137,6 @@ void confirmBlink() { } - - // Determine flash address of text string unsigned int currentStringAddress = 0; void selectFlashString(byte string) { @@ -161,10 +158,10 @@ void loadCharBuffer(byte character) { for (byte i = 0; i < 5; i++) { charBuffer[i] = pgm_read_byte(Font[mappedCharacter]+i); } + } // Fetch a character value from a text string in flash char loadStringChar(byte string, byte character) { return (char) pgm_read_byte(currentStringAddress + character); -; } From 0c8e97a2663933dcd40e4bf39133da74f08accd0 Mon Sep 17 00:00:00 2001 From: George Griffin Date: Sun, 4 Oct 2015 05:00:22 -0400 Subject: [PATCH 06/11] Hacked together POC for scrolling messages from serial --- RGBShades.ino | 11 +++++++++++ utils.h | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/RGBShades.ino b/RGBShades.ino index af3e8a3..2021f36 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -62,9 +62,20 @@ void setup() { // configure input buttons pinMode(MODEBUTTON, INPUT_PULLUP); pinMode(BRIGHTNESSBUTTON, INPUT_PULLUP); + Serial.begin(9600); } +void serialEvent(){ + if(Serial.available() == 0) return; + for (byte i = 0; i < sizeof(messageBuffer); i++) messageBuffer[i] = 0; + messageLen = Serial.available(); + Serial.readBytesUntil('\n', messageBuffer, sizeof(messageBuffer)); + Serial.println(messageLen); + Serial.println(messageBuffer); +} + + // list of functions that will be displayed functionList effectList[] = {threeSine, threeDee, diff --git a/utils.h b/utils.h index 6e7123a..885d0b9 100644 --- a/utils.h +++ b/utils.h @@ -137,10 +137,14 @@ void confirmBlink() { } +char messageBuffer[140]; +int messageLen = 0; + + // Determine flash address of text string unsigned int currentStringAddress = 0; void selectFlashString(byte string) { - currentStringAddress = pgm_read_word(&stringArray[string]); + // currentStringAddress = pgm_read_word(&stringArray[string]); } // Fetch font character bitmap from flash @@ -163,5 +167,5 @@ void loadCharBuffer(byte character) { // Fetch a character value from a text string in flash char loadStringChar(byte string, byte character) { - return (char) pgm_read_byte(currentStringAddress + character); + return messageBuffer[character]; } From bdeba5a68012a874039ff16fc2d8eec70ddf8666 Mon Sep 17 00:00:00 2001 From: George Griffin Date: Sun, 4 Oct 2015 16:39:06 -0400 Subject: [PATCH 07/11] adds default message to buffer --- RGBShades.ino | 36 ++++++------ effects.h | 28 ++++++---- font.h | 151 ++++++++++++++++++++++++++++---------------------- messages.h | 6 ++ utils.h | 36 ++++++------ 5 files changed, 144 insertions(+), 113 deletions(-) diff --git a/RGBShades.ino b/RGBShades.ino index 2021f36..e322ad5 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -69,28 +69,28 @@ void setup() { void serialEvent(){ if(Serial.available() == 0) return; for (byte i = 0; i < sizeof(messageBuffer); i++) messageBuffer[i] = 0; - messageLen = Serial.available(); Serial.readBytesUntil('\n', messageBuffer, sizeof(messageBuffer)); - Serial.println(messageLen); - Serial.println(messageBuffer); + effectInit = false; } // list of functions that will be displayed -functionList effectList[] = {threeSine, - threeDee, - scrollTextZero, - plasma, - confetti, - rider, +functionList effectList[] = {//threeSine, + //threeDee, + //scrollTextZero, + //plasma, + //confetti, + //rider, scrollTextOne, - glitter, - slantBars, - scrollTextTwo, - colorFill, - sideRain, - shadesOutline, - hearts}; + scrollTextSerial, + //glitter, + //slantBars, + //scrollTextTwo, + //colorFill, + //sideRain, + //shadesOutline, + //hearts + }; // Timing parameters #define cycleTime 15000 @@ -122,7 +122,7 @@ void loop() switch(buttonStatus(1)) { case BTNRELEASED: // button was pressed and released quickly - currentBrightness += 51; // increase the brightness (wraps to lowest) + currentBrightness += 16; // increase the brightness (wraps to lowest) FastLED.setBrightness(scale8(currentBrightness,MAXBRIGHTNESS)); drawMeter(currentBrightness/16); break; @@ -133,7 +133,7 @@ void loop() drawMeter(currentBrightness/16); break; - } + } // switch to a new effect every cycleTime milliseconds if (currentMillis - cycleMillis > cycleTime && autoCycle == true) { diff --git a/effects.h b/effects.h index 151750e..3ffc5ec 100644 --- a/effects.h +++ b/effects.h @@ -248,7 +248,7 @@ void slantBars() { #define NORMAL 0 #define RAINBOW 1 -#define charSpacing 2 +#define charSpacing 1 // Scroll a text string void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { static byte currentMessageChar = 0; @@ -257,24 +257,26 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { static CRGB currentColor; static byte bitBuffer[16] = {0}; static byte bitBufferPointer = 0; - + static int charWidth; // startup tasks if (effectInit == false) { effectInit = true; - effectDelay = 35; + effectDelay = 100; currentMessageChar = 0; currentCharColumn = 0; selectFlashString(message); loadCharBuffer(loadStringChar(message, currentMessageChar)); + charWidth = loadCharWidth(loadStringChar(message, currentMessageChar)); + Serial.print("Initialization charWidth: "); + Serial.println(charWidth); currentPalette = RainbowColors_p; for (byte i = 0; i < kMatrixWidth; i++) bitBuffer[i] = 0; } - paletteCycle += 15; - if (currentCharColumn < 5) { // characters are 5 pixels wide + if (currentCharColumn < charWidth) { // character bitfields are charwidth pixels wide bitBuffer[(bitBufferPointer + kMatrixWidth - 1) % kMatrixWidth] = charBuffer[currentCharColumn]; // character } else { bitBuffer[(bitBufferPointer + kMatrixWidth - 1) % kMatrixWidth] = 0; // space @@ -297,7 +299,7 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { } currentCharColumn++; - if (currentCharColumn > (4 + charSpacing)) { + if (currentCharColumn > ((charWidth - 1) + charSpacing)) { currentCharColumn = 0; currentMessageChar++; char nextChar = loadStringChar(message, currentMessageChar); @@ -306,6 +308,7 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { nextChar = loadStringChar(message, currentMessageChar); } loadCharBuffer(nextChar); + charWidth = loadCharWidth(nextChar); } bitBufferPointer++; @@ -325,9 +328,17 @@ void scrollTextOne() { void scrollTextTwo() { scrollText(2, NORMAL, CRGB::Green, CRGB(0,0,8)); } + +void scrollTextSerial(){ + scrollText(255, NORMAL, CRGB::DarkRed, CRGB::DarkBlue); +} //leds run around the periphery of the shades, changing color every go 'round boolean erase = false; uint8_t x,y = 0; +const uint8_t OutlineTable[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 43, + 44, 67, 66, 65, 64, 63, 50, 37, 21, 22, 36, 51, 62, 61, 60, 59, + 58, 57, 30, 29}; void shadesOutline(){ //startup tasks if (effectInit == false) { @@ -337,10 +348,7 @@ void shadesOutline(){ effectDelay = 15; FastLED.clear(); currentPalette = RainbowColors_p;} - const uint8_t OutlineTable[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 43, - 44, 67, 66, 65, 64, 63, 50, 37, 21, 22, 36, 51, 62, 61, 60, 59, - 58, 57, 30, 29}; + leds[OutlineTable[x]] = currentPalette[currentColor]; if (erase) leds[OutlineTable[x]] = CRGB::Black; diff --git a/font.h b/font.h index f359146..601af15 100644 --- a/font.h +++ b/font.h @@ -1,71 +1,88 @@ -// 5 x 5 pixel font (no lowercase) +// Fetch font character bitmap from flash +byte charBuffer[5] = {0}; -const char Font[][5] PROGMEM = { -{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 32 -{0b00000000, 0b00000000, 0b00010111, 0b00000000, 0b00000000}, // 33 ! -{0b00000000, 0b00000011, 0b00000000, 0b00000011, 0b00000000}, // 34 " -{0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010}, // 35 # -{0b00010010, 0b00010101, 0b00011111, 0b00010101, 0b00001001}, // 36 $ -{0b00010001, 0b00001000, 0b00000100, 0b00000010, 0b00010001}, // 37 % -{0b00001010, 0b00010101, 0b00001010, 0b00010000, 0b00000000}, // 38 & -{0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000}, // 39 ' -{0b00000000, 0b00000000, 0b00001110, 0b00010001, 0b00000000}, // 40 ( -{0b00000000, 0b00010001, 0b00001110, 0b00000000, 0b00000000}, // 41 ) -{0b00010001, 0b00001010, 0b00011111, 0b00001010, 0b00010001}, // 42 * -{0b00000100, 0b00000100, 0b00011111, 0b00000100, 0b00000100}, // 43 + -{0b00000000, 0b00010000, 0b00001000, 0b00000000, 0b00000000}, // 44 , -{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100}, // 45 - -{0b00000000, 0b00011000, 0b00011000, 0b00000000, 0b00000000}, // 46 . -{0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000001}, // 47 / -{0b00001110, 0b00010001, 0b00010101, 0b00010001, 0b00001110}, // 48 0 -{0b00000000, 0b00010010, 0b00011111, 0b00010000, 0b00000000}, // 49 1 -{0b00010010, 0b00011001, 0b00010101, 0b00010101, 0b00010010}, // 50 2 -{0b00010101, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 51 3 -{0b00000111, 0b00000100, 0b00000100, 0b00011111, 0b00000100}, // 52 4 -{0b00010111, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 53 5 -{0b00001110, 0b00010101, 0b00010101, 0b00010101, 0b00001000}, // 54 6 -{0b00000001, 0b00000001, 0b00011001, 0b00000101, 0b00000011}, // 55 7 -{0b00001010, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 56 8 -{0b00000010, 0b00010101, 0b00010101, 0b00010101, 0b00001110}, // 57 9 -{0b00000000, 0b00000000, 0b00001010, 0b00000000, 0b00000000}, // 58 : -{0b00000000, 0b00010000, 0b00001010, 0b00000000, 0b00000000}, // 59 ; -{0b00000000, 0b00000100, 0b00001010, 0b00010001, 0b00000000}, // 60 < -{0b00001010, 0b00001010, 0b00001010, 0b00001010, 0b00001010}, // 61 = -{0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00000000}, // 62 > -{0b00000010, 0b00000001, 0b00010101, 0b00000101, 0b00000010}, // 63 ? -{0b00011111, 0b00010001, 0b00010101, 0b00010101, 0b00010111}, // 64 @ -{0b00011110, 0b00000101, 0b00000101, 0b00000101, 0b00011110}, // 65 A -{0b00011111, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 66 B -{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001}, // 67 C -{0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 68 D -{0b00011111, 0b00010101, 0b00010101, 0b00010001, 0b00010001}, // 69 E -{0b00011111, 0b00000101, 0b00000101, 0b00000001, 0b00000001}, // 70 F -{0b00001110, 0b00010001, 0b00010101, 0b00010101, 0b00001101}, // 71 G -{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00011111}, // 72 H -{0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001}, // 73 I -{0b00001000, 0b00010000, 0b00010000, 0b00010001, 0b00001111}, // 74 J -{0b00011111, 0b00000100, 0b00001010, 0b00010001, 0b00010001}, // 75 K -{0b00011111, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 76 L -{0b00011111, 0b00000010, 0b00000100, 0b00000010, 0b00011111}, // 77 M -{0b00011111, 0b00000010, 0b00000100, 0b00001000, 0b00011111}, // 78 N -{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 79 O -{0b00011111, 0b00000101, 0b00000101, 0b00000101, 0b00000010}, // 80 P -{0b00001110, 0b00010001, 0b00010001, 0b00001001, 0b00010110}, // 81 Q -{0b00011111, 0b00000101, 0b00000101, 0b00001101, 0b00010010}, // 82 R -{0b00010010, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 83 S -{0b00000001, 0b00000001, 0b00011111, 0b00000001, 0b00000001}, // 84 T -{0b00001111, 0b00010000, 0b00010000, 0b00010000, 0b00001111}, // 85 U -{0b00000011, 0b00001100, 0b00010000, 0b00001100, 0b00000011}, // 86 V -{0b00000111, 0b00011000, 0b00000110, 0b00011000, 0b00000111}, // 87 W -{0b00010001, 0b00001010, 0b00000100, 0b00001010, 0b00010001}, // 88 X -{0b00000001, 0b00000010, 0b00011100, 0b00000010, 0b00000001}, // 89 Y -{0b00010001, 0b00011001, 0b00010101, 0b00010011, 0b00010001}, // 90 Z -{0b00000000, 0b00000000, 0b00011111, 0b00010001, 0b00010001}, // 91 [ -{0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 92 \ -{0b00010001, 0b00010001, 0b00011111, 0b00000000, 0b00000000}, // 93 ] -{0b00000100, 0b00000010, 0b00000001, 0b00000010, 0b00000100}, // 94 ^ -{0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 95 _ -{0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00011111}}; // 96 +int characterMapping(byte character){ + byte mappedCharacter = character; + if (mappedCharacter >= 32 && mappedCharacter <= 95) { + mappedCharacter -= 32; // subtract font array offset + } else if (mappedCharacter >= 97 && mappedCharacter <= 122) { + mappedCharacter -= 64; // subtract font array offset and convert lowercase to uppercase + } else { + mappedCharacter = 96; // unknown character block + } + return mappedCharacter; +} + +// variable width pixel font (no lowercase) +// character arrays are 6 bytes, +// byte 0 is the width of the character +// bytes 1-5 is the bitmask for the pixel columns +const char Font[][6] PROGMEM = { +{0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 32 +{0b00000001, 0b00010111, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 33 ! +{0b00000011, 0b00000011, 0b00000000, 0b00000011, 0b00000000, 0b00000000}, // 34 " +{0b00000101, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010}, // 35 # +{0b00000101, 0b00010010, 0b00010101, 0b00011111, 0b00010101, 0b00001001}, // 36 $ +{0b00000101, 0b00010001, 0b00001000, 0b00000100, 0b00000010, 0b00010001}, // 37 % +{0b00000101, 0b00001010, 0b00010101, 0b00001010, 0b00010000, 0b00000000}, // 38 & +{0b00000001, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 39 ' +{0b00000101, 0b00000000, 0b00000000, 0b00001110, 0b00010001, 0b00000000}, // 40 ( +{0b00000101, 0b00000000, 0b00010001, 0b00001110, 0b00000000, 0b00000000}, // 41 ) +{0b00000101, 0b00010001, 0b00001010, 0b00011111, 0b00001010, 0b00010001}, // 42 * +{0b00000101, 0b00000100, 0b00000100, 0b00011111, 0b00000100, 0b00000100}, // 43 + +{0b00000010, 0b00010000, 0b00001000, 0b00000000, 0b00000000, 0b00000000}, // 44 , +{0b00000101, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100}, // 45 - +{0b00000010, 0b00011000, 0b00011000, 0b00000000, 0b00000000, 0b00000000}, // 46 . +{0b00000101, 0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000001}, // 47 / +{0b00000101, 0b00001110, 0b00010001, 0b00010101, 0b00010001, 0b00001110}, // 48 0 +{0b00000101, 0b00000000, 0b00010010, 0b00011111, 0b00010000, 0b00000000}, // 49 1 +{0b00000101, 0b00010010, 0b00011001, 0b00010101, 0b00010101, 0b00010010}, // 50 2 +{0b00000101, 0b00010101, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 51 3 +{0b00000101, 0b00000111, 0b00000100, 0b00000100, 0b00011111, 0b00000100}, // 52 4 +{0b00000101, 0b00010111, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 53 5 +{0b00000101, 0b00001110, 0b00010101, 0b00010101, 0b00010101, 0b00001000}, // 54 6 +{0b00000101, 0b00000001, 0b00000001, 0b00011001, 0b00000101, 0b00000011}, // 55 7 +{0b00000101, 0b00001010, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 56 8 +{0b00000101, 0b00000010, 0b00010101, 0b00010101, 0b00010101, 0b00001110}, // 57 9 +{0b00000001, 0b00001010, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 58 : +{0b00000010, 0b00010000, 0b00001010, 0b00000000, 0b00000000, 0b00000000}, // 59 ; +{0b00000101, 0b00000000, 0b00000100, 0b00001010, 0b00010001, 0b00000000}, // 60 < +{0b00000101, 0b00001010, 0b00001010, 0b00001010, 0b00001010, 0b00001010}, // 61 = +{0b00000101, 0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00000000}, // 62 > +{0b00000101, 0b00000010, 0b00000001, 0b00010101, 0b00000101, 0b00000010}, // 63 ? +{0b00000101, 0b00011111, 0b00010001, 0b00010101, 0b00010101, 0b00010111}, // 64 @ +{0b00000101, 0b00011110, 0b00000101, 0b00000101, 0b00000101, 0b00011110}, // 65 A +{0b00000101, 0b00011111, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 66 B +{0b00000101, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001}, // 67 C +{0b00000101, 0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 68 D +{0b00000101, 0b00011111, 0b00010101, 0b00010101, 0b00010001, 0b00010001}, // 69 E +{0b00000101, 0b00011111, 0b00000101, 0b00000101, 0b00000001, 0b00000001}, // 70 F +{0b00000101, 0b00001110, 0b00010001, 0b00010101, 0b00010101, 0b00001101}, // 71 G +{0b00000101, 0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00011111}, // 72 H +{0b00000101, 0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001}, // 73 I +{0b00000101, 0b00001000, 0b00010000, 0b00010000, 0b00010001, 0b00001111}, // 74 J +{0b00000101, 0b00011111, 0b00000100, 0b00001010, 0b00010001, 0b00010001}, // 75 K +{0b00000101, 0b00011111, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 76 L +{0b00000101, 0b00011111, 0b00000010, 0b00000100, 0b00000010, 0b00011111}, // 77 M +{0b00000101, 0b00011111, 0b00000010, 0b00000100, 0b00001000, 0b00011111}, // 78 N +{0b00000101, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 79 O +{0b00000101, 0b00011111, 0b00000101, 0b00000101, 0b00000101, 0b00000010}, // 80 P +{0b00000101, 0b00001110, 0b00010001, 0b00010001, 0b00001001, 0b00010110}, // 81 Q +{0b00000101, 0b00011111, 0b00000101, 0b00000101, 0b00001101, 0b00010010}, // 82 R +{0b00000101, 0b00010010, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 83 S +{0b00000101, 0b00000001, 0b00000001, 0b00011111, 0b00000001, 0b00000001}, // 84 T +{0b00000101, 0b00001111, 0b00010000, 0b00010000, 0b00010000, 0b00001111}, // 85 U +{0b00000101, 0b00000011, 0b00001100, 0b00010000, 0b00001100, 0b00000011}, // 86 V +{0b00000101, 0b00000111, 0b00011000, 0b00000110, 0b00011000, 0b00000111}, // 87 W +{0b00000101, 0b00010001, 0b00001010, 0b00000100, 0b00001010, 0b00010001}, // 88 X +{0b00000101, 0b00000001, 0b00000010, 0b00011100, 0b00000010, 0b00000001}, // 89 Y +{0b00000101, 0b00010001, 0b00011001, 0b00010101, 0b00010011, 0b00010001}, // 90 Z +{0b00000101, 0b00000000, 0b00000000, 0b00011111, 0b00010001, 0b00010001}, // 91 [ +{0b00000101, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 92 \ +{0b00000101, 0b00010001, 0b00010001, 0b00011111, 0b00000000, 0b00000000}, // 93 ] +{0b00000101, 0b00000100, 0b00000010, 0b00000001, 0b00000010, 0b00000100}, // 94 ^ +{0b00000101, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 95 _ +{0b00000101, 0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00011111}}; // 96 diff --git a/messages.h b/messages.h index 54b91a9..1622c94 100644 --- a/messages.h +++ b/messages.h @@ -5,6 +5,12 @@ const char string1[] PROGMEM = "RAINBOW TEXT! "; const char string2[] PROGMEM = "macetech.com "; //char string3[] PROGMEM = " "; + + +// Setup for serial +char messageBuffer[140] = " 'apple' 'orange' apple's orange's"; +int messageLen = 0; + const char * const stringArray[] PROGMEM = { string0, string1, diff --git a/utils.h b/utils.h index 885d0b9..c330295 100644 --- a/utils.h +++ b/utils.h @@ -8,7 +8,7 @@ unsigned long currentMillis; // store current loop's millis value unsigned long hueMillis; // store time of last hue change byte currentEffect = 0; // index to the currently running effect -boolean autoCycle = true; // flag for automatic effect changes +boolean autoCycle = false; // flag for automatic effect changes CRGBPalette16 currentPalette(RainbowColors_p); // global pallete storage @@ -137,35 +137,35 @@ void confirmBlink() { } -char messageBuffer[140]; -int messageLen = 0; - - // Determine flash address of text string unsigned int currentStringAddress = 0; void selectFlashString(byte string) { - // currentStringAddress = pgm_read_word(&stringArray[string]); + currentStringAddress = pgm_read_word(&stringArray[string]); } -// Fetch font character bitmap from flash -byte charBuffer[5] = {0}; + + void loadCharBuffer(byte character) { - byte mappedCharacter = character; - if (mappedCharacter >= 32 && mappedCharacter <= 95) { - mappedCharacter -= 32; // subtract font array offset - } else if (mappedCharacter >= 97 && mappedCharacter <= 122) { - mappedCharacter -= 64; // subtract font array offset and convert lowercase to uppercase - } else { - mappedCharacter = 96; // unknown character block - } + int mappedCharacter = characterMapping(character); for (byte i = 0; i < 5; i++) { - charBuffer[i] = pgm_read_byte(Font[mappedCharacter]+i); + charBuffer[i] = pgm_read_byte(Font[mappedCharacter]+(i+1)); } } +int loadCharWidth(byte character){ + int mappedCharacter = characterMapping(character); + Serial.print("mappedCharacter: "); + Serial.println(mappedCharacter); + return (int)pgm_read_byte(Font[mappedCharacter]); +} + // Fetch a character value from a text string in flash char loadStringChar(byte string, byte character) { - return messageBuffer[character]; + if(string == 255){ // displaying serial string + return messageBuffer[character]; + }else{ + return (char) pgm_read_byte(currentStringAddress + character); + } } From 37c0a496eba791c65f585c5f2ed5b5b9f808cbef Mon Sep 17 00:00:00 2001 From: George Griffin Date: Sat, 10 Oct 2015 23:20:27 -0400 Subject: [PATCH 08/11] Places a more sensible message as the default serial message --- messages.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messages.h b/messages.h index 1622c94..12221f5 100644 --- a/messages.h +++ b/messages.h @@ -8,7 +8,7 @@ const char string2[] PROGMEM = "macetech.com "; // Setup for serial -char messageBuffer[140] = " 'apple' 'orange' apple's orange's"; +char messageBuffer[140] = "Upload message now... "; int messageLen = 0; const char * const stringArray[] PROGMEM = { From 7eb90a45f2323f6430a45091cbe6faddf59522d0 Mon Sep 17 00:00:00 2001 From: George Griffin Date: Sat, 10 Oct 2015 23:25:41 -0400 Subject: [PATCH 09/11] Increases update speed for scroll text --- effects.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/effects.h b/effects.h index 3ffc5ec..11d1914 100644 --- a/effects.h +++ b/effects.h @@ -262,7 +262,7 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { // startup tasks if (effectInit == false) { effectInit = true; - effectDelay = 100; + effectDelay = 35; currentMessageChar = 0; currentCharColumn = 0; selectFlashString(message); From 01a812954b571060c0da852a131f03a0c3e5938d Mon Sep 17 00:00:00 2001 From: George Griffin Date: Mon, 12 Oct 2015 09:39:40 -0400 Subject: [PATCH 10/11] Adds new font file --- RGBShades.ino | 11 +++-- effects.h | 11 +++-- font2.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ messages.h | 4 +- utils.h | 6 +-- 5 files changed, 150 insertions(+), 14 deletions(-) create mode 100644 font2.h diff --git a/RGBShades.ino b/RGBShades.ino index e322ad5..e4efb19 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -36,14 +36,14 @@ #define CHIPSET WS2811 // Global maximum brightness value, maximum 255 -#define MAXBRIGHTNESS 72 +#define MAXBRIGHTNESS 16 #define STARTBRIGHTNESS 127 byte currentBrightness = STARTBRIGHTNESS; // 0-255 will be scaled to 0-MAXBRIGHTNESS // Include FastLED library and other useful files #include #include "messages.h" -#include "font.h" +#include "font2.h" #include "XYmap.h" #include "utils.h" #include "effects.h" @@ -75,14 +75,15 @@ void serialEvent(){ // list of functions that will be displayed -functionList effectList[] = {//threeSine, +functionList effectList[] = { + scrollTextSerial, + //threeSine, //threeDee, //scrollTextZero, //plasma, //confetti, //rider, - scrollTextOne, - scrollTextSerial, + //scrollTextOne, //glitter, //slantBars, //scrollTextTwo, diff --git a/effects.h b/effects.h index 11d1914..7c74f4f 100644 --- a/effects.h +++ b/effects.h @@ -262,7 +262,7 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { // startup tasks if (effectInit == false) { effectInit = true; - effectDelay = 35; + effectDelay = 100; currentMessageChar = 0; currentCharColumn = 0; selectFlashString(message); @@ -270,7 +270,12 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { charWidth = loadCharWidth(loadStringChar(message, currentMessageChar)); Serial.print("Initialization charWidth: "); Serial.println(charWidth); - currentPalette = RainbowColors_p; + Serial.print("Init char:"); + Serial.print(loadStringChar(message, currentMessageChar)); + Serial.println((int)loadStringChar(message, currentMessageChar)); + Serial.print("Init charMapping: "); + Serial.println(characterMapping(loadStringChar(message, currentMessageChar))); + currentPalette = ForestColors_p; for (byte i = 0; i < kMatrixWidth; i++) bitBuffer[i] = 0; } @@ -330,7 +335,7 @@ void scrollTextTwo() { } void scrollTextSerial(){ - scrollText(255, NORMAL, CRGB::DarkRed, CRGB::DarkBlue); + scrollText(255, RAINBOW, CRGB::DarkRed, CRGB::Black); } //leds run around the periphery of the shades, changing color every go 'round boolean erase = false; diff --git a/font2.h b/font2.h new file mode 100644 index 0000000..d974cb0 --- /dev/null +++ b/font2.h @@ -0,0 +1,132 @@ +// Fetch font character bitmap from flash +byte charBuffer[5] = {0}; + +int characterMapping(byte character){ + byte mappedCharacter = character; + if (mappedCharacter >= 32 && mappedCharacter <= 255) { + mappedCharacter -= 32; // subtract font array offset + //} else if (mappedCharacter >= 97 && mappedCharacter <= 122) { + // mappedCharacter -= 64; // subtract font array offset and convert lowercase to uppercase + } else { + mappedCharacter = 96; // unknown character block + } + return mappedCharacter; +} + +// variable width pixel font (no lowercase) +// character arrays are 6 bytes, +// byte 0 is the width of the character +// bytes 1-5 is the bitmask for the pixel columns +const char Font[][6] PROGMEM = { +{1, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 00:32 +{1, 0b00010111, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 01:33 ! +{3, 0b00000011, 0b00000000, 0b00000011, 0b00000000, 0b00000000}, // 02:34 " +{5, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010}, // 03:35 # +{5, 0b00010010, 0b00010101, 0b00011111, 0b00010101, 0b00001001}, // 04:36 $ +{5, 0b00010001, 0b00001000, 0b00000100, 0b00000010, 0b00010001}, // 05:37 % +{5, 0b00001010, 0b00010101, 0b00010101, 0b00011110, 0b00010100}, // 06:38 & +{1, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 07:39 ' +{2, 0b00001110, 0b00010001, 0b00000000, 0b00000000, 0b00000000}, // 08:40 ( +{2, 0b00010001, 0b00001110, 0b00000000, 0b00000000, 0b00000000}, // 09:41 ) + +{5, 0b00001010, 0b00000100, 0b00011111, 0b00000100, 0b00001010}, // 10:42 * +{3, 0b00000100, 0b00001110, 0b00000100, 0b00000000, 0b00000000}, // 11:43 + +{1, 0b00010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 12:44 , +{3, 0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000000}, // 13:45 - +{1, 0b00010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 14:46 . +{5, 0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000001}, // 15:47 / +{5, 0b00001110, 0b00011001, 0b00010101, 0b00010011, 0b00001110}, // 16:48 0 +{3, 0b00010010, 0b00011111, 0b00010000, 0b00000000, 0b00000000}, // 17:49 1 +{5, 0b00011001, 0b00010101, 0b00010101, 0b00010101, 0b00010010}, // 18:50 2 +{5, 0b00010001, 0b00010001, 0b00010101, 0b00010101, 0b00001010}, // 19:51 3 + +{5, 0b00000011, 0b00000100, 0b00000100, 0b00000100, 0b00011111}, // 20:52 4 +{5, 0b00010111, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 21:53 5 +{5, 0b00001110, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 22:54 6 +{5, 0b00000001, 0b00000001, 0b00000001, 0b00011101, 0b00000011}, // 23:55 7 +{5, 0b00001010, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 24:56 8 +{5, 0b00000010, 0b00010101, 0b00010101, 0b00010101, 0b00001110}, // 25:57 9 +{1, 0b00001010, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 26:58 : +{2, 0b00010000, 0b00001010, 0b00000000, 0b00000000, 0b00000000}, // 27:59 ; +{3, 0b00000100, 0b00001010, 0b00010001, 0b00000000, 0b00000000}, // 28:60 < +{5, 0b00001010, 0b00001010, 0b00001010, 0b00001010, 0b00001010}, // 29:61 = + +{3, 0b00010001, 0b00001010, 0b00000100, 0b00000000, 0b00000000}, // 30:62 > +{5, 0b00000010, 0b00000001, 0b00010101, 0b00000101, 0b00000010}, // 31:63 ? +{5, 0b00001110, 0b00010001, 0b00010101, 0b00001001, 0b00001110}, // 32:64 @ +{5, 0b00011110, 0b00000101, 0b00000101, 0b00000101, 0b00011110}, // 33:65 A +{5, 0b00011111, 0b00010101, 0b00010101, 0b00010101, 0b00001010}, // 34:66 B +{5, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001}, // 35:67 C +{5, 0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 36:68 D +{5, 0b00011111, 0b00010101, 0b00010101, 0b00010101, 0b00010101}, // 37:69 E +{5, 0b00011111, 0b00000101, 0b00000101, 0b00000001, 0b00000001}, // 38:70 F +{5, 0b00001110, 0b00010001, 0b00010101, 0b00010101, 0b00011101}, // 39:71 G + +{5, 0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00011111}, // 40:72 H +{3, 0b00010001, 0b00011111, 0b00010001, 0b00000000, 0b00000000}, // 41:73 I +{5, 0b00001000, 0b00010000, 0b00010001, 0b00010001, 0b00001111}, // 42:74 J +{5, 0b00011111, 0b00000100, 0b00000100, 0b00001010, 0b00010001}, // 43:75 K +{5, 0b00011111, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 44:76 L +{5, 0b00011111, 0b00000010, 0b00000100, 0b00000010, 0b00011111}, // 45:77 M +{5, 0b00011111, 0b00000001, 0b00001110, 0b00010000, 0b00011111}, // 46:78 N +{5, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 47:79 O +{5, 0b00011111, 0b00000101, 0b00000101, 0b00000101, 0b00000010}, // 48:80 P +{5, 0b00001110, 0b00010001, 0b00010001, 0b00011110, 0b00010000}, // 49:81 Q + +{5, 0b00011111, 0b00000101, 0b00000101, 0b00001101, 0b00010010}, // 50:82 R +{5, 0b00010010, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, // 51:83 S +{5, 0b00000001, 0b00000001, 0b00011111, 0b00000001, 0b00000001}, // 52:84 T +{5, 0b00001111, 0b00010000, 0b00010000, 0b00010000, 0b00001111}, // 53:85 U +{5, 0b00000011, 0b00001100, 0b00010000, 0b00001100, 0b00000011}, // 54:86 V +{5, 0b00000111, 0b00011000, 0b00000110, 0b00011000, 0b00000111}, // 55:87 W +{5, 0b00010001, 0b00001010, 0b00000100, 0b00001010, 0b00010001}, // 56:88 X +{5, 0b00000001, 0b00000010, 0b00011100, 0b00000010, 0b00000001}, // 57:89 Y +{5, 0b00010001, 0b00011001, 0b00010101, 0b00010011, 0b00010001}, // 58:90 Z +{3, 0b00011111, 0b00010001, 0b00010001, 0b00000000, 0b00000000}, // 59:91 [ + +{5, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 60:92 \ +{0, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // ??? WHAT THE HELL? Putting this here somehow makes everything work. +{5, 0b00010001, 0b00010001, 0b00011111, 0b00000000, 0b00000000}, // 61:93 ] +{5, 0b00000010, 0b00000001, 0b00000010, 0b00000000, 0b00000000}, // 62:94 ^ +{5, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 63:95 _ +{2, 0b00000001, 0b00000010, 0b00000000, 0b00000000, 0b00000000}, // 64:96 ` +{5, 0b00001001, 0b00010101, 0b00010101, 0b00010101, 0b00011110}, // 65:97 a +{5, 0b00011111, 0b00010010, 0b00010010, 0b00010010, 0b00001100}, // 66:98 b +{5, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001010}, // 67:99 c +{5, 0b00001100, 0b00010010, 0b00010010, 0b00010010, 0b00011111}, // 68:100 d +{5, 0b00001110, 0b00010101, 0b00010101, 0b00010101, 0b00010110}, // 69:101 e + +{5, 0b00011110, 0b00000101, 0b00000101, 0b00000001, 0b00000001}, // 70:102 f +{5, 0b00010010, 0b00010101, 0b00010101, 0b00010101, 0b00001110}, // 71:103 g +{5, 0b00011111, 0b00000010, 0b00000010, 0b00000010, 0b00011100}, // 72:104 h +{1, 0b00011101, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // 73:105 i +{5, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00001111}, // 74:106 j +{5, 0b00011111, 0b00000100, 0b00000100, 0b00001010, 0b00010001}, // 75:107 k +{5, 0b00001111, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 76:108 l +{5, 0b00011110, 0b00000001, 0b00011110, 0b00000001, 0b00011110}, // 77:109 m +{5, 0b00011111, 0b00000001, 0b00000001, 0b00000001, 0b00011110}, // 78:110 n +{5, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110}, // 79:111 o + +{5, 0b00011111, 0b00001001, 0b00001001, 0b00001001, 0b00000110}, //112 p +{5, 0b00000110, 0b00001001, 0b00001001, 0b00001001, 0b00011111}, //113 q +{5, 0b00011111, 0b00000010, 0b00000001, 0b00000001, 0b00000010}, //114 r +{5, 0b00010010, 0b00010101, 0b00010101, 0b00010101, 0b00001001}, //115 s +{5, 0b00001111, 0b00010010, 0b00010010, 0b00010000, 0b00001000}, //116 t +{5, 0b00001111, 0b00010000, 0b00010000, 0b00001000, 0b00011111}, //117 u +{5, 0b00000011, 0b00001100, 0b00010000, 0b00001100, 0b00000011}, //118 v +{5, 0b00001111, 0b00010000, 0b00001111, 0b00010000, 0b00001111}, //119 w +{5, 0b00011011, 0b00000100, 0b00000100, 0b00000100, 0b00011011}, //120 x +{5, 0b00010011, 0b00010100, 0b00010100, 0b00010100, 0b00001111}, //121 y + +{5, 0b00100001, 0b00011001, 0b00010101, 0b00010110, 0b00010001}, //122 z +{3, 0b00000100, 0b00001110, 0b00010001, 0b00000000, 0b00000000}, //123 { +{1, 0b00011111, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, //124 | +{3, 0b00010001, 0b00001110, 0b00000100, 0b00000000, 0b00000000}, //125 } +{4, 0b00000010, 0b00000001, 0b00000010, 0b00000001, 0b00000000}, //126 ~ +}; + + + + + + diff --git a/messages.h b/messages.h index 12221f5..4ecaa28 100644 --- a/messages.h +++ b/messages.h @@ -8,9 +8,9 @@ const char string2[] PROGMEM = "macetech.com "; // Setup for serial -char messageBuffer[140] = "Upload message now... "; +char messageBuffer[240] = "Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz { | } ~ "; int messageLen = 0; - +// {|}~!\"#$%&'()*+.-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_` const char * const stringArray[] PROGMEM = { string0, string1, diff --git a/utils.h b/utils.h index c330295..1f4b449 100644 --- a/utils.h +++ b/utils.h @@ -148,16 +148,14 @@ void selectFlashString(byte string) { void loadCharBuffer(byte character) { int mappedCharacter = characterMapping(character); - for (byte i = 0; i < 5; i++) { - charBuffer[i] = pgm_read_byte(Font[mappedCharacter]+(i+1)); + for (byte i = 1; i < 6; i++) { + charBuffer[i-1] = pgm_read_byte(Font[mappedCharacter]+i); } } int loadCharWidth(byte character){ int mappedCharacter = characterMapping(character); - Serial.print("mappedCharacter: "); - Serial.println(mappedCharacter); return (int)pgm_read_byte(Font[mappedCharacter]); } From 08067f0685a53bb6d81344e5dcc9420f32099bfc Mon Sep 17 00:00:00 2001 From: George Griffin Date: Mon, 12 Oct 2015 14:41:11 -0400 Subject: [PATCH 11/11] Some minor fixes --- effects.h | 4 ++-- font.h | 2 +- font2.h | 3 +-- messages.h | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/effects.h b/effects.h index 3ef39c6..d4bc664 100644 --- a/effects.h +++ b/effects.h @@ -261,13 +261,13 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { // startup tasks if (effectInit == false) { effectInit = true; - effectDelay = 100; + effectDelay = 35; currentMessageChar = 0; currentCharColumn = 0; selectFlashString(message); loadCharBuffer(loadStringChar(message, currentMessageChar)); charWidth = loadCharWidth(loadStringChar(message, currentMessageChar)); - //currentPalette = ForestColors_p; + //currentPalette = ForestColors_p ; currentPalette = RainbowColors_p; for (byte i = 0; i < kMatrixWidth; i++) bitBuffer[i] = 0; } diff --git a/font.h b/font.h index 4d91083..4a80be0 100644 --- a/font.h +++ b/font.h @@ -78,7 +78,7 @@ const char Font[][6] PROGMEM = { {0b00000101, 0b00000001, 0b00000010, 0b00011100, 0b00000010, 0b00000001}, // 89 Y {0b00000101, 0b00010001, 0b00011001, 0b00010101, 0b00010011, 0b00010001}, // 90 Z {0b00000101, 0b00000000, 0b00000000, 0b00011111, 0b00010001, 0b00010001}, // 91 [ -{0b00000101, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 92 \ +{0b00000101, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 92 (\) {0b00000101, 0b00010001, 0b00010001, 0b00011111, 0b00000000, 0b00000000}, // 93 ] {0b00000101, 0b00000100, 0b00000010, 0b00000001, 0b00000010, 0b00000100}, // 94 ^ {0b00000101, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 95 _ diff --git a/font2.h b/font2.h index d974cb0..7ba0918 100644 --- a/font2.h +++ b/font2.h @@ -84,8 +84,7 @@ const char Font[][6] PROGMEM = { {5, 0b00010001, 0b00011001, 0b00010101, 0b00010011, 0b00010001}, // 58:90 Z {3, 0b00011111, 0b00010001, 0b00010001, 0b00000000, 0b00000000}, // 59:91 [ -{5, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 60:92 \ -{0, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, // ??? WHAT THE HELL? Putting this here somehow makes everything work. +{5, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000}, // 60:92 (\) {5, 0b00010001, 0b00010001, 0b00011111, 0b00000000, 0b00000000}, // 61:93 ] {5, 0b00000010, 0b00000001, 0b00000010, 0b00000000, 0b00000000}, // 62:94 ^ {5, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000}, // 63:95 _ diff --git a/messages.h b/messages.h index 9966307..93e5565 100644 --- a/messages.h +++ b/messages.h @@ -1,6 +1,6 @@ // Scrolling messages -const char string0[] PROGMEM = "HELLO WORLD "; +const char string0[] PROGMEM = "RGBShades are totally amazeballs!!! "; const char string1[] PROGMEM = "RAINBOW TEXT! "; const char string2[] PROGMEM = "macetech.com "; //char string3[] PROGMEM = " ";