#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Arduino.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
#include <DHT.h>
#include "image.h"
#define DHTPIN 5
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;
void setup(void) {
//while (!Serial); // used for leonardo debugging
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
Wire.setPins(10, 8); // redefine first I2C port to be on pins 10/8
tft.begin();
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
Serial.println("Capacitive touchscreen started");
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(30, 15);
tft.setTextColor(0XFFE0);
tft.setTextSize(3);
tft.print("A120E101");
tft.setCursor(20, 40);
tft.setTextColor(0XFFFF);
tft.setTextSize(3);
tft.print("temp:");
tft.setCursor(20, 80);
tft.setTextColor(0XFFFF);
tft.setTextSize(3);
tft.print("humi:");
}
void loop() {
delay(10);
float t = dht.readTemperature();
float h = dht.readHumidity();
// Wait for a touch
// Retrieve a point
TS_Point p = ctp.getPoint();
// flip it around to match the screen.
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
// Print out the remapped (rotated) coordinates
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
if (t>50){
tft.drawRGBBitmap(60,150,(uint16_t *)image_data_60x60x16,image_w, image_h);
}
else{
tft.drawRGBBitmap(60,150,(uint16_t *)image1_data_60x60x16,image_w, image_h);
}
tft.fillRect(120,40,240,100,ILI9341_BLACK);
tft.setCursor(120, 40);
tft.setTextColor(0XFFE0);
tft.setTextSize(3);
tft.print(t);
tft.setCursor(120, 80);
tft.setTextColor(0XFFE0);
tft.setTextSize(3);
tft.print(h);
if (! ctp.touched()) {
return;
}
}