TFTDisplayText

Bu örnek, bir Arduino'ya bağlanır Arduino GLCD fotoğrafları nasıl metin çizileceğini gösterir. Arduino, A0 pinine bağlı bir analog sensörün değerini okur ve değeri onu üç saniyede bir güncellenerek LCD ekranda yazar.

Gerekli Donanım

  • Arduino Uno
  • Arduino TFT ekran
  • breadboard
  • bağlantı teli
  • bir adet 10 kilohm potansiyometre

devre

Gücü ve topraklamayı devre tahtasına gidiyor.

Potansiyometreyi breadboard üzerine seçilir. Bir tarafı toprağa, diğerini güce içindir. Orta pimi A0'a bakın.

Ekranı breadboard'a bağlıdır. Ekranın yan tarafındaki küçük mavi sekmeli ve oklu üstbilgiler. Ekranın yönüne dikkat edin, bu görüntülerde baş aşağı.

BL ve + 5V pinlerini güce ve GND'yi toprağa çıkıyor. CS-LD'yi pin 10'a, DC 9 pinin, RESET pin 8'e, MOSI pin 11'e ve SCK'yı 13 pinine açar. Leonardo kullanın farklı pinler kullanacaksınız. daha fazla ayrıntı için başlangıç sayfasına bakın.


Daha büyük sürüm için resimin üzerine tıklayınız

Kod

Ekranı kullanmak için önce SPI ve TFT kitaplıklarını eklemeniz gerekir.

#include <SPI.h>
#include <TFT.h>
[Kodu Al]

Ekranı Kontrol etmek Için kullanacağınız pinleri tanımlayın ettik TFTscreen Adlı Bir TFT kütüphanesi Örneği oluşturun. Ekranla her çalışmayı bu nesneye çalışıruracaksınız.

#define cs 10
#define dc 9
#define rst 8

TFT TFT ekran = TFT ( cs , dc , rst ) ;

Ekranı metinle güncellemek için dinamik içerik karakter dizisinde saklanmıştır.

char sensorPrintout[4];

setup() , ekranda planlama ve arka planda yazdırma. stroke() yazı tipinin rengini görüntülemek ve görüntülemek statik metin yazın. Bu durumda, "Sensör Değeri:" yazarsınız. Bu, ekranın üstünde kalacaktır ve çizim çalıştığı içindir değişmeyecektir. loop() girmeden önce, sensör değerlerinin gerçekten göze çarpması için metin incelemesi.

void setup ( ) {
TFTscreen. begin ( ) ;

TFTscreen. arka plan ( 0 , 0 , 0 ) ;

TFTscreen. inme ( 255 , 255 , 255 ) ;
TFTscreen. setTextSize ( 2 ) ;
TFTscreen. metin ( "Sensör Değeri:" , 0 , 0 ) ;
TFTscreen. setTextSize ( 5 ) ;
}

loop() içinde potansiyometreden değeri okuyun ve bir dizede saklayın. Genel dizide saklayarak bir char dizisine dönüştürün.

void loop ( ) {

String sensorVal = String ( analogRead ( A0 ) ) ;

sensorVal. toCharArray ( sensorPrintout , 4 ) ;

Metin rengini seçin (bu, potansiyometrede değere bağlı olarak metnin rengini seçmek için iyi bir yer) ve statik metnin altına göre yazdırın.

TFTscreen. inme ( 255 , 255 , 255 ) ;
TFTscreen. metin ( sensorPrintout , 0 , 20 ) ;

Saniyenin çeyreğini bekliyoruz, sonra bir sonraki çalıştırma loop() .

gecikme ( 250 ) ;
TFTscreen. inme ( 0 , 0 , 0 ) ;
TFTscreen. metin ( sensorPrintout , 0 , 20 ) ;
}

Çizimin listesinde aşağıdakidır:


 /* Arduino TFT text example This example demonstrates how to draw text on the TFT with an Arduino. The Arduino reads the value of an analog sensor attached to pin A0, and writes the value to the LCD screen, updating every quarter second. This example code is in the public domain Created 15 April 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/TFTDisplayText */ #include // Arduino LCD library #include // pin definition for the Uno #define cs 10 #define dc 9 #define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 // #define rst 1 // create an instance of the library TFT TFTscreen = TFT(cs, dc, rst); // char array to print to the screen char sensorPrintout[4]; void setup() { // Put this line at the beginning of every sketch that uses the GLCD: TFTscreen.begin(); // clear the screen with a black background TFTscreen.background(0, 0, 0); // write the static text to the screen // set the font color to white TFTscreen.stroke(255, 255, 255); // set the font size TFTscreen.setTextSize(2); // write the text to the top left corner of the screen TFTscreen.text("Sensor Value :\n ", 0, 0); // ste the font size very large for the loop TFTscreen.setTextSize(5); } void loop() { // Read the value of the sensor on A0 String sensorVal = String(analogRead(A0)); // convert the reading to a char array sensorVal.toCharArray(sensorPrintout, 4); // set the font color TFTscreen.stroke(255, 255, 255); // print the sensor value TFTscreen.text(sensorPrintout, 0, 20); // wait for a moment delay(250); // erase the text you just wrote TFTscreen.stroke(0, 0, 0); TFTscreen.text(sensorPrintout, 0, 20); }  /* Arduino TFT text example This example demonstrates how to draw text on the TFT with an Arduino. The Arduino reads the value of an analog sensor attached to pin A0, and writes the value to the LCD screen, updating every quarter second. This example code is in the public domain Created 15 April 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/TFTDisplayText */ #include // Arduino LCD library #include // pin definition for the Uno #define cs 10 #define dc 9 #define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 // #define rst 1 // create an instance of the library TFT TFTscreen = TFT(cs, dc, rst); // char array to print to the screen char sensorPrintout[4]; void setup() { // Put this line at the beginning of every sketch that uses the GLCD: TFTscreen.begin(); // clear the screen with a black background TFTscreen.background(0, 0, 0); // write the static text to the screen // set the font color to white TFTscreen.stroke(255, 255, 255); // set the font size TFTscreen.setTextSize(2); // write the text to the top left corner of the screen TFTscreen.text("Sensor Value :\n ", 0, 0); // ste the font size very large for the loop TFTscreen.setTextSize(5); } void loop() { // Read the value of the sensor on A0 String sensorVal = String(analogRead(A0)); // convert the reading to a char array sensorVal.toCharArray(sensorPrintout, 4); // set the font color TFTscreen.stroke(255, 255, 255); // print the sensor value TFTscreen.text(sensorPrintout, 0, 20); // wait for a moment delay(250); // erase the text you just wrote TFTscreen.stroke(0, 0, 0); TFTscreen.text(sensorPrintout, 0, 20); }  /* Arduino TFT text example This example demonstrates how to draw text on the TFT with an Arduino. The Arduino reads the value of an analog sensor attached to pin A0, and writes the value to the LCD screen, updating every quarter second. This example code is in the public domain Created 15 April 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/TFTDisplayText */ #include // Arduino LCD library #include // pin definition for the Uno #define cs 10 #define dc 9 #define rst 8 // pin definition for the Leonardo // #define cs 7 // #define dc 0 // #define rst 1 // create an instance of the library TFT TFTscreen = TFT(cs, dc, rst); // char array to print to the screen char sensorPrintout[4]; void setup() { // Put this line at the beginning of every sketch that uses the GLCD: TFTscreen.begin(); // clear the screen with a black background TFTscreen.background(0, 0, 0); // write the static text to the screen // set the font color to white TFTscreen.stroke(255, 255, 255); // set the font size TFTscreen.setTextSize(2); // write the text to the top left corner of the screen TFTscreen.text("Sensor Value :\n ", 0, 0); // ste the font size very large for the loop TFTscreen.setTextSize(5); } void loop() { // Read the value of the sensor on A0 String sensorVal = String(analogRead(A0)); // convert the reading to a char array sensorVal.toCharArray(sensorPrintout, 4); // set the font color TFTscreen.stroke(255, 255, 255); // print the sensor value TFTscreen.text(sensorPrintout, 0, 20); // wait for a moment delay(250); // erase the text you just wrote TFTscreen.stroke(0, 0, 0); TFTscreen.text(sensorPrintout, 0, 20); }