Same problem here, find an solution?
I use a tft touch screen shield on an Uno and I want to send data to an other arduino.
The touchscreen works perfect and the slave recieves data.
But when i push a 'button' on my touchscreen ( and so send data to the slave) the screen goes fully white and the slave stops recieving...
master:
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <Wire.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
int straf = 5;
int drank;
// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 6, XM = A2, YP = A1, YM = 7; //240x320 ID=0x1505
const int TS_LEFT = 935, TS_RT = 152, TS_TOP = 922, TS_BOT = 129;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button knop1_btn, knop2_btn, knop3_btn, knop4_btn, knop5_btn, knop6_btn;
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}
return pressed;
}
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
void setup(void)
{
// open the serial port at 9600 bps:
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
tft.begin(0x1505);
tft.setRotation(2); //PORTRAIT
tft.fillScreen(BLACK);
knop1_btn.initButton(&tft, 120, 34, 200, 34, WHITE, CYAN, BLACK, "baco", 3); //x,y,breedte,hoogte
knop2_btn.initButton(&tft, 120, 87, 200, 34, WHITE, CYAN, BLACK, "ginto", 3);
knop3_btn.initButton(&tft, 120, 140, 200, 34, WHITE, CYAN, BLACK, "wodtea", 3);
knop4_btn.initButton(&tft, 30, 200, 40, 40, WHITE, CYAN, BLACK, "-", 3);
knop5_btn.initButton(&tft, 210, 200, 40, 40, WHITE, CYAN, BLACK, "+", 3);
knop6_btn.initButton(&tft, 120, 270, 220, 40, WHITE, CYAN, BLACK, "maak", 3);
knop1_btn.drawButton(false);
knop2_btn.drawButton(false);
knop3_btn.drawButton(false);
knop4_btn.drawButton(false);
knop5_btn.drawButton(false);
knop6_btn.drawButton(false);
}
void loop(void)
{
bool down = Touch_getXY();
straf = min(straf, 9);
straf = max(straf, 0);
knop1_btn.press(down && knop1_btn.contains(pixel_x, pixel_y));
knop2_btn.press(down && knop2_btn.contains(pixel_x, pixel_y));
knop3_btn.press(down && knop3_btn.contains(pixel_x, pixel_y));
knop4_btn.press(down && knop4_btn.contains(pixel_x, pixel_y));
knop5_btn.press(down && knop5_btn.contains(pixel_x, pixel_y));
knop6_btn.press(down && knop6_btn.contains(pixel_x, pixel_y));
//zorgt voor flikkern knop
if (knop1_btn.justReleased())
knop1_btn.drawButton();
if (knop2_btn.justReleased())
knop2_btn.drawButton();
if (knop3_btn.justReleased())
knop3_btn.drawButton();
if (knop4_btn.justReleased())
knop4_btn.drawButton();
if (knop5_btn.justReleased())
knop5_btn.drawButton();
if (knop6_btn.justReleased())
knop6_btn.drawButton();
// zorgt voor actie zelf
if (knop1_btn.justPressed()) {
knop1_btn.drawButton(true);
drank = 10;
Serial.println(drank);
}
if (knop2_btn.justPressed()) {
knop2_btn.drawButton(true);
drank = 120;
Serial.println(drank);
}
if (knop3_btn.justPressed()) {
knop3_btn.drawButton(true);
drank = 30;
Serial.println(drank);
}
if (knop4_btn.justPressed()) {
knop4_btn.drawButton(true);
Serial.println("min");
straf--;
delay(50);
}
if (knop5_btn.justPressed()) {
knop5_btn.drawButton(true);
Serial.println("plus");
straf++;
delay(50);
}
if (knop6_btn.justPressed()) {
knop6_btn.drawButton(true);
Serial.println("maak");
drank = drank + straf;
delay(50);
tft.setTextColor(RED, BLACK);
tft.setTextSize(2);
tft.setCursor(5, 300);
tft.print(drank);
Wire.beginTransmission(64); // transmit to device #8
Wire.write(drank); // sends one byte
Wire.endTransmission(64); // stop transmitting
delay(3000);
drank = 0;
straf = 5;
}
tft.setTextColor(RED, BLACK);
tft.setTextSize(5);
tft.setCursor(75, 185);
tft.print(straf);
tft.setCursor(115, 185);
tft.print("cl");
}
slave
#include <Wire.h>
int LED = 13;
int x = 0;
void setup() {
Serial.begin(9600);
// Define the LED pin as Output
pinMode (LED, OUTPUT);
// Start the I2C Bus as Slave on address 9
Wire.begin(64);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}
void loop() {
Serial.println(x);
}