Advertisement
WolfLarsen33

Untitled

Jan 28th, 2022
1,693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********************************************
  2.  *
  3.  *  HORLOGE PLASMA (prototype)
  4.  *
  5.  * L.VOLFOVSKY 26/01/2022
  6.  *********************************************/
  7.  
  8. #define WITH_PLASMA
  9.  
  10. #include <WiFi.h>
  11.  
  12. const char* ssid     = "freebox_chezmoi";
  13. const char* password = "1234567890";
  14.  
  15. #include <ESP32Time.h>
  16.  
  17. #define R1 25
  18. #define G1 26
  19. #define BL1 27
  20. #define R2 14
  21. #define G2 12
  22. #define BL2 13
  23. #define CH_A 23
  24. #define CH_B 19
  25. #define CH_C 5
  26. #define CH_D 17
  27. #define CH_E -1 // assign to any available pin if using two panels or 64x64 panels with 1/32 scan
  28. #define LAT 4
  29. #define OE 15
  30. #define CLK 16
  31.  
  32. #include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
  33. #include <FastLED.h>
  34.  
  35. #define PANEL_WIDTH 64
  36. #define PANEL_HEIGHT 32    // Panel height of 64 will required PIN_E to be defined.
  37. #define PANELS_NUMBER 2   // Number of chained panels, if just a single panel, obviously set to 1
  38. #define PIN_E -1
  39.  
  40. #define PANE_WIDTH PANEL_WIDTH * PANELS_NUMBER
  41. #define PANE_HEIGHT PANEL_HEIGHT
  42.  
  43. MatrixPanel_I2S_DMA *hdisplay = nullptr;
  44.  
  45. uint16_t time_counter = 0, cycles = 0, fps = 0;
  46. CRGB currentColor;
  47. //CRGBPalette16 palettes[] = {HeatColors_p, LavaColors_p, RainbowColors_p, RainbowStripeColors_p, CloudColors_p};
  48. //CRGBPalette16 palettes[] = {HeatColors2_p, LavaColors_p, CloudColors_p, OceanColors_p, ForestColors_p};
  49. CRGBPalette16 palettes[] = {HeatColors2_p, LavaColors2_p, CloudColors2_p, OceanColors2_p, ForestColors2_p};
  50. CRGBPalette16 currentPalette = palettes[0];
  51.  
  52. uint8_t intensite = 32;
  53.  
  54. //=================================================================================
  55. void setup() {
  56.   Serial.begin(115200);
  57.  
  58.   HUB75_I2S_CFG::i2s_pins _pins={R1, G1, BL1, R2, G2, BL2, CH_A, CH_B, CH_C, CH_D, CH_E, LAT, OE, CLK};
  59.   HUB75_I2S_CFG mxconfig(
  60.      PANEL_WIDTH
  61.     ,PANEL_HEIGHT
  62.     ,PANELS_NUMBER
  63.     ,_pins
  64.   );
  65.  
  66.   hdisplay = new MatrixPanel_I2S_DMA(mxconfig);
  67.   hdisplay->setBrightness8(intensite);    // 0-255 => 0-100%
  68.   if( not hdisplay->begin() ) {
  69.       Serial.println("I2S memory allocation failed...");
  70.   }
  71.   for (int r=31; r<=255; r+=32) {
  72.     for (int g=31; g<=255; g+=32) {
  73.       for (int b=31; b<=255; b+=32) {
  74.         hdisplay->fillScreenRGB888(r, g, b);
  75.         delay(1);
  76.       }
  77.     }
  78.   }
  79.   hdisplay->fillScreenRGB888(0, 0, 0);
  80.  
  81.   Serial.print("Connecting to ");
  82.   Serial.println(ssid);
  83.   hdisplay->setTextSize(1);
  84.   hdisplay->setCursor(0,0);
  85.   hdisplay->printf("Cnx:%s",ssid);
  86.   hdisplay->setCursor(0,10);
  87.   WiFi.begin(ssid, password);
  88.   int nbtry = 0;
  89.   while (WiFi.status() != WL_CONNECTED && nbtry++<20) {
  90.     delay(500);
  91.     Serial.print(".");
  92.     hdisplay->print(".");
  93.   }
  94.   hdisplay->setCursor(0,10);
  95.   if (nbtry<20) {
  96.     Serial.println();
  97.     Serial.println("Connecte au WiFi.");
  98.     Serial.println("IP: ");
  99.     Serial.println(WiFi.localIP());
  100.     hdisplay->print(WiFi.localIP());
  101.  
  102.     ESP32Time.begin();
  103.   }
  104.   else {
  105.     Serial.println();
  106.     Serial.println("Connexion impossible.");
  107.     hdisplay->print("Erreur cnx...");
  108.   }
  109.   delay(2000);
  110.  
  111.   currentPalette = palettes[0];
  112. }
  113.  
  114. //=================================================================================
  115. void loop() {
  116.  
  117.   time_t t = time(NULL);
  118.   struct tm *t_st;
  119.   t_st = localtime(&t);
  120.  
  121. #ifdef WITH_PLASMA
  122.   for (int x = 0; x < PANE_WIDTH; x++) {
  123.     for (int y = 0; y <  PANE_HEIGHT; y++) {
  124.       int16_t v = 0;
  125.       uint8_t wibble = sin8(time_counter);
  126.       v += sin16(x * wibble * 3 + time_counter);
  127.       v += cos16(y * (128 - wibble)  + time_counter);
  128.       v += sin16(y * x * cos8(-time_counter) / 8);
  129.  
  130.       currentColor = ColorFromPalette(currentPalette, (v >> 8) + 127); //, brightness, currentBlendType);
  131.       hdisplay->drawPixelRGB888(x, y, currentColor.r, currentColor.g, currentColor.b);
  132.     }
  133.     if (x%3==0) {
  134.       hdisplay->setTextSize(2);
  135.       hdisplay->setCursor(15,4);
  136.       hdisplay->setTextColor(hdisplay->color444(255, 255, 255));
  137.       hdisplay->printf("%02d:%02d:%02d",t_st->tm_hour, t_st->tm_min, t_st->tm_sec);
  138.       hdisplay->setTextSize(1);
  139.       hdisplay->setCursor(2,22);
  140.       hdisplay->printf("%c%c%c%c%c%c%c%c %02d/%02d/%04d", "Q  M V "[t_st->tm_wday], "iLMeJeS"[t_st->tm_wday], "muarena"[t_st->tm_wday], "anrcudm"[t_st->tm_wday], "nddrdre"[t_st->tm_wday], "ciieied"[t_st->tm_wday], "h  d di"[t_st->tm_wday], "e  i i "[t_st->tm_wday], t_st->tm_mday, 1 + t_st->tm_mon, 1900 + t_st->tm_year);
  141.     }
  142.   }
  143. #else
  144.   static uint32_t dly_afftime=0;
  145.   if (millis()-dly_afftime > 1000) {
  146.     dly_afftime = millis();
  147.     hdisplay->fillScreenRGB888(0, 0, 0);
  148.     hdisplay->setTextSize(2);
  149.     hdisplay->setCursor(15,4);
  150.     hdisplay->setTextColor(hdisplay->color444(255, 255, 255));
  151.     hdisplay->printf("%02d:%02d:%02d",t_st->tm_hour, t_st->tm_min, t_st->tm_sec);
  152.     hdisplay->setTextSize(1);
  153.     hdisplay->setCursor(2,22);
  154.     hdisplay->printf("%c%c%c%c%c%c%c%c %02d/%02d/%04d", "Q  M V "[t_st->tm_wday], "iLMeJeS"[t_st->tm_wday], "muarena"[t_st->tm_wday], "anrcudm"[t_st->tm_wday], "nddrdre"[t_st->tm_wday], "ciieied"[t_st->tm_wday], "h  d di"[t_st->tm_wday], "e  i i "[t_st->tm_wday], t_st->tm_mday, 1 + t_st->tm_mon, 1900 + t_st->tm_year);
  155.   }
  156. #endif
  157.  
  158. #ifdef WITH_PLASMA
  159.   ++time_counter;
  160.   ++cycles;
  161.  
  162.   if (cycles >= 512) {
  163.       time_counter = 0;
  164.       cycles = 0;
  165.       int pal = random(0,sizeof(palettes)/sizeof(palettes[0]));
  166.       currentPalette = palettes[pal];
  167.   }
  168. #endif
  169.  
  170. }
  171.  
  172. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement