Created
October 2, 2017 08:18
-
-
Save dackdel/1c809cf6a42875ee10ae164108f9d3ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Adafruit_GFX.h> | |
#include <TFT_ILI9163C.h> | |
#include <dht.h> | |
//#include <DS1302.h> | |
//DS1302 rtc(1, 6, 7); | |
//#include <Fonts/FreeSerifItalic12pt7b.h> | |
dht DHT; | |
#define DHT11_PIN 5 | |
// Color definitions | |
#define BLACK 0x0000 | |
#define BLUE 0x001F | |
#define RED 0xF800 | |
#define GREEN 0x07E0 | |
#define CYAN 0x07FF | |
#define MAGENTA 0xF81F | |
#define YELLOW 0xFFE0 | |
#define WHITE 0xFFFF | |
#define CUSTOM1 0x01AD | |
#define CUSTOM2 0x0064 | |
#define CUSTOM3 0x10A2 | |
/* | |
tft.fillRect(X,Y,width,height,color) kvadrat. | |
tft.drawLine(x0, yy0, x1, yy1, BLUE); | |
tft.fillCircle | |
*/ | |
/* | |
TFT_drawPixel Draw pixel at given x,y coordinates | |
TFT_drawLine Draw line between two points | |
TFT_drawFastVLine, TFT_drawFastHLine Draw vertical or horizontal line of given lenght | |
TFT_drawLineByAngle Draw line on screen from (x,y) point at given angle | |
TFT_drawRect, TFT_fillRect Draw rectangle on screen or fill given rectangular screen region with color | |
TFT_drawRoundRect, TFT_fillRoundRect Draw rectangle with rounded corners or fill given rectangular screen region with rounded corners | |
TFT_drawCircle, TFT_fillCircle Draw or fill circle on screen | |
TFT_drawEllipse, TFT_fillEllipse Draw or fill ellipse on screen | |
TFT_drawTriangel, TFT_fillTriangle Draw or fill triangle on screen | |
TFT_drawArc Draw circle arc on screen, from start angle to end angle, with given thickness. Can be outlined with different color | |
TFT_drawPolygon Draw poligon on screen with given number of sides (3~60). Can be outlined with different color and rotated by given angle. | |
*/ | |
#define __CS 10 | |
#define __DC 9 | |
float menu=1; | |
int buttonState1 =0; | |
int buttonState2 =0; | |
int laser = 0; | |
const int buttonPin1 = 2; | |
const int buttonPin2 = 3; | |
const int laserState = 4; | |
TFT_ILI9163C tft = TFT_ILI9163C(__CS,8, __DC); | |
int x=0; | |
int menus=-1; | |
int menuss=0; | |
int menusss=0; | |
int laserdurum=0; | |
int Temhum=0; | |
int Cloc = 0; | |
float secs = 0; | |
float mins = 0; | |
float hous = 0; | |
int rnd = 0; | |
int rnd1 = 0; | |
int rnd2 = 0; | |
int rnd3 = 0; | |
int rnd4 = 0; | |
void setup() { | |
tft.begin(); | |
tft.setFont(); | |
pinMode(buttonPin1, INPUT); | |
pinMode(buttonPin2, INPUT); | |
pinMode(laserState, OUTPUT); | |
//rtc.halt(false); | |
// rtc.writeProtect(false); | |
//rtc.setDOW(MONDAY); // Set Day-of-Week to FRIDAY | |
//rtc.setTime(23, 0, 0); // Set the time to 12:00:00 (24hr format) | |
//rtc.setDate(25, 9, 2017); // | |
tft.setTextColor(WHITE, BLACK); | |
delay(1000); | |
} | |
void loop() { | |
unsigned long cmillis = millis(); | |
buttonState1 = digitalRead(buttonPin1); | |
buttonState2 = digitalRead(buttonPin2); | |
//delay(100); | |
//xli(); | |
if (menuss>4) { | |
tft.clearScreen(); | |
menuss=0; | |
delay(100); | |
} | |
//-----------------------------SOLDAKI BUTON | |
if (buttonState1 == HIGH) { | |
// menusss = 0 olduğunda button1 işleyir. | |
if (menusss==0) { | |
menuss=menuss+1; | |
menus=menuss; | |
} else if (menusss==1) { | |
if (menuss==4) { | |
tft.setCursor(20, 64); | |
// tft.setTextSize(2); | |
if (laserdurum==0) { | |
tft.clearScreen(); | |
tft.setTextColor(RED); | |
tft.println("Laser ACTIVE"); | |
digitalWrite(laserState, HIGH); | |
laserdurum=1; | |
delay(100); | |
} else { | |
tft.clearScreen(); | |
tft.setTextColor(WHITE); | |
tft.println("Laser DEACTIVE"); | |
digitalWrite(laserState, LOW); | |
laserdurum=0; | |
delay(100); | |
} | |
} else if (menuss==3) { | |
} else if (menuss==2) { | |
} else if (menuss==1) { | |
} | |
} | |
delay(100); | |
//------------------------SOLDAKI BUTONUN BİTİŞİ | |
//----------------------------------SAĞDAKI BUTON | |
} else if (buttonState2 == HIGH) { | |
if (menus ==-1) { | |
menusss=0; | |
menuss=1; | |
menus=1; | |
delay(100); | |
} | |
tft.clearScreen(); | |
if (menusss==0) { | |
// bu kod bu cür işleyir her bir buton basışında: | |
// menusss = 0 ise menusss = 1 olsun | |
// menusss = 1 ise menusss = 0 olsun | |
if (menuss==4) { | |
tft.setCursor(20, 64); | |
tft.setTextColor(WHITE); | |
tft.println("Laser DEACTIVE"); | |
laserdurum=0; | |
digitalWrite(laserState, LOW); | |
} else if (menuss==3) { | |
tft.setCursor(0, 0); | |
tft.setTextColor(WHITE); | |
Temhum=Temhum+1; | |
} else if (menuss==2) { | |
tft.setCursor(0, 0); | |
tft.setTextColor(WHITE); | |
Cloc = Cloc + 1; | |
} else if (menuss==1) { // menuss=1 AÇILIŞ TEKRAR(Bayraq+ad) | |
// tft.setCursor(0, 0); | |
//tft.setTextColor(WHITE); | |
// tft.println("Submenu1 selected"); | |
menus=-1; | |
} | |
menusss=1; | |
} else if (menusss==1) { | |
menuss=1; | |
menus=1; | |
Temhum=0; | |
Cloc=0; | |
menusss=0; | |
} | |
delay(100); | |
} | |
//-----------------------SAĞDAKI BUTONUN BİTİŞİ | |
if (menus ==-1) { | |
rnd = int(random(27)); | |
rnd1 = int(random(25)); | |
rnd2 = int(random(29)); | |
rnd3 = int(random(28)); | |
rnd4 = int(random(31)); | |
//tft.fillScreen(BLUE); | |
/* | |
//tft.fillRect(0,30, 30, 100, BLACK); | |
tft.drawFastHLine(13, 20, 16, CYAN); | |
tft.drawFastVLine(29, 20, 110, CYAN); | |
tft.drawFastVLine(13, 20, 110, CYAN); | |
tft.drawFastHLine(29, 50, 16, CYAN); | |
tft.drawFastVLine(45, 50, 80, CYAN); | |
*/ | |
//----------------------- ARXAPLAN BİNALARI | |
tft.drawFastVLine(30, 20, 35, CUSTOM1); | |
tft.drawFastHLine(30, 20, 30, CUSTOM1); | |
tft.drawFastVLine(60, 20, 110, CUSTOM1); | |
//--------------------------SOLDAKI BİNA | |
tft.drawFastVLine(40, 60, 70, CYAN); | |
tft.drawFastVLine(39, 60, 70, CYAN); | |
tft.drawRect(-2, 55, 45,5, CYAN); | |
tft.fillRect(15, 70, 10,10, YELLOW); | |
tft.drawRect(15, 90, 10,10, CYAN); | |
tft.drawRect(15, 110, 10,10, CYAN); | |
tft.fillRect(45, 101, 6,13, BLUE); | |
tft.drawFastHLine(39, 104, 5, CYAN); | |
tft.drawFastHLine(39, 111, 5, CYAN); | |
//--------------------------SOLDAKI TABELA | |
tft.drawRect(44, 100, 8,15, CYAN); | |
//-------------------SOLDAKI BİNANIN TEPESİ | |
tft.drawLine(0, 45, 16, 45, CYAN); | |
tft.drawFastVLine(16, 45, 10, CYAN); | |
//-----------------------------DİVAR HİSSE | |
tft.drawFastVLine(110, 10, 127, CYAN); | |
tft.drawRect(95, -2, 45, 12, CYAN); | |
for (int i=0; i<9; i++) { | |
tft.drawFastHLine(111, 25+i*15, 18, CYAN); | |
// tft.drawRect(110, 10+i*15, 20,15, CYAN); | |
//tft.fillRect(4*i, 100+j*3, 1,1, RED); | |
} | |
//-----------------------------REKLAM TABELASI | |
tft.drawRoundRect(85, 25, 20, 57,4, CYAN); | |
tft.fillRect(105, 32, 5, 10, CUSTOM3); | |
tft.fillRect(105, 60, 5, 10, CUSTOM3); | |
tft.fillRoundRect(86, 26, 18, 55,4, CUSTOM1); | |
tft.drawRoundRect(86, 26, 18, 55,3, MAGENTA); | |
tft.setCursor(92, 30); | |
tft.setTextSize(1.5); | |
tft.setTextColor(BLACK); | |
tft.println("R"); | |
tft.setCursor(92, 38); | |
tft.print("E"); | |
tft.setCursor(92, 46); | |
tft.print("D"); | |
tft.setCursor(92, 54); | |
tft.print("D"); | |
tft.setCursor(92, 62); | |
tft.print("I"); | |
tft.setCursor(92, 70); | |
tft.print("T"); | |
delay(500); | |
tft.setCursor(92, 30); | |
tft.setTextColor(RED); | |
tft.println("R"); | |
tft.setCursor(92, 38); | |
tft.print("E"); | |
tft.setCursor(92, 46); | |
tft.print("D"); | |
tft.setCursor(92, 54); | |
tft.print("D"); | |
tft.setCursor(92, 62); | |
tft.print("I"); | |
tft.setCursor(92, 70); | |
tft.print("T"); | |
delay(500); | |
//-----------------------SOLDAKI TABELA | |
tft.fillRect(45, 101, 6,13, WHITE); | |
//-------------ARXAPLAn BİNALARI | |
tft.drawFastVLine(30, 20, 35, BLUE); | |
tft.drawFastHLine(30, 20, 30, BLUE); | |
tft.drawFastVLine(60, 20, 110, BLUE); | |
//-------------- | |
tft.setTextColor(BLACK); | |
tft.setCursor(92, 30); | |
tft.println("R"); | |
tft.setCursor(92, 38); | |
tft.print("E"); | |
tft.setCursor(92, 46); | |
tft.print("D"); | |
tft.setCursor(92, 54); | |
tft.print("D"); | |
tft.setCursor(92, 62); | |
tft.print("I"); | |
tft.setCursor(92, 70); | |
tft.print("T"); | |
delay(500); | |
tft.setTextColor(RED); | |
tft.setCursor(92, 30); | |
tft.println("R"); | |
delay(500); | |
//-------------ARXAPLAn BİNALARI | |
tft.drawFastVLine(30, 20, 35, CYAN); | |
tft.drawFastHLine(30, 20, 30, CYAN); | |
tft.drawFastVLine(60, 20, 110, CYAN); | |
//-------------- | |
tft.setTextColor(BLACK); | |
tft.setCursor(92, 30); | |
tft.println("R"); | |
tft.setTextColor(RED); | |
tft.setCursor(92, 38); | |
tft.print("E"); | |
delay(500); | |
tft.setTextColor(BLACK); | |
tft.setCursor(92, 38); | |
tft.print("E"); | |
tft.setTextColor(RED); | |
tft.setCursor(92, 46); | |
tft.print("D"); | |
delay(500); | |
//-------------ARXAPLAn BİNALARI | |
tft.drawFastVLine(30, 20, 35, WHITE); | |
tft.drawFastHLine(30, 20, 30, WHITE); | |
tft.drawFastVLine(60, 20, 110, WHITE); | |
//-------------- | |
tft.setTextColor(BLACK); | |
tft.setCursor(92, 46); | |
tft.print("D"); | |
tft.setTextColor(RED); | |
tft.setCursor(92, 54); | |
tft.print("D"); | |
delay(500); | |
tft.setTextColor(BLACK); | |
tft.setCursor(92, 54); | |
tft.print("D"); | |
tft.setTextColor(RED); | |
tft.setCursor(92, 62); | |
tft.print("I"); | |
delay(500); | |
//-------------ARXAPLAn BİNALARI | |
tft.drawFastVLine(30, 20, 35, BLUE); | |
tft.drawFastHLine(30, 20, 30, BLUE); | |
tft.drawFastVLine(60, 20, 110, BLUE); | |
//-------------- | |
tft.setTextColor(BLACK); | |
tft.setCursor(92, 62); | |
tft.print("I"); | |
tft.setTextColor(RED); | |
tft.setCursor(92, 70); | |
tft.print("T"); | |
//--------------SOLDAKI BİNANIN TABELASI | |
tft.fillRect(45, 101, 6,13, MAGENTA); | |
delay(500); | |
tft.setCursor(92, 30); | |
tft.setTextColor(RED); | |
tft.println("R"); | |
tft.setCursor(92, 38); | |
tft.print("E"); | |
tft.setCursor(92, 46); | |
tft.print("D"); | |
tft.setCursor(92, 54); | |
tft.print("D"); | |
tft.setCursor(92, 62); | |
tft.print("I"); | |
tft.setCursor(92, 70); | |
tft.print("T"); | |
delay(500); | |
if (buttonState2 == HIGH) { | |
tft.clearScreen(); | |
menusss=0; | |
menuss=1; | |
menus=1; | |
delay(200); | |
} | |
/* | |
for (int i=0; i<33; i++) { | |
for (int j=1; j<3; j++) { | |
tft.fillRect(4*i, 90+j*3, 1,1, YELLOW); | |
tft.fillRect(4*i, 100+j*3, 1,1, RED); | |
} | |
} | |
*/ | |
// for (int i=50; i<80; i++) { | |
// tft.drawPixel(i,50, GREEN);; | |
// } | |
// tft.setCursor(30, 75); | |
//tft.setTextColor(WHITE); | |
// tft.println("Tural Alizade"); | |
// menuss=1; | |
//menus=1; | |
//menusss=0; | |
// ona göre menusss = 0 oldu ki | |
// button1 işlesin | |
// delay(10000); | |
} else if (menus==1) { | |
// tft.clearScreen(); | |
tft.drawRect(25,10, 80,20, RED); | |
tft.drawRect(25,40, 80,20, GREEN); | |
tft.drawRect(25,70, 80,20, GREEN); | |
tft.drawRect(25,100, 80,20, GREEN); | |
tft.setCursor(40, 15); | |
tft.setTextColor(RED); | |
tft.println("Generate F."); | |
tft.setCursor(40, 45); | |
tft.setTextColor(GREEN); | |
tft.println("Time"); | |
tft.setCursor(40, 75); | |
tft.setTextColor(GREEN); | |
tft.println("Temp/Hum"); | |
tft.setCursor(40, 105); | |
tft.setTextColor(GREEN); | |
tft.println("Laser"); | |
delay(100); | |
menus=0; | |
} else if (menus==2) { | |
tft.drawRect(25,10, 80,20, GREEN); | |
tft.drawRect(25,40, 80,20, RED); | |
tft.drawRect(25,70, 80,20, GREEN); | |
tft.drawRect(25,100, 80,20, GREEN); | |
tft.setCursor(40, 15); | |
tft.setTextColor(GREEN); | |
tft.println("Generate F."); | |
tft.setCursor(40, 45); | |
tft.setTextColor(RED); | |
tft.println("Time"); | |
tft.setCursor(40, 75); | |
tft.setTextColor(GREEN); | |
tft.println("Temp/Hum"); | |
tft.setCursor(40, 105); | |
tft.setTextColor(GREEN); | |
tft.println("Laser"); | |
delay(100); | |
menus=0; | |
} else if (menus==3) { | |
tft.drawRect(25,10, 80,20, GREEN); | |
tft.drawRect(25,40, 80,20, GREEN); | |
tft.drawRect(25,70, 80,20, RED); | |
tft.drawRect(25,100, 80,20, GREEN); | |
tft.setCursor(40, 15); | |
tft.setTextColor(GREEN); | |
tft.println("Generate F."); | |
tft.setCursor(40, 45); | |
tft.setTextColor(GREEN); | |
tft.println("Time"); | |
tft.setCursor(40, 75); | |
tft.setTextColor(RED); | |
tft.println("Temp/Hum"); | |
tft.setCursor(40, 105); | |
tft.setTextColor(GREEN); | |
tft.println("Laser"); | |
delay(100); | |
menus=0; | |
} else if (menus==4) { | |
tft.drawRect(25,10, 80,20, GREEN); | |
tft.drawRect(25,40, 80,20, GREEN); | |
tft.drawRect(25,70, 80,20, GREEN); | |
tft.drawRect(25,100, 80,20, RED); | |
tft.setCursor(40, 15); | |
tft.setTextColor(GREEN); | |
tft.println("Generate F."); | |
tft.setCursor(40, 45); | |
tft.setTextColor(GREEN); | |
tft.println("Time"); | |
tft.setCursor(40, 75); | |
tft.setTextColor(GREEN); | |
tft.println("Temp/Hum"); | |
tft.setCursor(40, 105); | |
tft.setTextColor(RED); | |
tft.println("Laser"); | |
delay(100); | |
menus=0; | |
// tft.noDisplay(); | |
} | |
if (Temhum>0) { | |
tft.clearScreen(); | |
tft.setCursor(0, 0); | |
int chk = DHT.read11(DHT11_PIN); | |
tft.setTextColor(WHITE); | |
tft.print("TEMPERATURE(C'): "); | |
tft.setCursor(40, 15); | |
tft.setTextColor(RED); | |
tft.setTextSize(2); | |
tft.println(DHT.temperature); | |
tft.setCursor(0, 45); | |
tft.setTextColor(WHITE); | |
tft.setTextSize(1); | |
tft.print("HUMIDITY(%): "); | |
tft.setCursor(40, 60); | |
tft.setTextColor(RED); | |
tft.setTextSize(2); | |
tft.println(DHT.humidity); | |
tft.setTextSize(1); | |
delay(3000); | |
} | |
if (Cloc>0) { | |
//tft.clearScreen(); | |
tft.setTextWrap(false); | |
tft.setTextSize(2); | |
tft.setCursor(10, 30); | |
// tft.print(int(secs)); | |
//tft.print(" : "); | |
tft.setTextColor(WHITE); | |
tft.print(int(mins)); | |
tft.print(":"); | |
tft.print(int(hous)); | |
tft.setCursor(10, 80); | |
tft.setTextSize(1); | |
tft.setTextColor(RED); | |
tft.setCursor(10,100); | |
tft.setTextSize(1); | |
// tft.print(int(secs)); | |
tft.setTextColor(WHITE); | |
delay(1000); | |
tft.fillRect(5, 30, 120, 30, BLACK); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment