Advertisement
Mark2020H

Arduino dot matrix display

Mar 31st, 2021
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. /*  Voidrealms Facebook  for attention of Bryan Cairns*/
  2.  
  3.  
  4. #include <MD_Parola.h>
  5. #include <MD_MAX72xx.h>
  6. #include <SPI.h>
  7.  
  8.  
  9. #define BUF_SIZE 100  
  10.  
  11. #define HARDWARE_TYPE MD_MAX72XX::FC16_HW  /*< --- This is the hardware desription */
  12. #define MAX_DEVICES 4
  13. #define PAUSE_TIME  4000
  14.  
  15. #define CLK_PIN   13
  16. #define DATA_PIN  11
  17. #define CS_PIN    10
  18.  
  19. // Global variables
  20.  
  21. // HARDWARE SPI
  22. MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  23.  
  24.  
  25. char newMessage[BUF_SIZE] = { "Are you Ready ? Enter new message " };
  26. bool msgReady = false ;
  27.  
  28. uint8_t scrollSpeed = 50;    // default frame delay value
  29. textEffect_t scrollEffect = PA_SCROLL_LEFT;
  30. textPosition_t scrollAlign = PA_LEFT;
  31. uint16_t scrollPause = 2000; // in milliseconds
  32.  
  33. char *pChar = newMessage; // this is a pointer declaration
  34.  
  35. bool printOnce = false ;
  36.  
  37.  
  38. void setup() {
  39.   Serial.begin(57600);
  40.  
  41.   delay(500) ;
  42.  
  43.   P.begin();
  44.   P.displayText(newMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
  45. }
  46.  
  47.  
  48.  
  49. void readSerialPort(void)
  50. {
  51.  
  52.  
  53.   while (Serial.available())
  54.   {
  55.    
  56.     // read first byte or first character
  57.     *pChar = (char)Serial.read();
  58.     // Check  for newline
  59.     if ((*pChar == '\n') || (pChar - newMessage >= BUF_SIZE-2)) // end of message character or full buffer
  60.     {
  61.       *pChar = '\0'; // end the string
  62.       // restart the index for next filling spree and flag we have a message waiting
  63.       pChar = newMessage;
  64.       msgReady = true;
  65.     }
  66.     else  // move char pointer to next position
  67.       pChar++;
  68.   }
  69.  
  70.     if(printOnce)
  71.     {
  72.     Serial.flush();
  73.    
  74.     Serial.println(newMessage) ;
  75.     printOnce = false ;
  76.    
  77.     }
  78.  
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85. void loop() {
  86.  
  87.  
  88.  
  89.  
  90.    
  91.       if (P.displayAnimate())
  92.           {
  93.             if (msgReady)
  94.             {
  95.              
  96.               printOnce =true ;
  97.               msgReady = false;
  98.             }
  99.             P.displayReset();
  100.           }
  101.  
  102.          
  103.   readSerialPort();
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement