Skip to content

Commit 3b0d0a0

Browse files
committed
Refactored Effects, added several new effects.
Added a 'splash' on startup, shows the Pixelmatix logo and scrolls "Aurora by Pixelmatix". Added a BitmapPlayer for displaying 24bpp bitmaps, and an example pattern. Fixed a crash in PatterRainbowSmoke caused by a call to randomSeed, need to investigate further...
1 parent b65ea21 commit 3b0d0a0

File tree

12 files changed

+7336
-7165
lines changed

12 files changed

+7336
-7165
lines changed

Aurora.ino

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Effects effects;
5353
#include "GifPlayer.h"
5454
GifPlayer gifPlayer;
5555

56+
#include "BitmapPlayer.h"
57+
BitmapPlayer bitmapPlayer;
58+
59+
#include "Logo.h"
60+
5661
#include "Drawable.h"
5762
#include "Playlist.h"
5863
#include "Runnable.h"
@@ -112,10 +117,14 @@ void setup()
112117
matrix.begin();
113118
matrix.setBrightness(brightness);
114119
matrix.setColorCorrection(cc24);
115-
matrix.fillScreen(CRGB(CRGB::Black));
120+
drawLogo();
116121
matrix.swapBuffers();
117122
matrix.setFont(gohufont11b);
118123
matrix.setScrollStartOffsetFromLeft(8);
124+
matrix.setScrollOffsetFromTop(25);
125+
matrix.setScrollSpeed(60);
126+
matrix.setScrollMode(wrapForward);
127+
matrix.scrollText("Aurora by Pixelmatix", 1);
119128

120129
pinMode(SD_CARD_CS, OUTPUT);
121130
sdAvailable = SD.begin(SD_CARD_CS);
@@ -138,6 +147,8 @@ void setup()
138147

139148
if (sdAvailable)
140149
loadSettings();
150+
151+
while (matrix.getScrollStatus() != 0) {}
141152
}
142153

143154
void loop()

Aurora.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.30110.0
4+
VisualStudioVersion = 12.0.30723.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Aurora", "Aurora.vcxproj", "{B0C98204-D78F-4B9E-AAB9-0A8453BB16EC}"
77
EndProject

Aurora.vcxproj

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<WarningLevel>Level3</WarningLevel>
4545
<Optimization>Disabled</Optimization>
4646
<SDLCheck>true</SDLCheck>
47-
<AdditionalIncludeDirectories>F:\Arduino-1.0.6\hardware\teensy\cores\teensy3;F:\Arduino-1.0.6\hardware\teensy\cores\teensy3\utils;F:\Arduino-1.0.6\hardware\teensy\cores\teensy3\avr;C:\Users\Jason\Documents\Arduino\libraries\SmartMatrix;C:\Users\Jason\Documents\Arduino\libraries\SmartMatrix\utility;C:\Users\Jason\Documents\Arduino\libraries\FastLED;C:\Users\Jason\Documents\Arduino\libraries\FastLED\utility;C:\Users\Jason\Documents\Arduino\libraries\IRremote;C:\Users\Jason\Documents\Arduino\libraries\IRremote\utility;F:\Arduino-1.0.6\libraries\SdFat;F:\Arduino-1.0.6\libraries\SdFat\utility;F:\Arduino-1.0.6\libraries\Wire;F:\Arduino-1.0.6\libraries\Wire\utility;C:\Users\Jason\Documents\Arduino\libraries\Time;C:\Users\Jason\Documents\Arduino\libraries\Time\utility;C:\Users\Jason\Documents\Arduino\libraries\DS1307RTC;C:\Users\Jason\Documents\Arduino\libraries\DS1307RTC\utility;F:\Arduino-1.0.6\libraries;F:\Arduino-1.0.6\hardware\teensy\libraries;F:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\default\debuggers;C:\Users\Jason\Documents\Arduino\libraries;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\arm-none-eabi\include;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\arm-none-eabi\include;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\lib\gcc\arm-none-eabi\4.7.2\include;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\lib\gcc\arm-none-eabi\4.7.2\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
47+
<AdditionalIncludeDirectories>F:\Arduino-1.0.6\hardware\teensy\cores\teensy3;F:\Arduino-1.0.6\hardware\teensy\cores\teensy3\utils;F:\Arduino-1.0.6\hardware\teensy\cores\teensy3\avr;C:\Users\Jason\Documents\Arduino\libraries\SmartMatrix;C:\Users\Jason\Documents\Arduino\libraries\SmartMatrix\utility;C:\Users\Jason\Documents\Arduino\libraries\FastLED;C:\Users\Jason\Documents\Arduino\libraries\FastLED\utility;C:\Users\Jason\Documents\Arduino\libraries\IRremote;C:\Users\Jason\Documents\Arduino\libraries\IRremote\utility;F:\Arduino-1.0.6\libraries\SPI;F:\Arduino-1.0.6\libraries\SPI\utility;F:\Arduino-1.0.6\libraries\SD;F:\Arduino-1.0.6\libraries\SD\utility;F:\Arduino-1.0.6\libraries\Wire;F:\Arduino-1.0.6\libraries\Wire\utility;C:\Users\Jason\Documents\Arduino\libraries\Time;C:\Users\Jason\Documents\Arduino\libraries\Time\utility;C:\Users\Jason\Documents\Arduino\libraries\DS1307RTC;C:\Users\Jason\Documents\Arduino\libraries\DS1307RTC\utility;F:\Arduino-1.0.6\libraries;F:\Arduino-1.0.6\hardware\teensy\libraries;F:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\default\debuggers;C:\Users\Jason\Documents\Arduino\libraries;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\arm-none-eabi\include;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\arm-none-eabi\include;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\lib\gcc\arm-none-eabi\4.7.2\include;F:\Arduino-1.0.6\hardware\tools\arm-none-eabi\lib\gcc\arm-none-eabi\4.7.2\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
4848
<ForcedIncludeFiles>C:\Users\Jason\Documents\Arduino\Aurora-mf-release\Visual Micro\.Aurora-mf-release.vsarduino.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
4949
<IgnoreStandardIncludePath>true</IgnoreStandardIncludePath>
5050
<PreprocessorDefinitions>ARDUINO=106;ARDUINO_MAIN;__AVR__;__avr__;F_CPU=48000000;USB_SERIAL;LAYOUT_US_ENGLISH;__cplusplus;__MK20DX256__;TEENSYDUINO=120;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -80,6 +80,9 @@
8080
</ItemGroup>
8181
<ItemGroup>
8282
<ClInclude Include="Attractor.h" />
83+
<ClInclude Include="BitmapPlayer.h">
84+
<FileType>CppCode</FileType>
85+
</ClInclude>
8386
<ClInclude Include="Bitmaps.h" />
8487
<ClInclude Include="Boid.h" />
8588
<ClInclude Include="ClockDigitalShort.h" />
@@ -90,9 +93,15 @@
9093
<ClInclude Include="Animations.h" />
9194
<ClInclude Include="Hardware.h" />
9295
<ClInclude Include="IrCodes.h" />
96+
<ClInclude Include="Logo.h">
97+
<FileType>CppCode</FileType>
98+
</ClInclude>
9399
<ClInclude Include="Menu.h" />
94100
<ClInclude Include="MenuItem.h" />
95101
<ClInclude Include="PatternAttract.h" />
102+
<ClInclude Include="PatternBitmap.h">
103+
<FileType>CppCode</FileType>
104+
</ClInclude>
96105
<ClInclude Include="PatternBounce.h" />
97106
<ClInclude Include="PatternEffects.h">
98107
<FileType>CppCode</FileType>
@@ -159,7 +168,7 @@
159168
</ImportGroup>
160169
<ProjectExtensions>
161170
<VisualStudio>
162-
<UserProperties arduino.upload.port="COM6" VM_ADDITIONAL_PREPROC="F_CPU=48000000;USB_SERIAL;LAYOUT_US_ENGLISH" />
171+
<UserProperties arduino.upload.port="COM10" VM_ADDITIONAL_PREPROC="F_CPU=48000000;USB_SERIAL;LAYOUT_US_ENGLISH" />
163172
</VisualStudio>
164173
</ProjectExtensions>
165174
</Project>

BitmapPlayer.h

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* Aurora: https://github.com/pixelmatix/aurora
3+
* Copyright (c) 2014 Jason Coon
4+
*
5+
* Portions of this code are adapted from Adafruit's spitftbitmap example: https://github.com/adafruit/Adafruit_ILI9340/blob/master/examples/spitftbitmap/spitftbitmap.ino
6+
* Written by Limor Fried/Ladyada for Adafruit Industries: http://www.adafruit.com
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
9+
* this software and associated documentation files (the "Software"), to deal in
10+
* the Software without restriction, including without limitation the rights to
11+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12+
* the Software, and to permit persons to whom the Software is furnished to do so,
13+
* subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
#ifndef BitmapPlayer_H
27+
#define BitmapPlayer_H
28+
29+
#define BUFFPIXEL 64
30+
31+
class BitmapPlayer {
32+
private:
33+
// These read 16- and 32-bit types from the SD card file.
34+
// BMP data is stored little-endian, Arduino is little-endian too.
35+
// May need to reverse subscript order if porting elsewhere.
36+
37+
uint16_t read16(File& f) {
38+
uint16_t result;
39+
((uint8_t *) &result)[0] = f.read(); // LSB
40+
((uint8_t *) &result)[1] = f.read(); // MSB
41+
return result;
42+
}
43+
44+
uint32_t read32(File& f) {
45+
uint32_t result;
46+
((uint8_t *) &result)[0] = f.read(); // LSB
47+
((uint8_t *) &result)[1] = f.read();
48+
((uint8_t *) &result)[2] = f.read();
49+
((uint8_t *) &result)[3] = f.read(); // MSB
50+
return result;
51+
}
52+
53+
public:
54+
uint32_t drawBitmap(char *filename, uint8_t x = 0, uint8_t y = 0) {
55+
File bmpFile;
56+
int bmpWidth, bmpHeight; // W+H in pixels
57+
uint8_t bmpDepth; // Bit depth (currently must be 24)
58+
uint32_t bmpImageoffset; // Start of image data in file
59+
uint32_t rowSize; // Not always = bmpWidth; may have padding
60+
uint8_t sdbuffer[3 * BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
61+
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
62+
boolean goodBmp = false; // Set to true on valid header parse
63+
boolean flip = true; // BMP is stored bottom-to-top
64+
int w, h, row, col;
65+
// uint8_t r, g, b;
66+
uint32_t pos = 0, startTime = millis();
67+
68+
if ((x >= matrix.getScreenWidth()) || (y >= matrix.getScreenHeight())) return 0;
69+
70+
Serial.println();
71+
Serial.print("Loading image '");
72+
Serial.print(filename);
73+
Serial.println('\'');
74+
75+
// Open requested file on SD card
76+
bmpFile = SD.open(filename, O_READ);
77+
if (!bmpFile) {
78+
return 0;
79+
}
80+
81+
// Parse BMP header
82+
if (read16(bmpFile) == 0x4D42) { // BMP signature
83+
Serial.print("File size: ");
84+
Serial.println(read32(bmpFile));
85+
read32(bmpFile); // Read & ignore creator bytes
86+
bmpImageoffset = read32(bmpFile); // Start of image data
87+
Serial.print("Image Offset: ");
88+
Serial.println(bmpImageoffset, DEC);
89+
// Read DIB header
90+
Serial.print("Header size: ");
91+
Serial.println(read32(bmpFile));
92+
bmpWidth = read32(bmpFile);
93+
bmpHeight = read32(bmpFile);
94+
if (read16(bmpFile) == 1) { // # planes -- must be '1'
95+
bmpDepth = read16(bmpFile); // bits per pixel
96+
Serial.print("bmpDepth: ");
97+
Serial.println(bmpDepth);
98+
if ((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
99+
100+
goodBmp = true; // Supported BMP format -- proceed!
101+
Serial.print("Image size: ");
102+
Serial.print(bmpWidth);
103+
Serial.print('x');
104+
Serial.println(bmpHeight);
105+
106+
// BMP rows are padded (if needed) to 4-byte boundary
107+
rowSize = (bmpWidth * 3 + 3) & ~3;
108+
109+
// If bmpHeight is negative, image is in top-down order.
110+
// This is not canon but has been observed in the wild.
111+
if (bmpHeight < 0) {
112+
bmpHeight = -bmpHeight;
113+
flip = false;
114+
}
115+
116+
// Crop area to be loaded
117+
w = bmpWidth;
118+
h = bmpHeight;
119+
120+
if ((x + w - 1) >= matrix.getScreenWidth()) w = matrix.getScreenWidth() - x;
121+
if ((y + h - 1) >= matrix.getScreenHeight()) h = matrix.getScreenWidth() - y;
122+
123+
for (row = 0; row < h; row++) { // For each scanline...
124+
if (flip) // Bitmap is stored bottom-to-top order (normal BMP)
125+
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
126+
else // Bitmap is stored top-to-bottom
127+
pos = bmpImageoffset + row * rowSize;
128+
if (bmpFile.position() != pos) { // Need seek?
129+
bmpFile.seek(pos);
130+
buffidx = sizeof(sdbuffer); // Force buffer reload
131+
}
132+
133+
// optimize by setting pins now
134+
for (col = 0; col < w; col++) { // For each pixel...
135+
// Time to read more pixel data?
136+
if (buffidx >= sizeof(sdbuffer)) { // Indeed
137+
bmpFile.read(sdbuffer, sizeof(sdbuffer));
138+
buffidx = 0; // Set index to beginning
139+
}
140+
141+
// Convert pixel from BMP to Matrix format, push to display
142+
rgb24 color;
143+
color.blue = sdbuffer[buffidx++];
144+
color.green = sdbuffer[buffidx++];
145+
color.red = sdbuffer[buffidx++];
146+
147+
matrix.drawPixel(x + col, y + row, color);
148+
149+
} // end pixel
150+
} // end scanline
151+
// matrix.swapBuffers(true);
152+
Serial.print("Loaded in ");
153+
Serial.print(millis() - startTime);
154+
Serial.println(" ms");
155+
} // end goodBmp
156+
}
157+
}
158+
159+
bmpFile.close();
160+
161+
if (!goodBmp) {
162+
Serial.println("BMP format not recognized.");
163+
return 0;
164+
}
165+
else {
166+
return millis() - startTime;
167+
}
168+
}
169+
};
170+
171+
#endif

0 commit comments

Comments
 (0)