Sorry i thought posting to much would be a "no no" so here it is:
I will have a look at x. Thats a good one.
Such a dumb mistake.. Thanks very much it now works when i set x to zero at if x == 4
// All the mcufriend.com UNO shields have the same pinout.
// i.e. control pins A0-A4. Data D2-D9. microSD D10-D13.
// Touchscreens are normally A1, A2, D7, D6 but the order varies
//
// This demo should work with most Adafruit TFT libraries
// If you are not using a shield, use a full Adafruit constructor()
// e.g. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#include <SPI.h> // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
//#include <Adafruit_TFTLCD.h>
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#include <Wire.h>
int data [4];
int x = 0;
int number = 0;
int number2 = 0;
int set = 0;
String strZero = "0";
String strOne = "0";
String strTwo = "0";
String strThree = "0";
bool HDMIherkening = false;
bool verkadeNL = false;
bool googleNL = false;
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
void setup(void);
void loop(void);
bool executed = false;
void runtests(void);
//const char IpAdd;
void setup(void) {
Serial.begin(9600);
Wire.begin(0x04);
Wire.onReceive(receiveData); //callback for i2c. Jump to void recieveData() function when pi sends data
uint32_t when = millis();
// while (!Serial) ; //hangs a Leonardo until you connect a Serial
if (!Serial) delay(5000); //allow some time for Leonardo
Serial.println("Serial took " + String((millis() - when)) + "ms to start");
// tft.reset(); //hardware reset
uint16_t ID = tft.readID(); //
Serial.print("ID = 0x");
Serial.println(ID, HEX);
if (ID == 0xD3D3) ID = 0x9481; // write-only shield
// ID = 0x9329; // force ID
tft.begin(ID);
tft.fillScreen(BLACK);
tft.setRotation(45);
int row = 99;
tft.setTextColor(YELLOW, BLACK);
tft.setCursor(33, row);
tft.setTextSize(3);
tft.println("System booting");
tft.println(" ...");
}
#if defined(MCUFRIEND_KBV_H_)
uint16_t scrollbuf[320]; // my biggest screen is 320x480
#define READGRAM(x, y, buf, w, h) tft.readGRAM(x, y, buf, w, h)
#else
uint16_t scrollbuf[320]; // Adafruit only does 240x320
// Adafruit can read a block by one pixel at a time
int16_t READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
{
uint16_t *p;
for (int row = 0; row < h; row++) {
p = block + row * w;
for (int col = 0; col < w; col++) {
*p++ = tft.readPixel(x + col, y + row);
}
}
}
#endif
void printstring(int collum, int row, String message)
{
if (executed == false){
tft.fillScreen(GREEN);
executed = true;
}
tft.setTextColor(BLACK, GREEN);
tft.setCursor(collum, row);
tft.println(message);
}
void printmsg(int collum, int row, const char *msg)
{
if (executed == false){
tft.fillScreen(GREEN);
executed = true;
}
tft.setTextColor(BLACK, GREEN);
tft.setCursor(4, row);
tft.println(msg);
}
void loop(void) {
// uint8_t aspect;
// uint16_t pixel;
// const char *aspectname[] = {
// "PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"
// };
// const char *colorname[] = { "BLUE", "GREEN", "RED", "GRAY" };
// uint16_t colormask[] = { 0x001F, 0x07E0, 0xF800, 0xFFFF };
// uint16_t dx, rgb, n, wid, ht, msglin;
tft.setRotation(45);
delay(1111);
printmsg(4, 4, "IP: ");
printstring(66, 4, strZero);
printmsg(4, 33, "# Muziek speelt ");
if (HDMIherkening == true){
printmsg(4, 99, "HDMI: Herkend ");
}
if (HDMIherkening == false){
printmsg(4, 99, "HDMI: > Geen <");
}
if (googleNL == true){
printmsg(4, 165, "google.nl >Ja< ");
}
if (googleNL == false){
printmsg(4, 165, "google.nl >Nee<");
}
if (verkadeNL == true){
printmsg(4, 198, "verkade.nl >Ja< ");
}
if (verkadeNL == false){
printmsg(4, 198, "verkade.nl >Nee<");
}
}
void receiveData(int byteCount) {
while(Wire.available() && set == 0) { //Wire.available() returns the number of bytes available for retrieval with Wire.read(). Or it returns TRUE for values >0.
if (set == 0){
number=Wire.read();
}
}
Serial.println(number);
if (number == 1){
HDMIherkening = true;
}
if (number == 2){
HDMIherkening = false;
}
if (number == 4){
verkadeNL = true;
}
if (number == 5){
verkadeNL = false;
}
if (number == 6){
googleNL = true;
}
if (number == 7){
googleNL = false;
}
if (number == 8 && set == 0){
set = 1;
Serial.println("number 8 recieved");
clearLCD(4);
}
while(Wire.available() && set == 1) { //Wire.available() returns the number of bytes available for retrieval with Wire.read(). Or it returns TRUE for values >0.
data[x]=Wire.read();
strZero = String(data[0]);
strOne = String(data[1]);
strTwo = String(data[2]);
strThree = String(data[3]);
Serial.print("IPbegin: ");
Serial.println(strZero);
strZero.concat(".");
strZero.concat(strOne);
strZero.concat(".");
strZero.concat(strTwo);
strZero.concat(".");
strZero.concat(strThree);
/*
strIP.concat(".");
strIP.concat(strOne);
strIP.concat(".");
strIP.concat(strTwo);
strIP.concat(".");
strIP.concat(strThree);
*/
x++;
if (x == 4){
set = 0;
Serial.println("ja set = 0");
}
}
}
void clearLCD(int row){
tft.setTextColor(BLACK, GREEN);
tft.setCursor(4, row);
tft.println(" ");
}
Some words are dutch. So you know.