You are on page 1of 1

String inputString = "";

// a string to hold incoming data


boolean stringComplete = false; // whether the string is complete
#include <SoftwareSerial.h>
#include <Adafruit_ILI9341.h>
#include "TouchScreen.h"
#include <Adafruit_GFX.h>
// Core graphics library
#include <SPI.h>
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setRotation(1);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.setCursor(0,0);
tft.print(inputString);
delay (500);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.setCursor(0,0);
tft.print( inputString);
inputString = "";
stringComplete = false;
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}

You might also like