Facebook
From Obese Cockroach, 1 Year ago, written in Plain Text.
This paste is a reply to Untitled from Sm - view diff
Embed
Download Paste or View Raw
Hits: 150
  1. #include <MD_Parola.h>
  2. #include <MD_MAX72xx.h>
  3. #include <SPI.h>
  4. #include "Font_Data.h"
  5.  
  6. #define DEBUG 0
  7.  
  8. #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
  9. #define MAX_ZONES 2
  10. #define ZONE_SIZE 8
  11. #define MAX_DEVICES (MAX_ZONES * ZONE_SIZE)
  12. #define SCROLL_SPEED  30
  13.  
  14. #define ZONE_UPPER  1
  15. #define ZONE_LOWER  0
  16.  
  17. #define CLK_PIN   13
  18. #define DATA_PIN  11
  19. #define CS_PIN    10
  20.  
  21. // HARDWARE SPI
  22. MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  23. // SOFTWARE SPI
  24. //MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
  25.  
  26. // Hardware adaptation parameters for scrolling
  27. bool invertUpperZone = false;
  28.  
  29. #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
  30. char *msg[] =
  31. {
  32.   "HellO",
  33.  
  34. };
  35.  
  36. void setup(void)
  37. {
  38.   invertUpperZone = (HARDWARE_TYPE == MD_MAX72XX::GENERIC_HW || HARDWARE_TYPE == MD_MAX72XX::PAROLA_HW);
  39.  
  40. #if DEBUG
  41.   Serial.begin(57600);
  42.   Serial.println("[Double Height demo start]");
  43. #endif
  44.  
  45.   P.begin(MAX_ZONES);
  46.  
  47.   P.setZone(ZONE_LOWER, 0, ZONE_SIZE - 1);
  48.   P.setFont(ZONE_LOWER, BigFontLower);
  49.  
  50.   P.setZone(ZONE_UPPER, ZONE_SIZE, MAX_DEVICES-1);
  51.   P.setFont(ZONE_UPPER, BigFontUpper);
  52.   P.setCharSpacing(P.getCharSpacing() * 2);
  53.   if (invertUpperZone)
  54.   {
  55.     P.setZoneEffect(ZONE_UPPER, true, PA_FLIP_UD);
  56.     P.setZoneEffect(ZONE_UPPER, true, PA_FLIP_LR);
  57.   }
  58. }
  59.  
  60. void loop(void)
  61. {
  62.   static uint8_t cycle = 0;
  63.  
  64.   P.displayAnimate();
  65.  
  66.   if (P.getZoneStatus(ZONE_LOWER) && P.getZoneStatus(ZONE_UPPER))
  67.   {
  68. #if DEBUG
  69.     Serial.println(cycle);
  70. #endif
  71.  
  72.     switch (cycle)
  73.     {
  74.     default:
  75.       P.setFont(ZONE_LOWER, BigFontLower);
  76.       P.setFont(ZONE_UPPER, BigFontUpper);
  77.       if (invertUpperZone)
  78.       {
  79.         P.displayZoneText(ZONE_LOWER, msg[cycle], PA_LEFT, SCROLL_SPEED, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  80.         P.displayZoneText(ZONE_UPPER, msg[cycle], PA_LEFT, SCROLL_SPEED, 0, PA_SCROLL_RIGHT, PA_SCROLL_RIGHT);
  81.       }
  82.       else
  83.       {
  84.         P.displayZoneText(ZONE_LOWER, msg[cycle], PA_RIGHT, SCROLL_SPEED, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  85.         P.displayZoneText(ZONE_UPPER, msg[cycle], PA_LEFT, SCROLL_SPEED, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  86.       }
  87.  
  88.       break;
  89.     }
  90.  
  91.     cycle = (cycle + 1) % ARRAY_SIZE(msg);
  92.  
  93.     P.displayClear();
  94.     P.synchZoneStart();
  95.   }
  96. }