Advertisement
joeybab3

Untitled

Dec 21st, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.15 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <Button.h>
  4. #include <MaxMatrix.h>
  5. #include <avr/pgmspace.h>
  6.  
  7. PROGMEM prog_uchar CH[] = {
  8. 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  9. 1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
  10. 3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
  11. 5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
  12. 4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
  13. 5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
  14. 5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
  15. 1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
  16. 3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
  17. 3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
  18. 5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
  19. 5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
  20. 2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
  21. 4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
  22. 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
  23. 4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
  24. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
  25. 3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
  26. 4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
  27. 4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
  28. 4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
  29. 4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
  30. 4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
  31. 4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
  32. 4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
  33. 4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
  34. 2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
  35. 2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
  36. 3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
  37. 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
  38. 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
  39. 4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
  40. 5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
  41. 4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  42. 4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  43. 4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  44. 4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  45. 4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  46. 4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  47. 4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  48. 4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  49. 3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  50. 4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  51. 4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  52. 4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  53. 5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  54. 5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  55. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  56. 4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  57. 4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  58. 4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  59. 4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  60. 5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  61. 4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  62. 5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  63. 5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  64. 5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  65. 5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  66. 4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
  67. 2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
  68. 4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
  69. 2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
  70. 3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
  71. 4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
  72. 2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
  73. 4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
  74. 4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
  75. 4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
  76. 4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
  77. 4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
  78. 3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
  79. 4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
  80. 4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
  81. 3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
  82. 4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
  83. 4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
  84. 3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
  85. 5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
  86. 4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
  87. 4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
  88. 4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
  89. 4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
  90. 4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
  91. 4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
  92. 3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
  93. 4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
  94. 5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
  95. 5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
  96. 5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
  97. 4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
  98. 3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
  99. 3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
  100. 1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
  101. 3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
  102. 5, 8, B01010101,B10101010,B01010101,B10101010,B01010101,B10101010,B01010101,B10101010,  // ~
  103. };
  104.  
  105.  
  106.  
  107. int USE_POT_CONTROL = 0;
  108.  
  109. int data = 42;    // DIN pin of MAX7219 module
  110. int load = 40;    // CS pin of MAX7219 module
  111. int clock = 41;  // CLK pin of MAX7219 module
  112. int StringPos = 0;
  113. int maxInUse = 2;    //change this variable to set how many MAX7219's you'll use
  114. int maxNumber = maxInUse*8;
  115.  
  116. boolean reading;
  117. int Intensity = 5;
  118. int BUF_SIZE = 10;
  119.  
  120. int SPEED_IN = A0;
  121. int SCROLL_DELAY = 50;
  122. String location = "/homework.php HTTP/1.0";
  123. int t;
  124. int scrollDelay;
  125. char serialMessage[100];
  126. char newMessage[100];
  127. char *curMessage;
  128. boolean newMessageAvailable = false;
  129. char *readata;
  130. const char *s1;
  131. char inString[32]; // string for incoming serial data
  132. int stringPos = 0; // string index counter
  133. boolean startRead = false; // is reading?
  134.  
  135. MaxMatrix m(data, load, clock, maxInUse); // define module
  136.  
  137. byte buffer[100];
  138.  
  139. // Newer Ethernet shields have a MAC address printed on a sticker on the shield
  140. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  141. // if you don't want to use DNS (and reduce your sketch size)
  142. // use the numeric IP instead of the name for the server:
  143. //IPAddress server(74,125,232,128);  // numeric IP for site (no DNS)
  144. char server[] = "joeybabcock.me";    // name address for site (using DNS)
  145.  
  146. IPAddress ip(192,168,1,177);
  147.  
  148. EthernetClient client;
  149.  
  150.  
  151. void setup(){
  152.   m.init(); // module initialize
  153.   m.setIntensity(Intensity); // dot matix intensity 0-15
  154.   Serial.begin(38400); // serial communication initialize
  155.  
  156.  
  157.     scrollDelay = SCROLL_DELAY;
  158.   newMessage[0] = '\0';
  159.   // start the Ethernet connection:
  160.   if (Ethernet.begin(mac) == 0) {
  161.     Serial.println("Failed to configure Ethernet using DHCP");
  162.     // no point in carrying on, so do nothing forevermore:
  163.     // try to congifure using IP address instead of DHCP:
  164.     Ethernet.begin(mac, ip);
  165.   }
  166.   // give the Ethernet shield a second to initialize:
  167.   delay(1000);
  168.   Serial.println("connecting...");
  169.  
  170.   // if you get a connection, report back via serial:
  171. }
  172.  
  173. void loop(){
  174.     String pageValue = connectAndRead(); //connect to the server and read the output
  175.     printStringWithShift(pageValue, scrollDelay);
  176.   }
  177.  
  178.   // if the server's disconnected, stop the client:
  179.   if (!client.connected()) {
  180.     Serial.println();
  181.     Serial.println("disconnecting.");
  182.     client.stop();
  183.   }
  184. }
  185. String connectAndRead(){
  186.   //connect to the server
  187.  
  188.   Serial.println("connecting...");
  189.  
  190.   //port 80 is typical of a www page
  191.   if (client.connect(server, 80)) {
  192.     Serial.println("connected");
  193.     client.print("GET ");
  194.     client.println(location);
  195.     client.println();
  196.  
  197.     //Connected - Read the page
  198.     return readPage(); //go and read the output
  199.  
  200.   }else{
  201.     return "connection failed";
  202.   }
  203.  
  204. }
  205.  
  206. String readPage(){
  207.   //read the page, and capture & return everything between '<' and '>'
  208.  
  209.   stringPos = 0;
  210.   memset( &inString, 0, 32 ); //clear inString memory
  211.  
  212.   while(true){
  213.  
  214.     if (client.available()) {
  215.       char c = client.read();
  216.  
  217.       if (c == '<' ) { //'<' is our begining character
  218.         startRead = true; //Ready to start reading the part
  219.       }else if(startRead){
  220.  
  221.         if(c != '>'){ //'>' is our ending character
  222.           inString[stringPos] = c;
  223.           stringPos ++;
  224.         }else{
  225.           //got what we need here! We can disconnect now
  226.           startRead = false;
  227.           client.stop();
  228.           client.flush();
  229.           Serial.println("disconnecting.");
  230.           return inString;
  231.  
  232.         }
  233.  
  234.       }
  235.     }
  236.  
  237.   }
  238.  
  239. }
  240. void scrollText(void)
  241. {
  242.  
  243.   if(newMessageAvailable){  // there is a new message waiting
  244.     strcpy(serialMessage, newMessage);  // copy it in
  245.     newMessageAvailable = false;
  246.     printStringWithShift(serialMessage, scrollDelay);
  247.   }
  248. }
  249. void printCharWithShift(char c, int shift_speed){
  250.   Serial.print("Printing Char: ");
  251.   Serial.print(c);
  252.   Serial.print("\n");
  253.   shift_speed = 50;
  254.  
  255.  
  256.       m.setIntensity(Intensity);
  257.       if(Intensity < 0){
  258.         Intensity = 0;
  259.       }
  260.       m.setIntensity(Intensity);
  261.    
  262.  
  263.   if (c < 32) return;
  264.   c -= 32;
  265.   memcpy_P(buffer, CH + 7*c, 7);
  266.   m.writeSprite(maxNumber, 0, buffer);
  267.   m.setColumn(maxNumber + buffer[0], 0);
  268.  
  269.   for (int i=0; i<buffer[0]+1; i++)
  270.   {
  271.     delay(shift_speed);
  272.     m.shiftLeft(false, false);
  273.   }
  274. }
  275.  
  276. void printStringWithShift(char* s, int shift_speed){
  277.   while (*s != 0){
  278.     Serial.print(" String Left: ");
  279.     Serial.print(s);
  280.     Serial.print("\n");
  281.     shift_speed = 50;
  282.     printCharWithShift(*s, shift_speed);
  283.     s++;
  284.   }
  285. }
  286.  
  287. void printString(char* s)
  288. {
  289.  
  290.   int col = 0;
  291.   while (*s != 0)
  292.   {
  293.     if (*s < 32) continue;
  294.     char c = *s - 32;
  295.     memcpy_P(buffer, CH + 7*c, 7);
  296.     m.writeSprite(col, 0, buffer);
  297.     m.setColumn(col + buffer[0], 0);
  298.     col += buffer[0] + 1;
  299.     s++;
  300.   }
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement