Ana içeriğe atla

Arduino Tft Paint Uygulaması

                                                       Tft Ekran Proje Örneği
#include <Adafruit_GFX.h>   
#include <Adafruit_TFTLCD.h> 
#include <TouchScreen.h>
#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif
#define YP A2  
#define XM A1  
#define YM 6   
#define XP 7  
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;
void setup(void) {
  Serial.begin(9600);
  Serial.println(F("Paint!"));
  
  tft.reset();
  
  uint16_t identifier = tft.readID();
if(identifier==0x0101)    // bu 4 satırı mutlaka ekle...
      identifier=0x9341;
  if (identifier == 0x6767)
      identifier = 0x7575;//

  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    return;
  }
  tft.begin(identifier);
  tft.fillScreen(BLACK);  
  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
   tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE);
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
  currentcolor = RED;
  pinMode(13, OUTPUT);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    if (p.y < (TS_MINY-5)) {
      Serial.println("erase");
      // press the bottom of the screen to erase 
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);
    }
    // scale from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
    if (p.y < BOXSIZE) {
       oldcolor = currentcolor;
       if (p.x < BOXSIZE) { 
         currentcolor = RED; 
         tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*2) {
         currentcolor = YELLOW;
         tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*3) {
         currentcolor = GREEN;
         tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*4) {
         currentcolor = CYAN;
         tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*5) {
         currentcolor = BLUE;
         tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*6) {
         currentcolor = BLACK;
         tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
       }
       if (oldcolor != currentcolor) {
          if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
          if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
          if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
          if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
          if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
          if (oldcolor == BLACK) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
       }
    }
    if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
      tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
    }
  }
}


                                                     Proje Bağlantı Şeması











Yorumlar

Yorum Gönder

Bu blogdaki popüler yayınlar

Arduino İle 2.4 İnch Tft Lcd Kullanımı

                                                       Tft Ekran Nedir ? TFT, her piksel'in bir ila dört transistör tarafından kontrol edildiği LCD düz panel ekran türüdür. TFT kavramı İngilizce "Thin Film Transistor" kelimelerinin baş harflerinden oluşan bir kısaltmadır. Türkçe'de "ince film transistor" anlamına gelmektedir.                                                           Tft Ekran Proje Örneği #include <Adafruit_GFX.h>   #include <Adafruit_TFTLCD.h> #define LCD_CS A3 #define LCD_CD A2 #define LCD_WR A1 #define LCD_RD A0 #define LCD_RESET A4 #define  BLACK   0x0000 #define BLUE    0x001F #define RED     0xF800 #define GREEN   0x07E0 #define CYAN    0x07FF #define MAGENTA 0xF81F #define YELLOW  0xFFE0 #define WHITE   0xFFFF int a =100; Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); void setup() {   Serial.begin(9600);   tft.reset();     uint16_t identifier = tft.readID()

Arduino İle Pır Sensör Kullanımı

                                                        Pır Sensör Nedir ? Pasif infrared  sensör  ( PIR sensörü ), algılama alanındaki nesnelerden yayılan kızılötesi dalgayı algılayan elektronik bir cihazdır.  PIR sensörleri  genellikle alarm sistemlerinde kullanılan hareket dedektörlerinin yapımında kullanılmaktadır.                                                    Pır Sensör Proje Örneği int pirsensorPin = 1; // PIRsensorpini diye isim verildi int ledPin = 0; // LED pin diye isim verildi int deger = 0; void setup() { pinMode(pirsensorPin, INPUT); // pırsensor pini giriş olarak ayarlandı pinMode(ledPin, OUTPUT); // ledpin çıkış olarak ayarlandı Serial.begin(9600); //Serial Porttan başlatıldı } void loop(){ deger = digitalRead(pirsensorPin); // Dijital pin okunuyor Serial.println(deger); // Okunan değer seri portta gözüküyor if (deger == HIGH) { digitalWrite(ledPin, HIGH); //  okunan değer 1 ise LED yak } else{ digitalWrite(ledPin,LOW); // 

Nokia 5110 İle Ping-Pong Oyunu

                                                    Proje Kodları; #define PIN_SCE   7 #define PIN_RESET 6 #define PIN_DC    5 #define PIN_SDIN  4 #define PIN_SCLK  3 #define LCD_C     LOW #define LCD_D     HIGH #define LCD_X     84 #define LCD_Y     6 int barWidth = 16; int barHeight = 4; int ballPerimeter = 4; unsigned int bar1X = 0; unsigned int bar1Y = 0; unsigned int bar2X = 0; unsigned int bar2Y = LCD_Y * 8 - barHeight; int ballX = 0; int ballY = 0; boolean isBallUp = false; boolean isBallRight = true; byte pixels[LCD_X][LCD_Y]; unsigned long lastRefreshTime; const int refreshInterval = 150; byte gameState = 1; byte ballSpeed = 2; byte player1WinCount = 0; byte player2WinCount = 0; byte hitCount = 0; void setup(){   //Serial.begin(9600);   LcdInitialise();   restartGame(); } void loop(){   unsigned long now = millis();   if(now - lastRefreshTime > refreshInterval){       update();       refreshScreen();       lastRefreshTime = now;