#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_FT6206.h> // Hardware-specific library
#include <TouchScreen.h>
//----------------------------------------
//----------------------------------------
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
//----------------------------------------
Adafruit_FT6206 ctp = Adafruit_FT6206();
//----------------------------------------Pin configuration and initialization for LCD TFT
#define LCD_CS 10
#define LCD_CD 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(LCD_CS, LCD_CD);
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
float temp =0;
float pretemp =0;
float currtemp =50;
float i=0;
float j=0;
int Noise;
float dB;
unsigned long previousMillis = 0; //--> will store last time updated
// constants won't change:
const long interval = 2000; //--> interval
float peakToPeak; // peak-to-peak level
void setup(void)
{
Serial.begin(119600);
tft.begin();
tft.setRotation(1); //PORTRAIT
tft.fillScreen(BLACK);
tft.setTextColor(YELLOW, BLACK);
tft.setTextSize(2);
// testing();
tft.setTextSize(2);
tft.setCursor(15, 240);
tft.setTextColor(GREEN,BLACK);
tft.print("Teach Me Something");
// delay(1000);
tft.fillScreen(BLACK);
tft.setTextColor(GREEN,BLACK);
tft.setCursor(55, 180);
tft.print("20");
tft.setCursor(85, 180);
tft.print("900");
tft.setCursor(55, 120);
tft.print("NOISE");
tft.setCursor(30, 5);
tft.fillRect(0,0,320,45,BLACK);
tft.setTextColor(YELLOW,BLACK);
tft.print("Temperature & Humidity");
tft.setCursor(120, 25);
tft.print("Monitor");
tft.setTextColor(WHITE,BLACK);
}
//========================================================================
//========================================================================GetNoiseData()
void GetNoiseData() {
Noise = analogRead(A0); // Read the analog value of the Microphone
float peakToPeak = 0; // peak-to-peak level
int signalMax = 0; //minimum value
int signalMin = 1024; //maximum value
if (Noise < 1024) // toss out spurious readings
{
if (Noise > signalMax)
{
signalMax = Noise; // save just the max levels
}
else if (Noise < signalMin)
{
signalMin = Noise; // save just the min levels
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
}
//========================================================================
//========================================================================
void loop(void)
{
Noise = analogRead(A0); // Read the analog value of the Microphone
tft.fillRect(55, 150,60,20,BLACK);
tft.setCursor(55, 150);
tft.print(temp);
i = map(pretemp,20,900,0,300);
j = map(Noise,20,900,0,300);
for (i; i<=j; i=i+0.1)
{
float j=i-150 ;
float angle = (j / 57.2958) - 1.57;
float x1= 80 + cos(angle) * 55;
float y1 = 130+sin(angle) * 55;
float x2= 80 + cos(angle) * 75;
float y2 = 130+sin(angle) * 75;
tft.drawLine(x1 + 80, y1, x2, y2, GREEN);
}
i = map(pretemp,20,900,0,300);
j = map(Noise,20,900,0,300);
for (i-2; i>=j; i=i-0.05)
{
float j=i-150 ;
float angle = (j / 57.2958) - 1.57;
float x1= 80 + cos(angle) * 55;
float y1 = 130+sin(angle) * 55;
float x2= 80 + cos(angle) * 75;
float y2 = 130+sin(angle) * 75;
tft.drawLine(x1 + 80, y1,x2 + 80,y2, BLACK);
// tft.drawLine(x1+160, y1,x2+160,y2, MAGENTA);
}
pretemp=Noise;
temp = j;
Serial.println("TEMP:"+String(temp));
currtemp=temp;
delay(1000);
}Loading
ili9341-cap-touch
ili9341-cap-touch