Minggu, 24 Mei 2020

Membuat Scroll Text / Running Text / Tulisan berjalan dengan arduino dan display TFT 1.8"

Hallo Sobat Arduino Indonesia, Pada kali ini kami akan berbagai tutorial untuk membuat Scroll text atau running text atau tulisan berjalan pada TFT LCD 1.8" dengan menggunakan arduino Uno

TFT LCD (Thin film transistor liquid crystal display) adalah varian dari Liquid Crystal Display (LCD) yang menggunakan Transistor Film Tipis (TFT) teknologi untuk meningkatkan kualitas gambar seperti addressability dan kontras. TFT LCD matriks aktif LCD, berbeda dengan matriks pasif LCD atau sederhana, tampil dengan LCD dalam beberapa segmen. TFT LCD digunakan dalam peralatan termasuk televisi, monitor komputer, ponsel, video game portabel, PDA/Tablet, sistem navigasi dan proyektor.



Adapun bahan yang dibutuhkan adalah sebagai berikut :
  1. Arduino Uno
  2. TFT 1.8"
  3. Kabel Jumper male to male
  4. Projectboard
Library yang di butuhkan dalam pemrograman ini
  1.  Adafruit_GFX
  2. Adafruit_ST7735
Untuk wiring adalah sebagai berikut


Coding untuk scroll text / tulisan berjalan / running text sebagai berikut :


#include <Adafruit_GFX.h>  // Include core graphics library
#include <Adafruit_ST7735.h>  // Include Adafruit_ST7735 library to drive the display
#include <fonts/FreeSans9pt7b.h>
#include <fonts/FreeSans12pt7b.h>
#include <fonts/FreeSans18pt7b.h>
#include <fonts/FreeSans24pt7b.h>


// Declare pins for the display:
#define TFT_CS     10
#define TFT_RST    8  // You can also connect this to the Arduino reset in which case, set this #define pin to -1!
#define TFT_DC     9
// The rest of the pins are pre-selected as the default hardware SPI for Arduino Uno (SCK = 13 and SDA = 11)


// Create display:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


#include <Fonts/FreeSerif18pt7b.h>  // Add a custom font





int Variable1;  // Create a variable to have something dynamic to show on the display






void setup()  // Start of setup
{

  // Display setup:

  // Use this initializer if you're using a 1.8" TFT
  tft.initR(INITR_BLACKTAB);  // Initialize a ST7735S chip, black tab

  tft.fillScreen(ST7735_BLACK);  // Fill screen with black

  //tft.setRotation(0);  // Set orientation of the display. Values are from 0 to 3. If not declared, orientation would be 0,
                         // which is portrait mode.

  tft.setTextWrap(false);  // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
                           // To override this behavior (so text will run off the right side of the display - useful for
                           // scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
                           // with setTextWrap(true).

  tft.setTextColor(ST7735_WHITE);  // White on black
  tft.setTextSize(5);  // large letters
  tft.setRotation(1); // horizontal display
  //tft.println("Hello");

}  // End of setup




void scrolltext(int x, int y, const char *s, uint8_t dw = 1, const GFXfont *f = NULL, int sz = 1)
{
    int16_t x1, y1, wid = tft.width(), inview = 1;
    uint16_t w, h;
    tft.setFont(f);
    tft.setTextColor(YELLOW, BLACK);
    tft.setTextSize(sz);
    tft.setTextWrap(false);
    tft.getTextBounds((char*)s, x, y, &x1, &y1, &w, &h);
    //    w = strlen(s) * 6 * sz;

    for (int steps = wid + w; steps >= 0; steps -= dw) {
        x = steps - w;
        if (f != NULL) {
            inview = wid - x;
            if (inview > wid) inview = wid;
            if (inview > w) inview = w;
            tft.fillRect(x > 0 ? x : 0, y1, inview + dw, h, BLACK);
        }
        x -= dw;
        tft.setCursor(x, y);
        tft.print(s);
        if (f == NULL) tft.print("  "); //rubout trailing chars
        delay(5);
    }
}


void loop()
{
  
    scrolltext(0, 30, "Sekolah Robot Indonesia Mengucapkan Selamat Hari Raya Idul Fitri 1441 H , Mohon Maaf Lahir Dan Batin", 8, NULL, 6);
  
}

2 komentar:

  1. Assalamualaikum mas, saya boleh request artikel gak? Cara membuat RC Mobil/boat dengan arduino dan NRF24L01 WIRELESS 2.4GHZ. Maaf mas jika pertanyaan saya membingungkan.

    Jika mas bersedia untuk memberitahu update artikelnya, bisa kirim ke email saya alisunenmail@gmail.com

    BalasHapus
  2. Also give them a presentation on why they need to} take care of your company for a 12 months or even more until you establish your brand as a serious trader within the eyes of the market. This, along with the Wholesale Lock Manager and Wholesale Order & ReOrder apps have made our retailer a cohesive & user-friendly experience for each our prospects & our team. Having as many discounts as we wish to set up has made completely different discount tiers attainable and simple, and we LOVE an excellent import/export feature. Once you get the grasp of it, it's a fairly seamless experience. Libraries are completely different altogether because of|as a outcome of} they are not appear to be} trying to promote your guide. They have a set price range for purchasing books, so do not have|you do sex toy store not have} to offer them a high discount.

    BalasHapus