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”. diff --git a/RGBShades.ino b/RGBShades.ino index 5583378..375e087 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 @@ -27,19 +36,20 @@ #define CHIPSET WS2811 // Global maximum brightness value, maximum 255 -#define MAXBRIGHTNESS 72 +#define MAXBRIGHTNESS 127 #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" #include "buttons.h" + // Runs one time at the start of the program (power up or reset) void setup() { @@ -52,9 +62,18 @@ 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; + Serial.readBytesUntil('\n', messageBuffer, sizeof(messageBuffer)); + effectInit = false; +} + + // list of functions that will be displayed functionList effectList[] = {threeSine, threeDee, @@ -69,7 +88,9 @@ functionList effectList[] = {threeSine, scrollTextZero, sideRain, shadesOutline, - hearts}; + hearts, + scrollTextSerial, + }; // Timing parameters #define cycleTime 15000 @@ -112,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 6140c2a..d4bc664 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 } @@ -46,15 +46,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 @@ -66,7 +66,7 @@ void plasma() { // Scanning pattern left/right, uses global hue cycle byte riderPos = 0; void rider() { - + // startup tasks if (effectInit == false) { effectInit = true; @@ -76,12 +76,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; } } @@ -102,8 +102,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; @@ -169,21 +169,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; } @@ -196,11 +196,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); } @@ -217,10 +217,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); } - + } @@ -236,83 +236,18 @@ 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; } -//leds run around the periphery of the shades, changing color every go 'round -boolean erase = false; -uint8_t x,y = 0; -void shadesOutline(){ - //startup tasks - if (effectInit == false) { - effectInit = true; - erase = false; - uint8_t x=0; - 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; - x++; - if (x == (sizeof(OutlineTable))) { - erase = !erase; - x = 0; - currentColor += random8(3,6); - if (currentColor > 15) currentColor -= 16; - } -} -//hearts that start small on the bottom and get larger as they grow upward -const uint8_t SmHeart[] = {46, 48, 53, 55, 60, 65}; -const uint8_t MedHeart[] = {31, 32, 34, 35, 38, 39, - 41, 42, 46, 47, 48, 55, 54, 53, 54, 55, 60, 65}; -const uint8_t LrgHeart[] = {15, 16, 18, 19, 24, 25, - 27, 28, 31, 32, 33, 34, 35, 38, 39, 40, 41, 42, - 46, 47, 48, 53, 54, 55, 60, 65}; -const uint8_t HugeHeart[] = {0, 1, 3, 4, 9, 10, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, - 27, 28, 29, 31, 32, 33, 34, 35, 38, 39, 40, 41, - 42, 46, 47, 48, 53, 54, 55, 60, 65}; -void hearts() { - if (effectInit == false) { - effectInit = true; - effectDelay = 250; - FastLED.clear(); - int x = 0; - int y = 0; - } - effectDelay = 250; - if (y==5) - y = 0; - if (y == 0) - for (x = 0; x < 6; x++) - leds[SmHeart[x]] = CRGB::Salmon; //Tried to transition from pink-ish to red. Kinda worked. - if (y == 1) - for (x = 0; x < 18; x++) - leds[MedHeart[x]] = CRGB::Tomato; - if (y == 2) - for (x = 0; x < 26; x++) - leds[LrgHeart[x]] = CRGB::Crimson; - if (y == 3){ - for (x = 0; x < 40; x++) - leds[HugeHeart[x]] = CRGB::Red; - effectDelay = 450;} //set the delay slightly longer for HUGE heart. - if (y == 4) - FastLED.clear(); - y++; -} + #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; @@ -321,7 +256,7 @@ 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) { @@ -331,14 +266,15 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { currentCharColumn = 0; selectFlashString(message); loadCharBuffer(loadStringChar(message, currentMessageChar)); + charWidth = loadCharWidth(loadStringChar(message, currentMessageChar)); + //currentPalette = ForestColors_p ; 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 @@ -361,7 +297,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); @@ -370,6 +306,7 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { nextChar = loadStringChar(message, currentMessageChar); } loadCharBuffer(nextChar); + charWidth = loadCharWidth(nextChar); } bitBufferPointer++; @@ -388,4 +325,75 @@ void scrollTextOne() { void scrollTextTwo() { scrollText(2, NORMAL, CRGB::Green, CRGB(0,0,8)); +} + +void scrollTextSerial(){ + scrollText(255, RAINBOW, CRGB::DarkRed, CRGB::Black); +} +//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) { + effectInit = true; + erase = false; + uint8_t x=0; + effectDelay = 15; + FastLED.clear(); + currentPalette = RainbowColors_p;} + + leds[OutlineTable[x]] = currentPalette[currentColor]; + if (erase) + leds[OutlineTable[x]] = CRGB::Black; + x++; + if (x == (sizeof(OutlineTable))) { + erase = !erase; + x = 0; + currentColor += random8(3,6); + if (currentColor > 15) currentColor -= 16; + } +} +//hearts that start small on the bottom and get larger as they grow upward +const uint8_t SmHeart[] = {46, 48, 53, 55, 60, 65}; +const uint8_t MedHeart[] = {31, 32, 34, 35, 38, 39, + 41, 42, 46, 47, 48, 55, 54, 53, 54, 55, 60, 65}; +const uint8_t LrgHeart[] = {15, 16, 18, 19, 24, 25, + 27, 28, 31, 32, 33, 34, 35, 38, 39, 40, 41, 42, + 46, 47, 48, 53, 54, 55, 60, 65}; +const uint8_t HugeHeart[] = {0, 1, 3, 4, 9, 10, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 23, 24, 25, 26, + 27, 28, 29, 31, 32, 33, 34, 35, 38, 39, 40, 41, + 42, 46, 47, 48, 53, 54, 55, 60, 65}; +void hearts() { + if (effectInit == false) { + effectInit = true; + effectDelay = 250; + FastLED.clear(); + int x = 0; + int y = 0; + } + effectDelay = 250; + if (y==5) + y = 0; + if (y == 0) + for (x = 0; x < 6; x++) + leds[SmHeart[x]] = CRGB::Salmon; //Tried to transition from pink-ish to red. Kinda worked. + if (y == 1) + for (x = 0; x < 18; x++) + leds[MedHeart[x]] = CRGB::Tomato; + if (y == 2) + for (x = 0; x < 26; x++) + leds[LrgHeart[x]] = CRGB::Crimson; + if (y == 3){ + for (x = 0; x < 40; x++) + leds[HugeHeart[x]] = CRGB::Red; + effectDelay = 450;} //set the delay slightly longer for HUGE heart. + if (y == 4) + FastLED.clear(); + y++; } \ No newline at end of file diff --git a/font.h b/font.h index b3671a0..4a80be0 100644 --- a/font.h +++ b/font.h @@ -1,73 +1,85 @@ -// 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 - - - +// Fetch font character bitmap from flash +byte charBuffer[5] = {0}; +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 \ No newline at end of file diff --git a/font2.h b/font2.h new file mode 100644 index 0000000..7ba0918 --- /dev/null +++ b/font2.h @@ -0,0 +1,131 @@ +// 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 (\) +{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 1d9ac4b..93e5565 100644 --- a/messages.h +++ b/messages.h @@ -1,13 +1,20 @@ // 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 = " "; + +// Setup for serial +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 {|}~!\"#$%&'()*+.-./\\0123456789:;<=>?"; +int messageLen = 0; +// {|}~!\"#$%&'()*+.-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_` + const char * const stringArray[] PROGMEM = { string0, string1, string2 //string3 -}; \ No newline at end of file + +}; diff --git a/utils.h b/utils.h index 42c99a9..8455495 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 @@ -57,6 +57,7 @@ void scrollArray(byte scrollDir) { } + // Pick a random palette from a list void selectRandomPalette() { @@ -90,7 +91,6 @@ void selectRandomPalette() { break; } - } void drawMeter(int step){ @@ -135,7 +135,6 @@ void confirmBlink() { FastLED.delay(200); } - } // Determine flash address of text string @@ -144,25 +143,25 @@ 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 - } + int mappedCharacter = characterMapping(character); - for (byte i = 0; i < 5; i++) { - charBuffer[i] = pgm_read_byte(Font[mappedCharacter]+i); + for (byte i = 1; i < 6; i++) { + charBuffer[i-1] = pgm_read_byte(Font[mappedCharacter]+i); } } +int loadCharWidth(byte character){ + int mappedCharacter = characterMapping(character); + return (int)pgm_read_byte(Font[mappedCharacter]); +} + // Fetch a character value from a text string in flash char loadStringChar(byte string, byte character) { - return (char) pgm_read_byte(currentStringAddress + character); -} + if(string == 255){ // displaying serial string + return messageBuffer[character]; + }else{ + return (char) pgm_read_byte(currentStringAddress + character); + } +} \ No newline at end of file