1 | /*
|
2 | * Pin Belegung:
|
3 | *
|
4 | * gebrückt auf beide Displays:
|
5 | * Arduino Display
|
6 | * +5V => VCC
|
7 | * GND => GND
|
8 | * 52 => SCL
|
9 | * 51 => SDA
|
10 | * 50 => MOSI-T
|
11 | *
|
12 | * Display 1:
|
13 | * 25 => DC
|
14 | * 27 => RES
|
15 | * 23 => CS
|
16 | * 3 => IRQ-T
|
17 | * 24 => CS-T
|
18 | *
|
19 | *
|
20 | * Display 2:
|
21 | * 35 => DC
|
22 | * 37 => RES
|
23 | * 33 => CS
|
24 | * 2 => IQR-T
|
25 | * 34 => CS-T
|
26 | */
|
27 |
|
28 |
|
29 | #include <Adafruit_GFX.h>
|
30 | #include <Adafruit_ST7735.h>
|
31 | #include <SPI.h>
|
32 | #include <XPT2046_Touchscreen.h>
|
33 | #include <Fonts/FreeSans9pt7b.h>
|
34 |
|
35 | //Variablen erstellen
|
36 | //Ein-/Ausgänge
|
37 | //Display Anzeige
|
38 | int RS[3] = {25, 35, 45};
|
39 | int CS[3] = {23, 33, 43};
|
40 | int RES[3] = {27, 37, 47};
|
41 | //Display Touch
|
42 | int CS_T[3] = {24, 34, 44};
|
43 | int IRQ_T[3] = {3, 2}; //Interuptible pins For Mega: 2,3,18,19,20,21
|
44 | //desweiteren müssen die Hardware SPI-pins angeschlossen werden: SCK=52, SDA=51, MISO=50
|
45 |
|
46 | //Zuletzt berührt
|
47 | TS_Point last_1;
|
48 | TS_Point last_2;
|
49 |
|
50 | //Definitionen
|
51 | //Diplay Touch
|
52 | #define TS_SMALLMIN 3850// 250//
|
53 | #define TS_LONGMIN 250
|
54 | #define TS_SMALLMAX 250// 3850
|
55 | #define TS_LONGMAX 3900
|
56 |
|
57 | //Objekte erstellen
|
58 | //Display Anzeige
|
59 | Adafruit_ST7735 tft_test[2] = {{CS[0], RS[0], RES[0]}, {CS[1], RS[1], RES[1]}};
|
60 | //Display Touch
|
61 | XPT2046_Touchscreen touch1 = (CS_T[0], IRQ_T[0]);
|
62 | XPT2046_Touchscreen touch2 = (CS_T[1], IRQ_T[1]);
|
63 |
|
64 |
|
65 | void setup() {
|
66 | //Serial starten
|
67 | Serial.begin(9600);
|
68 | Serial.println("Setup");
|
69 |
|
70 | //Display 1 starten
|
71 | tft_test[0].initR(INITR_GREENTAB);
|
72 | touch1.begin();
|
73 | touch1.setRotation(0);
|
74 |
|
75 | //Display 2 starten
|
76 | tft_test[1].initR(INITR_GREENTAB);
|
77 | touch2.begin();
|
78 | touch2.setRotation(0);
|
79 |
|
80 | //Display 1 Testbilder anzeigen
|
81 | //RGB 10 bit: 5 bits Blau, 6 bits Grün, 5 bits Rot
|
82 | // Blau = 0x001f, Grün = 0x07e0, Rot = 0xf800
|
83 | tft_test[0].fillScreen(0x07e0);
|
84 | tft_test[0].setFont(&FreeSans9pt7b);
|
85 | tft_test[0].setTextColor(0x0000, 0xffff);
|
86 | tft_test[0].setCursor(10, 20);
|
87 | tft_test[0].print("Test screen 2");
|
88 |
|
89 | //Display 1 Testbilder anzeigen
|
90 | tft_test[1].fillScreen(0x001f);
|
91 | tft_test[1].setFont(&FreeSans9pt7b);
|
92 | tft_test[1].setTextColor(0x0000, 0xffff);
|
93 | tft_test[1].setCursor(10, 20);
|
94 | tft_test[1].print("Test");
|
95 | }
|
96 |
|
97 | void loop() {
|
98 | //Display 1 Positionen von Clicks anzeigen
|
99 | if (touch1.touched()){
|
100 | last_1 = touch1.getPoint();
|
101 | Serial.println("Touch1: x:" + String(last_1.x) + "\ty:" + String(last_1.y) + "\tz:" + String(last_1.z));
|
102 | }
|
103 |
|
104 | //Display 2 Positionen von Clicks anzeigen
|
105 | if (touch2.touched()){
|
106 | last_2 = touch2.getPoint();
|
107 | Serial.println("touch2: x:" + String(last_2.x) + "\ty:" + String(last_2.y) + "\tz:" + String(last_2.z));
|
108 | }
|
109 |
|
110 | //ausgabe, wenn nur ein Display berührt wird
|
111 | if (touch2.touched() != touch1.touched()){
|
112 | Serial.println("Test");
|
113 | }
|
114 | }
|