TFTGraph

Arduino TFT ekran için bu örnek bir potansiyometrenin değerini okur ve gerekiyor grafiğini çizer. Bu seri iletişim Grafiği örneğine benzer.

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.

TFT ekranını breadboard'a getiriyor. 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 ) ;

Grafiğin x ekseninin dışında tutmak için bir değişkenlikte. Bunu onun loop() . setup() , ekranda bir arka plan güzel bir renk haline getirin.

int xPos = 0 ;

void setup ( ) {
TFTscreen. begin ( ) ;
TFTscreen. arka plan ( 250 , 16 , 200 ) ;
}

loop() öğesinde potansiyometreden değer okuyun ve ekran yüksekliğine uyan bir değerle eşleyin.

void loop ( ) {
int algılayıcı = analogOkuma ( A0 ) ;
int graphHeight = harita ( sensör , 0 , 1023 , 0 , LCD ekran. yükseklik ( ) ) ;

Kontur rengini, arka plan için gerekli hoş renge karşı biri çıkacak bir şeye göre ve sensörün değerine göre ekranın altından bir çizgi çizin

TFTscreen. inme ( 250 , 180 , 10 ) ;
TFTscreen. çizgi (XPOS, TFTscreen Yüksekliği () - graphHeight, xPos, TFTscreen Yüksekliği ().).;

loop() kapatmadan önce, grafiğin ekranın kenarını geçmediğinden emin olun. Varsa, her şeyi silin ve x ekseninde 0'dan yapın.

altında ( xPos > = 160 ) {
xPos = 0 ;
TFTscreen. arka plan ( 250 , 16 , 200 ) ;
}
başka {
xPos ++;
}
gecikme ( 16 ) ;
}

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


 /* TFT Graph This example for an Arduino screen reads the value of an analog sensor on A0, and graphs the values on the screen. This example code is in the public domain. Created 15 April 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/TFTGraph */ #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 TFT TFTscreen = TFT(cs, dc, rst); // position of the line on screen int xPos = 0; void setup() { // initialize the serial port Serial.begin(9600); // initialize the display TFTscreen.begin(); // clear the screen with a pretty color TFTscreen.background(250, 16, 200); } void loop() { // read the sensor and map it to the screen height int sensor = analogRead(A0); int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height()); // print out the height to the serial monitor Serial.println(drawHeight); // draw a line in a nice color TFTscreen.stroke(250, 180, 10); TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height()); // if the graph has reached the screen edge // erase the screen and start again if (xPos >= 160) { xPos = 0; TFTscreen.background(250, 16, 200); } else { // increment the horizontal position: xPos++; } delay(16); }  /* TFT Graph This example for an Arduino screen reads the value of an analog sensor on A0, and graphs the values on the screen. This example code is in the public domain. Created 15 April 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/TFTGraph */ #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 TFT TFTscreen = TFT(cs, dc, rst); // position of the line on screen int xPos = 0; void setup() { // initialize the serial port Serial.begin(9600); // initialize the display TFTscreen.begin(); // clear the screen with a pretty color TFTscreen.background(250, 16, 200); } void loop() { // read the sensor and map it to the screen height int sensor = analogRead(A0); int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height()); // print out the height to the serial monitor Serial.println(drawHeight); // draw a line in a nice color TFTscreen.stroke(250, 180, 10); TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height()); // if the graph has reached the screen edge // erase the screen and start again if (xPos >= 160) { xPos = 0; TFTscreen.background(250, 16, 200); } else { // increment the horizontal position: xPos++; } delay(16); }  /* TFT Graph This example for an Arduino screen reads the value of an analog sensor on A0, and graphs the values on the screen. This example code is in the public domain. Created 15 April 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/TFTGraph */ #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 TFT TFTscreen = TFT(cs, dc, rst); // position of the line on screen int xPos = 0; void setup() { // initialize the serial port Serial.begin(9600); // initialize the display TFTscreen.begin(); // clear the screen with a pretty color TFTscreen.background(250, 16, 200); } void loop() { // read the sensor and map it to the screen height int sensor = analogRead(A0); int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height()); // print out the height to the serial monitor Serial.println(drawHeight); // draw a line in a nice color TFTscreen.stroke(250, 180, 10); TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height()); // if the graph has reached the screen edge // erase the screen and start again if (xPos >= 160) { xPos = 0; TFTscreen.background(250, 16, 200); } else { // increment the horizontal position: xPos++; } delay(16); }