// ILI9341 example with embedded color bitmaps in sketch.
// WILL NOT FIT ON ARDUINO UNO OR OTHER AVR BOARDS;
// uses large bitmap image stored in array!
// Options for converting images to the format used here include:
// http://www.rinkydinkelectronics.com/t_imageconverter565.php
// or
// GIMP (https://www.gimp.org/) as follows:
// 1. File -> Export As
// 2. In Export Image dialog, use 'C source code (*.c)' as filetype.
// 3. Press export to get the export options dialog.
// 4. Type the desired variable name into the 'prefixed name' box.
// 5. Uncheck 'GLIB types (guint8*)'
// 6. Check 'Save as RGB565 (16-bit)'
// 7. Press export to save your image.
// Assuming 'image_name' was typed in the 'prefixed name' box of step 4,
// you can have to include the c file, then using the image can be done with:
// tft.drawRGBBitmap(0, 0, image_name.pixel_data, image_name.width, image_name.height);
// See also https://forum.pjrc.com/threads/35575-Export-for-ILI9341_t3-with-GIMP
#include "SPI.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_GFX.h"
#include "NTC_Thermistor.h"
#include <Thermistor.h>
#include "dragon.h"
#include "quat.h"
// For the Adafruit shield, these are the default.
//#define TFT_DC 9
//#define TFT_CS 10
// Feather 32u4 or M0 with TFT FeatherWing:
#define TFT_DC 2
#define TFT_CS 15
// ESP8266:
//#define TFT_DC 15
//#define TFT_CS 0
// Other boards (including Feather boards) may have other pinouts;
// see learn.adafruit.com/adafruit-2-4-tft-touch-screen-featherwing/pinouts
// PUSH BUTTOM
#define BTN_UP 5 // PUSH UP
#define BTN_DOW 12 // PUSH DOW
#define BTN_ENTER 14 // PUSH CHOOS
float macdinh = 0.5;
float dem = 10;
int chonlist =0;
int chon;
float gtcong;
float gttru;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// NTC
#define SENSOR_PIN 25
#define REFERENCE_RESISTANCE 8000
#define NOMINAL_RESISTANCE 100000
#define NOMINAL_TEMPERATURE 25
#define B_VALUE 3950
Thermistor* thermistor;
void setup() {
tft.begin();
pinMode(BTN_UP, INPUT_PULLUP);
pinMode(BTN_DOW, INPUT_PULLUP);
pinMode(BTN_ENTER, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("ILI9341 Test!");
tft.setRotation(1);
tft.drawLine(80, 0, 80, 240, ILI9341_WHITE);
tft.drawRGBBitmap(0,0,dragonBitmap,50,50);
tft.drawRGBBitmap(0,80,quatBitmap,50,50);
//tft.fillRect(50, 0, 50, 50, ILI9341_RED);
tft.setCursor(200, 20);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
tft.println("MENU_1");
tft.setCursor(200, 50);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
tft.println("MENU_2");
tft.setCursor(200, 80);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
tft.println("MENU_3");
tft.setCursor(200, 110);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
tft.println("MENU_4");
// sensor NTC
thermistor = new NTC_Thermistor(
SENSOR_PIN,
REFERENCE_RESISTANCE,
NOMINAL_RESISTANCE,
NOMINAL_TEMPERATURE,
B_VALUE
);
}
//hàm chọn............
void fchonlist(){
if (chon != 1){
if (chon == 0) {
chonlist = chonlist + 1;
Serial.print("chon list:"); Serial.println(chonlist);
delay(100);
}
}
}
//hàm cộng tăng............
void fcong(){
if (gtcong != 1){
if (gtcong == 0) {
dem = dem + macdinh;
Serial.print("Dem tang:"); Serial.println(dem);
delay(100);
}
}
}
// Hàm Trừ........................
void ftru(){
if (gttru != 1){
if (gttru == 0) {
dem = dem - macdinh;
Serial.print("Dem giam:"); Serial.println(dem);
delay(100);
}
}
}
///
void loop(void) {
// tăng - Giảm
gtcong = digitalRead(BTN_UP);
// Serial.print("Cộng: "); Serial.print(gtcong); Serial.print(" ");
gttru = digitalRead(BTN_DOW);
// Serial.print("Trừ: "); Serial.print(gttru); Serial.print(" ");
chon = digitalRead(BTN_ENTER);
// NTC reading
const double celsius = thermistor->readCelsius();
//Serial.println(celsius);
delay(50);
//
//
if (chon != 1){
if (chon == 0)
{
chonlist ++;
if (chonlist > 3)
{
chonlist = 0;
}
}
//chon = 0;
Serial.print("chonlist : "); Serial.println(chonlist);
delay(100);
}
//
switch (chonlist)
{ case 0: Serial.println("Giặt thông thường");
fcong();
ftru();
delay(100);
break;
case 1: Serial.println("Giặt nhẹ");
fcong();
ftru();
delay(100);
break;
case 2: Serial.println("Giặt mạnh");
fcong();
ftru();
delay(100);
break;
case 3: Serial.println("Vắt");
fcong();
ftru();
delay(100);
break;
}
tft.setCursor(150, 100);
tft.setTextColor(ILI9341_BLACK); tft.setTextSize(4);
tft.setTextColor(ILI9341_RED); tft.setTextSize(4);
tft.println(dem);
tft.setCursor(150,0);
tft.setTextSize(2);tft.print("Temp:");tft.print(" "); tft.print(celsius);
delay(50);
// kết thúc tăng - giảm
/*
//read the pushbutton value into a variable
if (digitalRead(BTN_UP) == LOW) {
giam();
};
delay(100);
//print out the value of the pushbutton
if (digitalRead(BTN_UP) == LOW) {
tft.fillRect(50, 0, 50, 50, ILI9341_RED);
tft.drawRect(190, 15, 90, 25, ILI9341_RED);
Serial.println("1");
};
delay(100);
if (digitalRead(BTN_DOW) == LOW) {
tft.fillRect(50, 80, 50, 50, ILI9341_RED);
Serial.println("2");
};
delay(100);
*/
}