Advertisement
RamiChan

ScrollText

Apr 26th, 2016
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. // scrolltext demo for Adafruit RGBmatrixPanel library.
  2. // Demonstrates double-buffered animation on our 16x32 RGB LED matrix:
  3. // http://www.adafruit.com/products/420
  4.  
  5. // Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
  6. // for Adafruit Industries.
  7. // BSD license, all text above must be included in any redistribution.
  8.  
  9. #include <Adafruit_GFX.h> // Core graphics library
  10. #include <RGBmatrixPanel.h> // Hardware-specific library
  11.  
  12. // Similar to F(), but for PROGMEM string pointers rather than literals
  13. #define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr
  14.  
  15. #define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
  16. #define LAT A3
  17. #define OE 9
  18. #define A A0
  19. #define B A1
  20. #define C A2
  21. // Last parameter = 'true' enables double-buffering, for flicker-free,
  22. // buttery smooth animation. Note that NOTHING WILL SHOW ON THE DISPLAY
  23. // until the first call to swapBuffers(). This is normal.
  24. RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
  25. // Double-buffered mode consumes nearly all the RAM available on the
  26. // Arduino Uno -- only a handful of free bytes remain. Even the
  27. // following string needs to go in PROGMEM:
  28.  
  29. const char str[] PROGMEM = "Adafruit 16x32 RGB LED Matrix";
  30. int textX = matrix.width(),
  31. textMin = sizeof(str) * -12,
  32. hue = 0;
  33. int8_t ball[3][4] = {
  34. { 3, 0, 1, 1 }, // Initial X,Y pos & velocity for 3 bouncy balls
  35. { 17, 15, 1, -1 },
  36. { 27, 4, -1, 1 }
  37. };
  38. static const uint16_t PROGMEM ballcolor[3] = {
  39. 0x0080, // Green=1
  40. 0x0002, // Blue=1
  41. 0x1000 // Red=1
  42. };
  43.  
  44. void setup() {
  45. matrix.begin();
  46. matrix.setTextWrap(false); // Allow text to run off right edge
  47. matrix.setTextSize(2);
  48. }
  49.  
  50. void loop() {
  51. byte i;
  52.  
  53. // Clear background
  54. matrix.fillScreen(0);
  55.  
  56. // Bounce three balls around
  57. for(i=0; i<3; i++) {
  58. // Draw 'ball'
  59. matrix.fillCircle(ball[i][0], ball[i][1], 5, pgm_read_word(&ballcolor[i]));
  60. // Update X, Y position
  61. ball[i][0] += ball[i][2];
  62. ball[i][1] += ball[i][3];
  63. // Bounce off edges
  64. if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
  65. ball[i][2] *= -1;
  66. if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
  67. ball[i][3] *= -1;
  68. }
  69.  
  70. // Draw big scrolly text on top
  71. matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  72. matrix.setCursor(textX, 1);
  73. matrix.print(F2(str));
  74.  
  75. // Move text left (w/wrap), increase hue
  76. if((--textX) < textMin) textX = matrix.width();
  77. hue += 7;
  78. if(hue >= 1536) hue -= 1536;
  79.  
  80. // Update display
  81. matrix.swapBuffers(false);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement