Minggu, 04 April 2021

Sketch ESP8266 + Panel P10 (Animasi Text Turun Naik)

Berikut ini adalah sketch / program arduino (esp8266) untuk menampilkan teks dengan animasi naik dan turun.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
/*
 * Pin on  DMD P10     GPIO      NODEMCU               Pin on  DS3231      NODEMCU                   Pin on  Buzzer       NODEMCU
        2  A        GPIO16    D0                            SCL         D1 (GPIO 5)                       +            RX (GPIO 3)
        4  B        GPIO12    D6                            SDA         D2 (GPIO 4)                       -            GND
        8  CLK      GPIO14    D5                            VCC         3V
        10 SCK      GPIO0     D3                            GND         GND
        12 R        GPIO13    D7
        1  NOE      GPIO15    D8
        3  GND      GND       GND
*/


#include <Timer.h>
#include <HJS589.h>
#include <fonts/ABLED_ArialRMTB10b_Hrfx7.h>

#define DISPLAYS_WIDE 3 //2 
#define DISPLAYS_HIGH 1
HJS589 Disp(DISPLAYS_WIDE, DISPLAYS_HIGH); 

// HJS589 P10 FUNGSI TAMBAHAN UNTUK NODEMCU ESP8266
void ICACHE_RAM_ATTR refresh() { 
  Disp.refresh();
  timer0_write(ESP.getCycleCount() + 80000);  
}

void Disp_init() {
  Disp.setDoubleBuffer(true);
  Disp.start();
  timer0_attachInterrupt(refresh);
  Disp.clear();
}

void setup() {
  // put your setup code here, to run once:
  
  //DMD
  Disp_init();
  Disp.setBrightness(90); //(20);
}

void loop() 
{
 
  // put your main code here, to run repeatedly:

  animasiYinYout(24, 0, 80, 4000, "TES YA");
  
}

void animasiYinYout(int x1, int y1, int kecepatan, int durasi, String teks)
{
  static int8_t y;
  static uint8_t d;           
  static uint32_t pM;
  uint32_t cM = millis();

  if (cM - pM >= kecepatan && d == 0)
  {
    pM = cM;
    y++;

    Disp.drawFilledRect(0, 0, 96, 15, 0);
    Disp.setFont(ABLED_ArialRMTB10b_Hrfx7);
    Disp.drawText(x1, y - 9 + y1, teks);
    Disp.drawText(78, 0, String(y));
    Disp.swapBuffers();
  }

  if (y > 8)
  {
    d = 1;
  }

  if (cM - pM > durasi && d == 1)
  {
    y = 0;
    pM = cM;
    d = 2;
  }

  if (cM - pM >= kecepatan && d == 2)
  {
    pM = cM;
    y--;

    Disp.drawFilledRect(12, 0, 96, 15, 0);
    Disp.setFont(ABLED_ArialRMTB10b_Hrfx7);
    Disp.drawText(x1, y + y1, teks);
    Disp.drawText(78, 0, String(y));
    Disp.swapBuffers();
  }
  
  if (y < -9)
  {
    y = 0;
    d = 0;
    pM = cM;
    
    delay(2000);
  }
}



2 komentar:

  1. tutorialnya bagus mas..nggk pelit ilmu juga, btw kalo misalnya setalh tulisan naik dan turun kemudian textnya running dan berulang lagi gmna sketchnya mas?

    BalasHapus
  2. Izin praktek kang, terimakasih

    BalasHapus