Advertisement
Guest User

ScrollingSmiley

a guest
Jul 16th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. #include <avr/pgmspace.h> //AVR library for writing to ROM
  2. #include <Charliplexing.h> //Imports the library, which needs to be
  3. //Initialized in setup.
  4.  
  5. //Sets the time each frame is shown (milliseconds)
  6. const unsigned int blinkdelay = 75;
  7. boolean fadeMode = false;
  8. byte brightness = 7; //Brightness goes from 0-7
  9.  
  10. /*
  11. The BitMap array is what contains the frame data. Each line is one full frame.
  12. Since each number is 16 bits, we can easily fit all 14 LEDs per row into it.
  13. The number is calculated by adding up all the bits, starting with lowest on
  14. the left of each row. 18000 was chosen as the kill number, so make sure that
  15. is at the end of the matrix, or the program will continue to read into memory.
  16.  
  17. Here PROGMEM is called, which stores the array into ROM, which leaves us
  18. with our RAM. You cannot change the array during run-time, only when you
  19. upload to the Arduino. You will need to pull it out of ROM, which is covered
  20. below. If you want it to stay in RAM, just delete PROGMEM
  21. */
  22. PROGMEM const uint16_t BitMap[][9] = {
  23. //smiley face moving across screen
  24. //1 2 3 4 5 6 7 8 9
  25. {0, 0, 0, 0, 0, 0, 0, 0, 0},
  26. {0, 0, 0, 0, 1, 0, 0, 0, 0},
  27. {0, 0, 0, 0, 1, 0, 0, 0, 0},
  28. {0, 1, 1, 0, 3, 1, 1, 0, 0},
  29. {0, 1, 1, 0, 3, 1, 1, 0, 0},
  30. {0, 3, 3, 0, 6, 3, 3, 1, 0},
  31. {0, 3, 3, 0, 6, 3, 3, 1, 0},
  32. {0, 6, 6, 0, 12, 6, 7, 3, 1},
  33. {0, 6, 6, 0, 12, 6, 7, 3, 1},
  34. {0, 12, 12, 0, 24, 12, 14, 7, 3},
  35. {0, 12, 12, 0, 24, 12, 14, 7, 3},
  36. {0, 24, 24, 0, 48, 24, 29, 15, 7},
  37. {0, 24, 24, 0, 48, 24, 29, 15, 7},
  38. {0, 49, 49, 0, 96, 49, 59, 31, 14},
  39. {0, 49, 49, 0, 96, 49, 59, 31, 14},
  40. {0, 99, 99, 0, 193, 99, 119, 62, 28},
  41. {0, 99, 99, 0, 193, 99, 119, 62, 28},
  42. {0, 198, 198, 0, 387, 198, 238, 124, 56},
  43. {0, 198, 198, 0, 387, 198, 238, 124, 56},
  44. {0, 396, 396, 0, 774, 396, 476, 248, 112},
  45. {0, 396, 396, 0, 774, 396, 476, 248, 112},
  46. {0, 792, 792, 0, 1548, 792, 952, 496, 224},
  47. {0, 792, 792, 0, 1548, 792, 952, 496, 224},
  48. {0, 1584, 1584, 0, 3096, 1584, 1904, 992, 448},
  49. {0, 1584, 1584, 0, 3096, 1584, 1904, 992, 448},
  50. {0, 3168, 3168, 0, 6192, 3168, 3808, 1984, 896},
  51. {0, 3168, 3168, 0, 6192, 3168, 3808, 1984, 896},
  52. {0, 6336, 6336, 0, 12384, 6336, 7616, 3968, 1792},
  53. {0, 6336, 6336, 0, 12384, 6336, 7616, 3968, 1792},
  54. {0, 12672, 12672, 0, 8384, 12672, 15232, 7936, 3584},
  55. {0, 12672, 12672, 0, 8384, 12672, 15232, 7936, 3584},
  56. {0, 8960, 8960, 0, 384, 8960, 14080, 15872, 7168},
  57. {0, 8960, 8960, 0, 384, 8960, 14080, 15872, 7168},
  58. {0, 1536, 1536, 0, 768, 1536, 11776, 15360, 14336},
  59. {0, 1536, 1536, 0, 768, 1536, 11776, 15360, 14336},
  60. {0, 3072, 3072, 0, 1536, 3072, 7168, 14336, 12288},
  61. {0, 3072, 3072, 0, 1536, 3072, 7168, 14336, 12288},
  62. {0, 6144, 6144, 0, 3072, 6144, 14336, 12288, 8192},
  63. {0, 6144, 6144, 0, 3072, 6144, 14336, 12288, 8192},
  64. {0, 12288, 12288, 0, 6144, 12288, 12288, 8192, 0},
  65. {0, 12288, 12288, 0, 6144, 12288, 12288, 8192, 0},
  66. {0, 8192, 8192, 0, 12288, 8192, 8192, 0, 0},
  67. {0, 8192, 8192, 0, 12288, 8192, 8192, 0, 0},
  68. {0, 0, 0, 0, 8192, 0, 0, 0, 0},
  69. {0, 0, 0, 0, 8192, 0, 0, 0, 0},
  70. {0, 0, 0, 0, 0, 0, 0, 0, 0},
  71. {0, 0, 0, 0, 0, 0, 0, 0, 0},
  72. {18000}
  73. };
  74.  
  75. void setup() {
  76. LedSign::Init(GRAYSCALE); //Initializes the screen
  77. }
  78. void loop() {
  79.  
  80. if(fadeMode)
  81. for (uint8_t gray = 1; gray < SHADES; gray++)
  82. DisplayBitMap(gray); //Displays the bitmap
  83. else DisplayBitMap(brightness); //Displays the bitmap
  84. }
  85.  
  86. void DisplayBitMap(uint8_t grayscale)
  87. {
  88. boolean run=true; //While this is true, the screen updates
  89. byte frame = 0; //Frame counter
  90. byte line = 0; //Row counter
  91. unsigned long data; //Temporary storage of the row data
  92. unsigned long start = 0;
  93.  
  94. while(run == true) {
  95.  
  96. for(line = 0; line < 9; line++) {
  97.  
  98. //Here we fetch data from program memory with a pointer.
  99. data = pgm_read_word_near (&BitMap[frame][line]);
  100.  
  101. //Kills the loop if the kill number is found
  102. if (data==18000){
  103. run=false;
  104. }
  105.  
  106. //This is where the bit-shifting happens to pull out
  107. //each LED from a row. If the bit is 1, then the LED
  108. //is turned on, otherwise it is turned off.
  109. else for (byte led=0; led<14; ++led) {
  110. if (data & (1<<led)) {
  111. LedSign::Set(led, line, grayscale);
  112. }
  113. else {
  114. LedSign::Set(led, line, 0);
  115. }
  116. }
  117. }
  118.  
  119. LedSign::Flip(true);
  120.  
  121. unsigned long end = millis();
  122. unsigned long diff = end - start;
  123. if ( start && (diff < blinkdelay) )
  124. delay( blinkdelay - diff );
  125. start = end;
  126.  
  127. frame++;
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement