Advertisement
RuiViana

MAX729_SD

Oct 2nd, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <SD.h>
  3. #include <MD_MAX72xx.h>
  4.  
  5. /////////////////////////////////
  6.  
  7. //declarações
  8. File myFile;
  9. int tecla = 2;
  10. int leitura;
  11. int contador;
  12. char c;
  13.  
  14. ///////////////////////////////
  15.  
  16. // Numero de modulos utilizados
  17. #define MAX_DEVICES 2
  18. // Ligacoes matrix
  19. #define DATA_PIN 4
  20. #define CS_PIN 5
  21. #define CLK_PIN 6
  22. MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
  23. // Velocidade do scroll
  24. #define SCROLL_DELAY 80
  25. // Colunas entre cada caracter
  26. #define CHAR_SPACING 1
  27.  
  28. #define BUF_SIZE 75
  29. char curMessage[BUF_SIZE];
  30. char newMessage[BUF_SIZE];
  31.  
  32. // int scrollDelay;
  33.  
  34. uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)
  35. {
  36. static char *p = curMessage;
  37. static uint8_t state = 0;
  38. static uint8_t curLen, showLen;
  39. static uint8_t cBuf[8];
  40. uint8_t colData;
  41.  
  42. switch(state)
  43. {
  44. case 0:
  45. showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
  46. curLen = 0;
  47. state++;
  48. if (*p == '\0')
  49. {
  50. p = curMessage;
  51. }
  52. case 1:
  53. colData = cBuf[curLen++];
  54. if (curLen == showLen)
  55. {
  56. showLen = CHAR_SPACING;
  57. curLen = 0;
  58. state = 2;
  59. }
  60. break;
  61. case 2:
  62. colData = 0;
  63. curLen++;
  64. if (curLen == showLen)
  65. state = 0;
  66. break;
  67. default:
  68. state = 0;
  69. }
  70. return(colData);
  71. }
  72.  
  73. void scrollText(void)
  74. {
  75. static uint32_t prevTime = 0;
  76. if (millis()-prevTime >= SCROLL_DELAY)
  77. {
  78. mx.transform(MD_MAX72XX::TSR);
  79. prevTime = millis();
  80. }
  81. }
  82.  
  83.  
  84.  
  85. void setup(){
  86. mx.begin();
  87. mx.setShiftDataInCallback(scrollDataSource);
  88. // Define o nivel de luminosidade
  89. mx.control(MD_MAX72XX::INTENSITY, 1);
  90. ////////////////////////////////////////
  91. Serial.begin(9600);
  92. pinMode(tecla, INPUT);
  93. while (!Serial) {
  94. }
  95. if (!SD.begin(7)){return;}
  96. }
  97. void loop(){
  98. leitura = digitalRead(tecla);
  99. if (leitura != 0) {
  100. contador = contador + 1;
  101. while(digitalRead(tecla) != 0) {}
  102. }
  103. if(contador == 3){
  104. contador = 0;}
  105. ///////////////////////////////
  106.  
  107. // caso 1
  108. if (contador == 0){
  109. myFile = SD.open("texto1.txt");
  110. if (myFile) {
  111. scrollText();
  112.  
  113. while (myFile.available()) {
  114. c = (myFile.read());
  115. char msg[75];
  116. sprintf(msg, "%d", c);
  117. strcpy(curMessage, msg );
  118. Serial.print(msg);
  119. newMessage[0] = '\0';
  120.  
  121. }
  122. // feixando
  123. myFile.close();
  124. }
  125. else {
  126. // erro de arquivo
  127. Serial.println("erro ao abrir o arquivo");
  128. }}
  129.  
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement