demo.ino 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #include <SPI.h>
  2. #define SELECT() digitalWrite(9, 0)
  3. #define UNSELECT() digitalWrite(9, 1)
  4. void setup()
  5. {
  6. SPI.begin();
  7. pinMode(9, OUTPUT);
  8. UNSELECT();
  9. }
  10. static byte scroll;
  11. void start(int addr)
  12. {
  13. SELECT();
  14. SPI.transfer(scroll);
  15. SPI.transfer(addr >> 8);
  16. SPI.transfer(addr);
  17. }
  18. void cls()
  19. {
  20. start(0);
  21. for (uint16_t i = (128 * 128 * 2); i; i--)
  22. SPI.transfer(0);
  23. UNSELECT();
  24. }
  25. void xloop()
  26. {
  27. cls();
  28. for (int a = 30; a < 10000; a += 256) {
  29. start(a);
  30. for (int attr = 0; attr < 16; attr++) {
  31. SPI.transfer('*');
  32. SPI.transfer(attr);
  33. }
  34. SPI.transfer(0);
  35. SPI.transfer(0);
  36. for (int attr = 0; attr < 256; attr += 16) {
  37. SPI.transfer('*');
  38. SPI.transfer(attr);
  39. }
  40. UNSELECT();
  41. }
  42. delay(1000);
  43. }
  44. void demo_random()
  45. {
  46. cls();
  47. for (uint16_t i = 0; i < 60000; i++) {
  48. int a = random(128 * 48);
  49. start(2 * a);
  50. SPI.transfer(random(256));
  51. SPI.transfer(random(256));
  52. UNSELECT();
  53. }
  54. }
  55. void at(byte x, byte y, byte color, const char *s)
  56. {
  57. start(256 * y + 2 * x);
  58. while (*s) {
  59. SPI.transfer(*s++);
  60. SPI.transfer(color);
  61. }
  62. UNSELECT();
  63. }
  64. prog_char book[] PROGMEM =
  65. "A TALE OF TWO CITIES\n"
  66. "\n"
  67. "A STORY OF THE FRENCH REVOLUTION\n"
  68. "\n"
  69. "By Charles Dickens\n"
  70. "\n"
  71. "Book the First--Recalled to Life\n"
  72. "\n"
  73. "I. The Period\n"
  74. "\n"
  75. "It was the best of times,\n"
  76. "it was the worst of times,\n"
  77. "it was the age of wisdom,\n"
  78. "it was the age of foolishness,\n"
  79. "it was the epoch of belief,\n"
  80. "it was the epoch of incredulity,\n"
  81. "it was the season of Light,\n"
  82. "it was the season of Darkness,\n"
  83. "it was the spring of hope,\n"
  84. "it was the winter of despair,\n"
  85. "we had everything before us,\n"
  86. "we had nothing before us,\n"
  87. "we were all going direct to Heaven,\n"
  88. "we were all going direct the other way--\n"
  89. "in short, the period was so far like the present period,\n"
  90. "that some of its noisiest authorities insisted on its being\n"
  91. "received, for good or for evil, in the superlative degree of\n"
  92. "comparison only.\n"
  93. "\n"
  94. "There were a king with a large jaw and a queen with a plain\n"
  95. "face, on the throne of England; there were a king with a large\n"
  96. "jaw and a queen with a fair face, on the throne of France. In\n"
  97. "both countries it was clearer than crystal to the lords of\n"
  98. "the State preserves of loaves and fishes, that things in\n"
  99. "general were settled for ever.\n"
  100. "\n"
  101. "It was the year of Our Lord one thousand seven hundred\n"
  102. "and seventy-five. Spiritual revelations were conceded to\n"
  103. "England at that favoured period, as at this. Mrs. Southcott\n"
  104. "had recently attained her five-and-twentieth blessed birthday,\n"
  105. "of whom a prophetic private in the Life Guards had heralded\n"
  106. "the sublime appearance by announcing that arrangements were\n"
  107. "made for the swallowing up of London and Westminster. Even the\n"
  108. "Cock-lane ghost had been laid only a round dozen of years,\n"
  109. "after rapping out its messages, as the spirits of this very\n"
  110. "year last past (supernaturally deficient in originality)\n"
  111. "rapped out theirs. Mere messages in the earthly order of\n"
  112. "events had lately come to the English Crown and People, from\n"
  113. "a congress of British subjects in America: which, strange\n"
  114. "to relate, have proved more important to the human race than\n"
  115. "any communications yet received through any of the chickens\n"
  116. "of the Cock-lane brood.\n"
  117. "\n"
  118. "France, less favoured on the whole as to matters spiritual than\n"
  119. "her sister of the shield and trident, rolled with exceeding\n"
  120. "smoothness down hill, making paper money and spending it. Under\n"
  121. "the guidance of her Christian pastors, she entertained herself,\n"
  122. "besides, with such humane achievements as sentencing a youth\n"
  123. "to have his hands cut off, his tongue torn out with pincers,\n"
  124. "and his body burned alive, because he had not kneeled down\n"
  125. "in the rain to do honour to a dirty procession of monks\n"
  126. "which passed within his view, at a distance of some fifty or\n"
  127. "sixty yards. It is likely enough that, rooted in the woods\n"
  128. "of France and Norway, there were growing trees, when that\n"
  129. "sufferer was put to death, already marked by the Woodman,\n"
  130. "Fate, to come down and be sawn into boards, to make a certain\n"
  131. "movable framework with a sack and a knife in it, terrible\n"
  132. "in history. It is likely enough that in the rough outhouses\n"
  133. "of some tillers of the heavy lands adjacent to Paris, there\n"
  134. "were sheltered from the weather that very day, rude carts,\n"
  135. "bespattered with rustic mire, snuffed about by pigs, and\n"
  136. "roosted in by poultry, which the Farmer, Death, had already set\n"
  137. "apart to be his tumbrils of the Revolution. But that Woodman\n"
  138. "and that Farmer, though they work unceasingly, work silently,\n"
  139. "and no one heard them as they went about with muffled tread:\n"
  140. "the rather, forasmuch as to entertain any suspicion that they\n"
  141. "were awake, was to be atheistical and traitorous.\n"
  142. "\n"
  143. "In England, there was scarcely an amount of order and\n"
  144. "protection to justify much national boasting. Daring burglaries\n"
  145. "by armed men, and highway robberies, took place in the capital\n"
  146. "itself every night; families were publicly cautioned not to go\n"
  147. "out of town without removing their furniture to upholsterers'\n"
  148. "warehouses for security; the highwayman in the dark was a City\n"
  149. "tradesman in the light, and, being recognised and challenged\n"
  150. "by his fellow-tradesman whom he stopped in his character of\n"
  151. "`the Captain,' gallantly shot him through the head and rode\n"
  152. "away; the mail was waylaid by seven robbers, and the guard shot\n"
  153. "three dead, and then got shot dead himself by the other four,\n"
  154. "`in consequence of the failure of his ammunition:' after which\n"
  155. "the mail was robbed in peace; that magnificent potentate,\n"
  156. "the Lord Mayor of London, was made to stand and deliver on\n"
  157. "Turnham Green, by one highwayman, who despoiled the illustrious\n"
  158. "creature in sight of all his retinue; prisoners in London\n"
  159. "gaols fought battles with their turnkeys, and the majesty of\n"
  160. "the law fired blunderbusses in among them, loaded with rounds";
  161. void demo_book()
  162. {
  163. cls();
  164. char c;
  165. start(0);
  166. uint16_t y = 0;
  167. byte attr = 0x0f;
  168. char prev;
  169. for (prog_char *p = book; (c = pgm_read_byte(p)) != 0; p++) {
  170. if (c == '\n') {
  171. UNSELECT();
  172. ++y;
  173. start(256 * (y % 48) + 128 * (y / 48));
  174. prev = ' ';
  175. } else {
  176. if (prev == ' ') {
  177. if (c < 'Z')
  178. attr = 0x0f;
  179. else
  180. attr = 0x0a;
  181. }
  182. SPI.transfer(c);
  183. SPI.transfer(attr);
  184. prev = c;
  185. }
  186. }
  187. UNSELECT();
  188. }
  189. static void demo_colors()
  190. {
  191. cls();
  192. for (byte j = 0; j < 16; j++)
  193. for (byte i = 0; i < 16; i++) {
  194. byte attr = (j << 4) | i;
  195. at(8 * j, 3 * i + 0, attr, " ");
  196. at(8 * j, 3 * i + 1, attr, " *TEXT* ");
  197. at(8 * j, 3 * i + 2, attr, " ");
  198. }
  199. }
  200. void loop()
  201. {
  202. demo_colors();
  203. delay(4000);
  204. demo_book();
  205. delay(4000);
  206. demo_random();
  207. }
  208. class TTY: public Print {
  209. public:
  210. virtual size_t write(uint8_t character) {
  211. };
  212. private:
  213. // otherstuff
  214. };