Advertisement
Guest User

Grad Cap Arduino Code

a guest
May 16th, 2016
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.74 KB | None | 0 0
  1. /*
  2. * Animated GIFs Display Code for SmartMatrix and 32x32 RGB LED Panels
  3. *
  4. * Uses SmartMatrix Library for Teensy 3.1 written by Louis Beaudoin at pixelmatix.com
  5. *
  6. * Written by: Craig A. Lindley
  7. *
  8. * Copyright (c) 2014 Craig A. Lindley
  9. * Refactoring by Louis Beaudoin (Pixelmatix)
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  12. * this software and associated documentation files (the "Software"), to deal in
  13. * the Software without restriction, including without limitation the rights to
  14. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  15. * the Software, and to permit persons to whom the Software is furnished to do so,
  16. * subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in all
  19. * copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  23. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  24. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  25. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  26. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28.  
  29. /*
  30. * This example displays 32x32 GIF animations loaded from a SD Card connected to the Teensy 3.1
  31. * The GIFs can be up to 32 pixels in width and height.
  32. * This code has been tested with 32x32 pixel and 16x16 pixel GIFs, but is optimized for 32x32 pixel GIFs.
  33. *
  34. * Wiring is on the default Teensy 3.1 SPI pins, and chip select can be on any GPIO,
  35. * set by defining SD_CS in the code below
  36. * Function | Pin
  37. * DOUT | 11
  38. * DIN | 12
  39. * CLK | 13
  40. * CS (default) | 15
  41. *
  42. * This code first looks for .gif files in the /gifs/ directory
  43. * (customize below with the GIF_DIRECTORY definition) then plays random GIFs in the directory,
  44. * looping each GIF for DISPLAY_TIME_SECONDS
  45. *
  46. * This example is meant to give you an idea of how to add GIF playback to your own sketch.
  47. * For a project that adds GIF playback with other features, take a look at
  48. * Light Appliance and Aurora:
  49. * https://github.com/CraigLindley/LightAppliance
  50. * https://github.com/pixelmatix/aurora
  51. *
  52. * If you find any GIFs that won't play properly, please attach them to a new
  53. * Issue post in the GitHub repo here:
  54. * https://github.com/pixelmatix/AnimatedGIFs/issues
  55. */
  56.  
  57. /*
  58. * CONFIGURATION:
  59. * - update the "SmartMatrix configuration and memory allocation" section to match the width and height and other configuration of your display
  60. * - Note for 128x32 and 64x64 displays - need to reduce RAM:
  61. * set kRefreshDepth=24 and kDmaBufferRows=2 or set USB Type: "None" in Arduino,
  62. * decrease refreshRate in setup() to 90 or lower to get good an accurate GIF frame rate
  63. * - WIDTH and HEIGHT are defined in GIFParseFunctions.cpp, update to match the size of your GIFs
  64. * only play GIFs that are size WIDTHxHEIGHT or smaller
  65. */
  66. #include <SmartMatrix3.h>
  67. #include <SPI.h>
  68. #include <SD.h>
  69. #include "GIFDecoder.h"
  70.  
  71. #define DISPLAY_TIME_SECONDS 10
  72. #define DISPLAY_TIME_SECONDS_GT_LOGO 10
  73.  
  74. #define ENABLE_SCROLLING 1
  75.  
  76. #define NUMBER_MESSAGES 13
  77.  
  78. // range 0-255
  79. const int defaultBrightness = 255;
  80.  
  81. const rgb24 COLOR_BLACK = {
  82. 0, 0, 0 };
  83.  
  84.  
  85. /* SmartMatrix configuration and memory allocation */
  86. #define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
  87. const uint8_t kMatrixWidth = 32; // known working: 32, 64, 96, 128
  88. const uint8_t kMatrixHeight = 32; // known working: 16, 32, 48, 64
  89. const uint8_t kRefreshDepth = 36; // known working: 24, 36, 48
  90. const uint8_t kDmaBufferRows = 2; // known working: 2-4
  91. const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
  92. const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE); // see http://docs.pixelmatix.com/SmartMatrix for options
  93. const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
  94. const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
  95.  
  96. SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
  97. SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
  98. #if ENABLE_SCROLLING == 1
  99. SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer1, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
  100. SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer2, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
  101. SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer3, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
  102. #endif
  103.  
  104. // Chip select for SD card on the SmartMatrix Shield
  105. #define SD_CS 15
  106.  
  107. #define GIF_DIRECTORY "/gifs/"
  108. #define GT_DIRECTORY "/gtgif/"
  109.  
  110. int num_files;
  111.  
  112. void screenClearCallback(void) {
  113. backgroundLayer.fillScreen({0,0,0});
  114. }
  115.  
  116. void updateScreenCallback(void) {
  117. backgroundLayer.swapBuffers();
  118. }
  119.  
  120. void drawPixelCallback(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t blue) {
  121. backgroundLayer.drawPixel(x, y, {red, green, blue});
  122. }
  123.  
  124. // Setup method runs once, when the sketch starts
  125. void setup() {
  126. setScreenClearCallback(screenClearCallback);
  127. setUpdateScreenCallback(updateScreenCallback);
  128. setDrawPixelCallback(drawPixelCallback);
  129.  
  130. // Seed the random number generator
  131. randomSeed(analogRead(14));
  132.  
  133. Serial.begin(115200);
  134.  
  135. // Initialize matrix
  136. matrix.addLayer(&backgroundLayer);
  137. #if ENABLE_SCROLLING == 1
  138. matrix.addLayer(&scrollingLayer1);
  139. matrix.addLayer(&scrollingLayer2);
  140. matrix.addLayer(&scrollingLayer3);
  141.  
  142. scrollingLayer1.setMode(wrapForward);
  143.  
  144. scrollingLayer3.setMode(wrapForward);
  145.  
  146.  
  147. scrollingLayer1.setColor({0x00, 0x00, 0xff});
  148. scrollingLayer2.setColor({0xff, 0x00, 0xff});
  149. scrollingLayer3.setColor({0xff, 0xff, 0x00});
  150.  
  151.  
  152. #endif
  153.  
  154. matrix.begin();
  155.  
  156. //matrix.setRefreshRate(90);
  157. // for large panels, set the refresh rate lower to leave more CPU time to decoding GIFs (needed if GIFs are playing back slowly)
  158.  
  159. // Clear screen
  160. backgroundLayer.fillScreen(COLOR_BLACK);
  161. backgroundLayer.swapBuffers();
  162.  
  163. // initialize the SD card at full speed
  164. pinMode(SD_CS, OUTPUT);
  165. if (!SD.begin(SD_CS)) {
  166. #if ENABLE_SCROLLING == 1
  167.  
  168. scrollingLayer1.start("No SD card", -1);
  169. #endif
  170. Serial.println("No SD card");
  171. while(1);
  172. }
  173.  
  174. // Determine how many animated GIF files exist
  175. num_files = enumerateGIFFiles(GIF_DIRECTORY, false);
  176.  
  177. if(num_files < 0) {
  178. #if ENABLE_SCROLLING == 1
  179. scrollingLayer1.start("No gifs directory", -1);
  180. #endif
  181. Serial.println("No gifs directory");
  182. while(1);
  183. }
  184.  
  185. if(!num_files) {
  186. #if ENABLE_SCROLLING == 1
  187. scrollingLayer1.start("Empty gifs directory", -1);
  188. #endif
  189. Serial.println("Empty gifs directory");
  190. while(1);
  191. }
  192. }
  193.  
  194.  
  195. void loop() {
  196. unsigned long futureTime;
  197. char pathname[30];
  198.  
  199. char* messages[] = {"I'm a Ramblin' Wreck from Georgia Tech, and a hell of an engineer.",
  200. "Oh well it's up with the White and Gold, down with the Red and Black.",
  201. "Thanks Mom and Dad!",
  202. "Thanks Rachel!",
  203. "GT Football: 2011: TECH 31 CU 17 -- 2012: TECH 21 USC 7",
  204. "2014: TECH 30 u[sic]ga 24, TECH 49 MSU 34 -- 2015: TECH 22 FSU 16",
  205. "Bachelor of Science in Electrical Engineering Class of 2016",
  206. "Georgia Tech Yellow Jacket Marching Band",
  207. "Georgia Tech Solar Racing",
  208. "Tau Beta Sigma - Epsilon Theta",
  209. "Co-op: Georgia Tech Research Institute Electronic Systems Laboratory",
  210. "Georgia Tech Lorraine",
  211. "Towers -> Woodruff -> Maulding",
  212.  
  213. };
  214.  
  215. int index = random(num_files);
  216. int gtindex = 0;
  217. int i = 0;
  218.  
  219. // Do forever
  220. while (true) {
  221. // Can clear screen for new animation here, but this might cause flicker with short animations
  222. // matrix.fillScreen(COLOR_BLACK);
  223. // matrix.swapBuffers();
  224.  
  225. //GT Logo Here
  226. futureTime = millis() + (DISPLAY_TIME_SECONDS_GT_LOGO * 1000);
  227. if (futureTime > millis()){
  228. scrollingLayer1.setMode(wrapForward);
  229. scrollingLayer1.start(messages[i], -1);
  230. i = (i + 1) % NUMBER_MESSAGES;
  231.  
  232. scrollingLayer3.setMode(wrapForward);
  233. scrollingLayer3.setOffsetFromTop((kMatrixHeight/2 + kMatrixHeight/4) + 1 );
  234. scrollingLayer3.start(messages[i], -1);
  235. i = (i + 1) % NUMBER_MESSAGES;
  236. }
  237.  
  238.  
  239.  
  240.  
  241. getGIFFilenameByIndex(GT_DIRECTORY, gtindex, pathname);
  242.  
  243.  
  244. // Calculate time in the future to terminate animation
  245. futureTime = millis() + (DISPLAY_TIME_SECONDS_GT_LOGO * 1000);
  246.  
  247. while (futureTime > millis()) {
  248. processGIFFile(pathname);
  249. }
  250.  
  251.  
  252. //Videos go here
  253. scrollingLayer1.start(" ", -1);
  254. scrollingLayer3.start(" ", -1);
  255. scrollingLayer1.setMode(stopped);
  256. scrollingLayer3.setMode(stopped);
  257.  
  258. futureTime = millis() + (DISPLAY_TIME_SECONDS * 1000);
  259.  
  260.  
  261.  
  262. getGIFFilenameByIndex(GIF_DIRECTORY, index++, pathname);
  263. if (index >= num_files) {
  264. index = 0;
  265. }
  266.  
  267. // Calculate time in the future to terminate animation
  268. futureTime = millis() + (DISPLAY_TIME_SECONDS * 1000);
  269.  
  270. while (futureTime > millis()) {
  271. processGIFFile(pathname);
  272. }
  273.  
  274. }
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement