////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Wire.h>
#include <EEPROM.h>
#include <TimerOne.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET A7 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int interrupt0 = 0;
#define Enter 2
#define up 3
#define down 4
#define back 5
#define choncambien A2
int Relay = 12;
int loa = 10;
int BC1 = A6;
int giatriBC1;
const int trig = 7; // chân trig của HC-SR04
const int echo = 8; // chân echo của HC-SR04
int timer_us = 300;
int menu = 3;
int menu1 = 1, temp = LOW;
int menu4 = 0;
int dis, x = 0, z, ttcb;
long dem = 0;
int t = 0;
float PIN;
int quydoipin = 0;
int vachpin = 0;
float vin;
float vout;
unsigned int giatriadc;
unsigned int e, a = 0, i = 0, n = 0, m = 0;
int j = 0, k = 0;
unsigned int save = 0;
int b = 1, gtpin;
int demkl, demkl1, f = 0, w = 0, g = 0, u = 0;
int demtt, demtt1, luu, tocdo;
int khoidong = 0, muctc = 1000, ttloa = 1;
byte check = 0;
unsigned long bandau = 0;
static const unsigned char PROGMEM image_ButtonRight_bits[] = { 0x80, 0xc0, 0xe0, 0xf0, 0xe0, 0xc0, 0x80 };
static const unsigned char PROGMEM image_menu_settings_gear_bits[] = { 0x03, 0xc0, 0x12, 0x48, 0x2c, 0x34, 0x40, 0x02, 0x23, 0xc4, 0x24, 0x24, 0xc8, 0x13, 0x88, 0x11, 0x88, 0x11, 0xc8, 0x13, 0x24, 0x24, 0x23, 0xc4, 0x40, 0x02, 0x2c, 0x34, 0x12, 0x48, 0x03, 0xc0 };
static const unsigned char PROGMEM image_cards_clubs_bits[] = { 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x07, 0xc0, 0x3b, 0xb8, 0x7f, 0xfc, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xfe, 0xfe, 0x7d, 0x7c, 0x39, 0x38, 0x03, 0x80, 0x07, 0xc0 };
static const unsigned char PROGMEM image_arrow_right_bits[] = { 0x08, 0x04, 0xfe, 0x04, 0x08 };
static const unsigned char PROGMEM image_Layer_7_bits[] = { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x07, 0xc0, 0x3c, 0x78, 0xff, 0xfe };
static const unsigned char PROGMEM image_Layer_7_1_bits[] = { 0xff, 0xff, 0xf8, 0xc0, 0x00, 0x18, 0x60, 0x00, 0x30, 0x30, 0x00, 0x60, 0x18, 0x00, 0xc0, 0x0c, 0x01, 0x80, 0x06, 0x03, 0x00, 0x03, 0x06, 0x00, 0x01, 0xfc, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x70, 0x00 };
static const unsigned char PROGMEM image_music_stop_button_bits[] = { 0x07, 0xc0, 0x18, 0x30, 0x20, 0x08, 0x40, 0x04, 0x4f, 0xe4, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x4f, 0xe4, 0x40, 0x04, 0x20, 0x08, 0x18, 0x30, 0x07, 0xc0, 0x00, 0x00 };
static const unsigned char PROGMEM image_arrow_right_bits1[] = { 0x08, 0x04, 0xfe, 0x04, 0x08 };
static const unsigned char PROGMEM image_music_next_button_bits[] = { 0x07, 0xc0, 0x18, 0x30, 0x20, 0x08, 0x50, 0x04, 0x58, 0x74, 0x96, 0x52, 0x93, 0x52, 0x91, 0xd2, 0x93, 0x52, 0x96, 0x52, 0x58, 0x74, 0x50, 0x04, 0x20, 0x08, 0x18, 0x30, 0x07, 0xc0, 0x00, 0x00 };
static const unsigned char PROGMEM image_Layer_12_bits[] = { 0xc0, 0xc0 };
static const unsigned char PROGMEM image_weather_temperature_bits[] = { 0x1c, 0x00, 0x22, 0x02, 0x2b, 0x05, 0x2a, 0x02, 0x2b, 0x38, 0x2a, 0x60, 0x2b, 0x40, 0x2a, 0x40, 0x2a, 0x60, 0x49, 0x38, 0x9c, 0x80, 0xae, 0x80, 0xbe, 0x80, 0x9c, 0x80, 0x41, 0x00, 0x3e, 0x00 };
static const unsigned char PROGMEM image_Layer_13_bits[] = { 0x43, 0x80, 0xa4, 0x40, 0x44, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x40, 0x03, 0x80 };
static const unsigned char PROGMEM image_arrow_up_bits[] = { 0x20, 0x70, 0xa8, 0x20, 0x20, 0x20, 0x20 };
static const unsigned char PROGMEM image_arrow_down_bits[] = { 0x20, 0x20, 0x20, 0x20, 0xa8, 0x70, 0x20 };
static const unsigned char PROGMEM image_check_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x60, 0x80, 0xc0, 0xc1, 0x80, 0x63, 0x00, 0x36, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char PROGMEM image_png_clipart_hanoi_hotel_television_music_sport_hanoi_television_text_thumbnail_bits[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char PROGMEM image_Layer_1_bits[] = {0xae,0x3b,0x3a,0x80,0xaa,0x22,0xaa,0x80,0xe8,0xbb,0x2b,0x80,0xaa,0x0a,0xa8,0x80,0xae,0x3a,0xb8,0x80};
static const unsigned char PROGMEM image_Layer_2_bits[] = {0xa8,0x8e,0xe4,0xaa,0x82,0xac,0xea,0xae,0xa4,0xaa,0x88,0xa4,0xa5,0x0e,0xee};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//KHAI BÁO CHƯƠNG TRÌNH
void setup() {
Serial.begin(9600);
//attachInterrupt (interrupt0, int_, FALLING);
pinMode(choncambien, INPUT_PULLUP);
pinMode(up, INPUT_PULLUP);
pinMode(down, INPUT_PULLUP);
pinMode(Enter, INPUT_PULLUP);
pinMode(back, INPUT_PULLUP);
pinMode(giatriadc, INPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(Relay, OUTPUT);
pinMode(loa, OUTPUT);
pinMode(A1, OUTPUT);
int demkl = 0;
float demtt = 0;
Timer1.initialize(timer_us);
Timer1.attachInterrupt(timer_isr);
Timer1.stop();
timer2();
//clk_old = digitalRead(CLK);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
analogWrite(11, LOW);
digitalWrite(Relay, LOW);
digitalWrite(A1, LOW);
for (int o = 0; o < 5; o++) {
digitalWrite(loa, HIGH);
delay(100);
digitalWrite(loa, LOW);
delay(100);
}
if(digitalRead(choncambien) == LOW) {
EEPROM.update(100, 0);
delay(200);
}
if(digitalRead(choncambien) == HIGH) {
EEPROM.update(100, 1);
delay(200);
}
//Serial.println(EEPROM.read(100));
sensors.begin();
VPIN();
chaomung2();
chaomung();
NTC();
tocdo = EEPROM.read(200);
b = EEPROM.read(300);
delay(50);
if (b > 5) {
EEPROM.update(300, 3);
delay(100);
}
menu = EEPROM.read(300);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH CHÍNH
void loop() {
VPIN();
if (vin < 726) {
ttloa = 0;
}
if (vin >= 726) {
ttloa = 1;
}
setting();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH ĐO ĐIỆN ÁP PIN
void VPIN() {
vin = analogRead(giatriadc);
if (vin > 760) {
vin = 760;
}
if (vin < 716) {
vin = 715;
}
quydoipin = map(vin, 715, 760, 1, 100); //Hiển thị % PIN
if(vin > 0 && vin <716 ) {
gtpin = 0;
}
if(vin >= 716 && vin < 720){
gtpin = 1;
}
if(vin >= 720 && vin < 725){
gtpin = 2;
}
if(vin >= 725 && vin < 730){
gtpin = 3;
}
if(vin >= 730 && vin < 735){
gtpin = 4;
}
if(vin >= 735 && vin < 740){
gtpin = 5;
}
if(vin >= 740 && vin < 745){
gtpin = 6;
}
if(vin >= 745 && vin < 750){
gtpin = 7;
}
if(vin >= 755 && vin < 760){
gtpin = 8;
}
if(vin >= 760){
gtpin = 9;
}
//vachpin = map(vin, 715, 760, 1, 9); //Hiển thị vạch PIN
if (millis() - bandau > 500 && menu1 == 0) {
bandau = millis();
if (vin < 726 && menu1 == 0 | dis >= 5 ) {
digitalWrite(loa, HIGH);
}
//Serial.print(bandau); Serial.print(" "); Serial.println(loa);
} else {
digitalWrite(loa, LOW);
}
// Serial.print("Pin :");
// Serial.print(vin);
// Serial.print ("/");
// Serial.print(quydoipin);
// Serial.print("%");
// Serial.println("");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ĐỌC NHIỆT ĐỘ NTC
void NTC() {
sensors.requestTemperatures();
if ((int)sensors.getTempCByIndex(0) > 8) {
digitalWrite(Relay, HIGH);
} else if ((int)sensors.getTempCByIndex(0) <= 5) {
digitalWrite(Relay, LOW);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void buzzer() {
digitalWrite(loa, ttloa);
delay(50);
digitalWrite(loa, LOW);
}
//CHƯƠNG TRÌNH KHỞI ĐỘNG
void chaomung() {
for (j = 0; j < 10; j++) {
delay(12);
display.clearDisplay();
display.setCursor(32, 10);
display.setTextSize(2);
display.setTextColor(WHITE);
display.println("HELLO!");
display.setCursor(4, 33);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println(" NGUYEN THANH TINH");
display.setTextColor(1);
display.setCursor(63, 47);
display.print(quydoipin);
display.print("%");
display.fillRect(45, 49, gtpin, 4, 1);
display.drawLine(56, 49, 56, 52, 1);
display.drawRect(43, 47, 13, 8, 1);
// khoidong = map(j, 0, 10, 27, 101);
// display.drawRect(25, 59, 76, 5, 1);
// display.drawLine(27, 61, khoidong, 61, 1);
// display.fillRect(110, 53, 48, 11, 0);
display.display();
delay(10);
}
}
void chaomung2() {
for (j = 0; j < 10; j++) {
delay(50);
display.clearDisplay();
display.drawBitmap(33, -4, image_png_clipart_hanoi_hotel_television_music_sport_hanoi_television_text_thumbnail_bits, 60, 60, 1);
khoidong = map(j, 0, 10, 32, 96);
//display.drawRect(29, 55, 70, 5, 1);
display.drawLine(32, 57, khoidong, 57, 1);
display.display();
delay(10);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH ENCODER EC11 VÀ NÚT NHẤN
void nutnhan() {
if (digitalRead(up) == 0) {
delay(5);
buzzer();
menu++;
if (menu > 3) {
menu = 1;
}
while (digitalRead(up) == 0)
;
}
if (digitalRead(down) == 0) {
delay(5);
buzzer();
menu--;
if (menu < 1) {
menu = 3;
}
while (digitalRead(down) == 0)
;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH NGẮT TIMER2
void timer2() {
TCCR2A = 0;
TCCR2B = 0;
// reset lại thanh ghi
TCCR2B |= (1 << CS21) | (1 << CS20);
TCCR2A |= (1 << COM2A1);
// so sánh thường ( none-inverting)
TCCR2A |= (1 << WGM21) | (1 << WGM20);
// PWM Mode (răng cưa)
analogWrite(11, 0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH CHÍNH HIỂN THỊ
void home() {
display.clearDisplay();
display.drawLine(41, 18, 86, 18, 1);
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(41, 1);
display.print("MENU");
display.setTextSize(1);
display.setCursor(13, 30);
display.print("1. ROT TU DONG");
display.setCursor(13, 42);
display.print("2. ROT THU CONG");
display.setCursor(13, 54);
display.print("3. CAI DAT");
//display.setCursor(13, 54);
//display.print("4. CHON CAM BIEN");
display.drawLine(41, 17, 86, 17, 1);
display.drawBitmap(9, 3, image_cards_clubs_bits, 15, 16, 1);
display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
display.drawRect(112, 2, 13, 8, 1); // Line pin
display.drawLine(125, 4, 125, 7, 1); // Line pin
if (menu == 1) {
display.drawBitmap(3, 31, image_arrow_right_bits, 7, 5, 1);
display.display();
delay(5);
} else if (menu == 2) {
display.drawBitmap(3, 43, image_arrow_right_bits, 7, 5, 1);
display.display();
delay(5);
} else if (menu == 3) {
display.drawBitmap(3, 55, image_arrow_right_bits, 7, 5, 1);
display.display();
delay(5);
}
//else if (menu == 4) {
// display.drawBitmap(3, 55, image_arrow_right_bits, 7, 5, 1);
// display.display();
// delay(5);
//}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH CẢM BIẾN SIÊU ÂM HC02 (Nếu chân A2 bỏ trống thì sử dụng cảm biến HC-SR04, nếu chân A2 được nối xuống GND thì sử dụng cảm biến HW-201)
void cambien() {
switch (EEPROM.read(100)) {
case 0:
unsigned long dur; // biến đo thời gian
digitalWrite(trig, 0); // tắt chân tri
delayMicroseconds(2);
digitalWrite(trig, 1); // phát xung từ chân tri
delayMicroseconds(5); // xung có độ dài 5 microSecond
digitalWrite(trig, 0); // tắt chân tri
dur = pulseIn(echo, HIGH);
dis = int(dur / 2 / 29.412);
delay(10);
// Serial.print(dis);
// Serial.println("cm");
break;
case 1:
giatriBC1 = analogRead(BC1);
dis = map(giatriBC1, 0, 1023, 0, 10);
delay(10);
break;
}
//Serial.print("Cam bien da luu gia tri x = ");
//Serial.print(EEPROM.read(100));
//Serial.println();
}
////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH ĐIỀU KHIỂN BẬT MÔ TƠ BƠM
void moto_on() {
analogWrite(11, tocdo);
delay(20);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH ĐIỀU KHIỂN TẮT MÔ TƠ BƠM
void moto_off() {
analogWrite(11, 0);
delay(20);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH CÀI ĐẶT CHÍNH
void setting() {
if (menu1 == 0) {
if (digitalRead(Enter) == LOW) {
delay(5);
buzzer();
menu1++;
if (menu1 == 3) {
menu1 = 0;
}
while (digitalRead(Enter) == LOW)
;
}
if(digitalRead(back) == 0){
delay(5);
buzzer();
menu = 1;
menu1 = 1;
while(digitalRead(back) == 0);
}
nutnhan();
home();
}
//CHƯƠNG TRÌNH RÓT TỰ ĐỘNG
else if ((menu1 == 1) && (menu == 1)) {
if (digitalRead(back) == LOW) {
delay(5);
buzzer();
menu1 = 0;
}
save = EEPROM.read(0x01);
tocdo = EEPROM.read(200);
display.clearDisplay();
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(36, 1);
display.print("REALY");
display.setTextSize(1);
if (save < 10) {
display.setCursor(44, 25);
display.print("LEVEL:");
display.print(save);
}
if (save >= 10 && save <= 99) {
display.setCursor(42, 25);
display.print("LEVEL:");
display.print(save);
} else if (save > 100) {
display.setCursor(38, 25);
display.print("LEVEL:");
display.print(save);
}
display.drawLine(36, 17, 93, 17, 1);
display.drawLine(36, 18, 93, 18, 1);
display.drawBitmap(57, 49, image_Layer_7_bits, 15, 11, 1);
display.drawBitmap(54, 38, image_Layer_7_1_bits, 21, 11, 1);
display.drawBitmap(12, 4, image_music_stop_button_bits, 15, 16, 1);
display.drawBitmap(49, 49, image_arrow_right_bits1, 7, 5, 1);
display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
display.drawRect(112, 2, 13, 8, 1); // Line pin
display.drawLine(125, 4, 125, 7, 1); // Line pin
display.drawBitmap(4, 44, image_weather_temperature_bits, 16, 16, 1);
display.drawBitmap(35, 53, image_Layer_13_bits, 10, 7, 1);
display.setCursor(21, 53);
display.setTextSize(1);
display.setTextColor(WHITE);
display.print((int)sensors.getTempCByIndex(0));
display.setTextSize(1);
display.setCursor(80, 38);
display.print("KL:");
display.print(demkl);
display.setCursor(80, 53);
display.print("V:");
display.print(demtt);
display.print("ml");
display.setCursor(22, 40);
display.print("S:");
display.setCursor(34, 40);
display.print(tocdo);
display.display();
delay(10);
NTC();
cambien();
if (dis < 5) {
while (a < 1) {
buzzer();
delay(200);
while (a < save) {
if (digitalRead(Enter) == LOW) {
delay(5);
buzzer();
k = !k;
while (digitalRead(Enter) == LOW)
;
}
if (k == 0) {
Timer1.start();
moto_on();
} else if (k == 1) {
Timer1.stop();
moto_off();
}
if (a == (save - 1)) {
demkl++;
demtt = demtt + save;
}
if (digitalRead(back) == 0) {
delay(5);
buzzer();
if (a > 1) {
demkl++;
demtt = demtt + a;
}
save = 0;
k = 0;
while (digitalRead(back) == 0)
;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(40, 3);
display.print("AUTO");
display.setTextSize(1);
if (save <= 9) {
display.setCursor(42, 25);
display.print("LEVEL:");
display.print(save);
}
if (save >= 10 && save <= 99) {
display.setCursor(40, 25);
display.print("LEVEL:");
display.print(save);
} else if (save >= 100) {
display.setCursor(37, 25);
display.print("LEVEL:");
display.print(save);
}
display.drawLine(39, 19, 86, 19, 1);
display.drawLine(39, 20, 86, 20, 1);
display.drawBitmap(7, 4, image_music_next_button_bits, 15, 16, 1);
//display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
//display.drawRect(112, 2, 13, 8, 1); // Line pin
//display.drawLine(125, 4, 125, 7, 1); // Line pin
if (a >= 0 && a <= 9) {
display.setTextSize(2);
display.setCursor(59, 40);
display.print(a);
} else if (a >= 10 && a <= 99) {
display.setTextSize(2);
display.setCursor(53, 40);
display.print(a);
} else {
display.setTextSize(2);
display.setCursor(45, 40);
display.print(a);
}
display.fillRect(79, 52, 49, 12, 0);
unsigned int tientrinh = map(a, 0, save, 0, 128);
display.drawLine(1, 63, tientrinh, 63, 1); //Thanh tiến trình
unsigned int Tyle = map(a, 0, save, 0, 100);
display.setTextSize(1);
display.setCursor(1, 51); //Tỷ lệ chạy
display.print(Tyle); //Tỷ lệ chạy
display.print("%"); //Tỷ lệ chạy
display.setTextSize(1);
display.setCursor(82, 40);
display.print("(ml)");
display.display();
delay(10);
}
}
} else {
a = 0;
Timer1.stop();
moto_off();
}
Timer1.stop();
moto_off();
}
//PHẦN RÓT THỦ CÔNG
else if ((menu1 == 1) && (menu == 2)) {
if (digitalRead(back) == LOW) {
delay(5);
buzzer();
menu1 = 0;
}
save = EEPROM.read(0x01);
tocdo = EEPROM.read(200);
display.clearDisplay();
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(36, 1);
display.print("REALY");
display.setTextSize(1);
display.setCursor(33, 25);
display.print("LEVEL:");
display.setCursor(74, 25);
display.print(muctc);
display.drawLine(36, 18, 93, 18, 1);
display.drawLine(36, 17, 93, 17, 1);
display.drawBitmap(57, 49, image_Layer_7_bits, 15, 11, 1);
display.drawBitmap(54, 38, image_Layer_7_1_bits, 21, 11, 1);
display.drawBitmap(12, 4, image_music_stop_button_bits, 15, 16, 1);
display.drawBitmap(49, 49, image_arrow_right_bits1, 7, 5, 1);
display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
display.drawRect(112, 2, 13, 8, 1); // Line pin
display.drawLine(125, 4, 125, 7, 1); // Line pin
display.drawBitmap(4, 44, image_weather_temperature_bits, 16, 16, 1);
display.drawBitmap(35, 53, image_Layer_13_bits, 10, 7, 1);
display.setCursor(21, 53);
display.setTextSize(1);
display.setTextColor(WHITE);
display.print((int)sensors.getTempCByIndex(0));
display.setTextSize(1);
display.setCursor(80, 38);
display.print("KL:");
display.print(demkl1);
display.setCursor(80, 53);
display.print("V:");
display.print(demtt1);
display.print("ml");
display.setCursor(22, 40);
display.print("S:");
display.setCursor(34, 40);
display.print(tocdo);
display.display();
delay(10);
NTC();
if (digitalRead(Enter) == 0) {
delay(5);
buzzer();
k = !k;
while (digitalRead(Enter) == LOW)
;
}
if (k == 1) {
a = 0;
demkl1++;
while (a <= (muctc + 1)) {
if (digitalRead(Enter) == LOW) {
delay(5);
buzzer();
k = !k;
while (digitalRead(Enter) == LOW)
;
}
if (k == 1) {
Timer1.start();
moto_on();
if (a > 999) {
Timer1.stop();
moto_off();
k = 0;
demtt1 = demtt1 + a;
a = 0;
delay(300);
for (int y = 0; y < 3; y++) {
delay(100);
digitalWrite(loa, HIGH);
delay(100);
digitalWrite(loa, LOW);
}
break;
}
} else if (k == 0) {
Timer1.stop();
moto_off();
}
if (digitalRead(back) == 0) {
Timer1.stop();
moto_off();
k = 0;
demtt1 = demtt1 + a;
a = 0;
buzzer();
delay(300);
for (int y = 0; y < 3; y++) {
delay(100);
digitalWrite(loa, HIGH);
delay(100);
digitalWrite(loa, LOW);
}
break;
while (digitalRead(back) == 0)
;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(29, 1);
display.print("MANUAL");
display.setTextSize(1);
display.setCursor(33, 25);
display.print("LEVEL:");
display.setCursor(72, 24);
display.print(muctc);
display.drawLine(29, 17, 98, 17, 1);
display.drawLine(29, 18, 98, 18, 1);
display.drawBitmap(7, 4, image_music_next_button_bits, 15, 16, 1);
//display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
//display.drawRect(112, 2, 13, 8, 1); // Line pin
//display.drawLine(125, 4, 125, 7, 1); // Line pin
if (a >= 0 && a <= 9) {
display.setTextSize(2);
display.setCursor(59, 40);
display.print(a);
} else if (a >= 10 && a <= 99) {
display.setTextSize(2);
display.setCursor(53, 40);
display.print(a);
} else if (a > 99 && a < 1000) {
display.setTextSize(2);
display.setCursor(45, 40);
display.print(a);
} else {
display.setTextSize(2);
display.setCursor(45, 40);
display.print(" ");
}
display.fillRect(79, 52, 49, 12, 0);
unsigned int tientrinh = map(a, 0, 1000, 0, 128);
display.drawLine(1, 63, tientrinh, 63, 1); //Thanh tiến trình
unsigned int Tyle = map(a, 0, 1000, 0, 100);
display.setTextSize(1);
display.setCursor(1, 51); //Tỷ lệ chạy
display.print(Tyle); //Tỷ lệ chạy
display.print("%"); //Tỷ lệ chạy
display.setTextSize(1);
display.setCursor(82, 40);
display.print("(ml)");
display.display();
delay(10);
}
} else {
a = 0;
moto_off();
Timer1.stop();
}
moto_off();
Timer1.stop();
}
//CHƯƠNG TRÌNH CÀI ĐẶT MỰC RÓT
else if (menu1 == 1 && menu == 3) {
if (i == 0) {
if (digitalRead(up) == 0) {
delay(10);
buzzer();
u++;
}
if (u > 2) {
u = 0;
}
if (digitalRead(down) == 0) {
delay(10);
buzzer();
u--;
}
if (u < 0) {
u = 2;
}
if (digitalRead(Enter) == LOW) {
delay(5);
buzzer();
i = 1;
while (digitalRead(Enter) == LOW);
}
if (digitalRead(back) == 0) {
delay(5);
buzzer();
i = 0;
u = 0;
menu = 1;
menu1 = 0;
}
}
////////////////////////////////////////////////////////////////////////
if (u == 0 && i == 1) {
if (digitalRead(up) == 0) {
delay(5);
buzzer();
b++;
check = 0;
}
if (b > 3) {
b = 1;
}
if (digitalRead(down) == 0) {
delay(5);
buzzer();
b--;
check = 0;
}
if (b < 1) {
b = 3;
}
if (digitalRead(Enter) == LOW) {
delay(5);
buzzer();
check = 1;
}
if (digitalRead(back) == LOW) {
delay(5);
buzzer();
EEPROM.update(300, b);
delay(100);
i = 0;
u = 0;
check = 0;
}
}
//////////////////////////////////////////////
if (u == 1 && i == 1) {
if (digitalRead(Enter) == 0) {
delay(10);
buzzer();
m++;
while (digitalRead(Enter) == 0);
}
if (m > 3) {
m = 3;
check = 1;
}
if (digitalRead(up) == 0) {
delay(10);
buzzer();
a++;
check = 0;
}
if (digitalRead(down) == 0) {
delay(10);
buzzer();
a--;
check = 0;
}
if (digitalRead(back) == LOW) {
delay(5);
buzzer();
u = 0;
i = 0;
check = 0;
m = 0;
while (digitalRead(back) == 0);
EEPROM.update(0x01, a);
delay(200);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
if (u == 2 && i == 1) {
if (digitalRead(up) == 0) {
delay(5);
buzzer();
tocdo++;
check = 0;
}
if (tocdo > 255) {
tocdo = 255;
}
if (digitalRead(down) == 0) {
delay(5);
buzzer();
tocdo--;
check = 0;
}
if (tocdo < 100) {
tocdo = 100;
}
if (digitalRead(Enter) == LOW) {
delay(5);
buzzer();
check = 1;
}
if (digitalRead(back) == LOW) {
delay(5);
buzzer();
EEPROM.update(200, tocdo);
delay(100);
i = 0;
u = 0;
check = 0;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
if (i == 0) {
display.clearDisplay();
display.drawLine(36, 17, 94, 17, 1);
display.drawLine(36, 18, 94, 18, 1);
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(36, 1);
display.print("SETUP");
display.setTextSize(1);
display.setCursor(13, 30);
display.print("1. MENU KHOI DONG");
display.setCursor(13, 42);
display.print("2. MUC ROT TU DONG");
display.setCursor(13, 54);
display.print("3. SAI SO THE TICH");
display.drawBitmap(9, 3, image_cards_clubs_bits, 15, 16, 1);
//display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
//display.drawRect(112, 2, 13, 8, 1); // Line pin
//display.drawLine(125, 4, 125, 7, 1); // Line pin
if(EEPROM.read(100) == 0){
display.drawBitmap(53, 21, image_Layer_1_bits, 25, 5, 1);
}
else if(EEPROM.read(100) == 1){
display.drawBitmap(55, 21, image_Layer_2_bits, 23, 5, 1);
}
if (u == 0) {
display.drawBitmap(3, 31, image_arrow_right_bits, 7, 5, 1);
display.display();
delay(5);
} else if (u == 1) {
display.drawBitmap(3, 43, image_arrow_right_bits, 7, 5, 1);
display.display();
delay(5);
} else if (u == 2) {
display.drawBitmap(3, 55, image_arrow_right_bits, 7, 5, 1);
display.display();
delay(5);
display.display();
delay(5);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
if (i == 1 && u == 0) {
display.clearDisplay();
display.drawLine(36, 17, 94, 17, 1);
display.drawLine(36, 18, 94, 18, 1);
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(36, 1);
display.print("START");
display.drawBitmap(9, 3, image_cards_clubs_bits, 15, 16, 1);
//display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
//display.drawRect(112, 2, 13, 8, 1); // Line pin
//display.drawLine(125, 4, 125, 7, 1); // Line pin
display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
display.setTextSize(2);
display.setTextSize(2);
display.setCursor(61, 35);
display.print(b);
if (check == 1) {
display.drawBitmap(98, 32, image_check_bits, 12, 16, 1);
}
display.setTextColor(1);
display.setTextSize(1);
if (check == 0) {
display.setCursor(1, 56);
display.print("SAVE");
}
display.fillRect(87, 54, 41, 10, 0);
display.setCursor(104, 56);
display.print("BACK");
display.drawRoundRect(37, 30, 56, 24, 4, 1);
//display.fillRect(87, 54, 41, 10, 0);
display.display();
delay(5);
}
//////////////////////////////////////////////////////////////////////////////////////////
if (i == 1 && u == 1) {
display.clearDisplay();
display.drawLine(36, 17, 94, 17, 1);
display.drawLine(36, 18, 94, 18, 1);
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(36, 1);
display.print("LEVEL");
display.drawBitmap(9, 3, image_cards_clubs_bits, 15, 16, 1);
//display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
//display.drawRect(112, 2, 13, 8, 1); // Line pin
//display.drawLine(125, 4, 125, 7, 1); // Line pin
if (m == 0) {
Timer1.stop();
moto_off();
a = EEPROM.read(0x01);
display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
display.setTextSize(2);
if (a >= 0 && a <= 9) {
display.setTextSize(2);
display.setCursor(61, 35);
display.print(a);
} else if (a >= 10 && a <= 99) {
display.setTextSize(2);
display.setCursor(55, 35);
display.print(a);
} else {
display.setTextSize(2);
display.setCursor(47, 35);
display.print(a);
}
display.setTextColor(1);
display.setTextSize(1);
display.setCursor(1, 56);
display.print("DEL");
display.setCursor(98, 30);
display.print("(ml)");
display.drawRoundRect(37, 30, 56, 24, 4, 1);
// display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// display.drawRect(112, 2, 13, 8, 1); // Line pin
// display.drawLine(125, 4, 125, 7, 1); // Line pin
display.fillRect(87, 54, 41, 10, 0);
display.display();
delay(5);
} else if (m == 1) {
a = 0;
display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
display.setTextSize(2);
if (a >= 0 && a <= 9) {
display.setTextSize(2);
display.setCursor(61, 35);
display.print(a);
} else if (a >= 10 && a <= 99) {
display.setTextSize(2);
display.setCursor(55, 35);
display.print(a);
} else {
display.setTextSize(2);
display.setCursor(47, 35);
display.print(a);
}
display.setTextColor(1);
display.setTextSize(1);
display.setCursor(1, 56);
display.print("RUN");
display.setCursor(98, 30);
display.print("(ml)");
display.drawRoundRect(37, 30, 56, 24, 4, 1);
// display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// display.drawRect(112, 2, 13, 8, 1); // Line pin
// display.drawLine(125, 4, 125, 7, 1); // Line pin
display.fillRect(87, 54, 41, 10, 0);
} else if (m == 2) {
Timer1.start();
moto_on();
display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
if (a >= 0 && a <= 9) {
display.setTextSize(2);
display.setCursor(61, 35);
display.print(a);
} else if (a >= 10 && a <= 99) {
display.setTextSize(2);
display.setCursor(55, 35);
display.print(a);
} else {
display.setTextSize(2);
display.setCursor(47, 35);
display.print(a);
}
display.setTextColor(1);
display.setTextSize(1);
display.setCursor(98, 30);
display.print("(ml)");
display.setTextSize(1);
display.setCursor(1, 56);
display.print("STOP");
// display.setCursor(104, 56);
// display.print("EXIT");
display.fillRect(87, 54, 41, 10, 0);
display.drawRoundRect(37, 30, 56, 24, 4, 1);
// display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// display.drawRect(112, 2, 13, 8, 1); // Line pin
// display.drawLine(125, 4, 125, 7, 1); // Line pin
} else if (m == 3) {
Timer1.stop();
moto_off();
display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
if (a >= 0 && a <= 9) {
display.setTextSize(2);
display.setCursor(61, 35);
display.print(a);
} else if (a >= 10 && a <= 99) {
display.setTextSize(2);
display.setCursor(55, 35);
display.print(a);
} else {
display.setTextSize(2);
display.setCursor(47, 35);
display.print(a);
}
display.setTextColor(1);
display.setTextSize(1);
display.setCursor(98, 30);
display.print("(ml)");
if (check == 0) {
display.setCursor(1, 56);
display.print("SAVE");
}
// display.setCursor(104, 56);
// display.print("EXIT");
display.fillRect(87, 54, 41, 10, 0);
display.drawRoundRect(37, 30, 56, 24, 4, 1);
// display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// display.drawRect(112, 2, 13, 8, 1); // Line pin
// display.drawLine(125, 4, 125, 7, 1); // Line pin
if (check == 1) {
display.drawBitmap(102, 38, image_check_bits, 12, 16, 1);
display.setCursor(104, 56);
display.print("BACK");
}
display.display();
EEPROM.update(0x01, a);
delay(100);
}
}
///////////////////////////////////////////////////////////////////////////////////
if (i == 1 && u == 2) {
display.clearDisplay();
display.drawLine(36, 17, 94, 17, 1);
display.drawLine(36, 18, 94, 18, 1);
display.setTextSize(2);
display.setTextWrap(false);
display.setCursor(36, 1);
display.print("SPEED");
display.drawBitmap(9, 3, image_cards_clubs_bits, 15, 16, 1);
//display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
//display.drawRect(112, 2, 13, 8, 1); // Line pin
//display.drawLine(125, 4, 125, 7, 1); // Line pin
display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
display.setTextSize(2);
if (tocdo >= 0 && tocdo <= 9) {
display.setTextSize(2);
display.setCursor(61, 35);
display.print(tocdo);
} else if (tocdo >= 10 && tocdo <= 99) {
display.setTextSize(2);
display.setCursor(55, 35);
display.print(tocdo);
} else {
display.setTextSize(2);
display.setCursor(47, 35);
display.print(tocdo);
}
display.setTextColor(1);
if (check == 1) {
display.drawBitmap(98, 32, image_check_bits, 12, 16, 1);
}
display.setTextColor(1);
display.setTextSize(1);
if (check == 0) {
display.setCursor(1, 56);
display.print("SAVE");
}
display.fillRect(87, 54, 41, 10, 0);
display.setCursor(104, 56);
display.print("BACK");
display.drawRoundRect(37, 30, 56, 24, 4, 1);
//display.fillRect(87, 54, 41, 10, 0);
display.display();
delay(5);
}
//////////////:////////////////////////////////////////////////////////////////
display.display();
delay(10);
}
// CHỌN CẢM BIẾN
// else if ((menu1 == 1) && (menu == 4)) {
// ttcb = EEPROM.read(100);
// display.clearDisplay();
// display.drawLine(30, 22, 100, 22, 1);
// display.drawLine(30, 23, 100, 23, 1);
// display.setTextSize(2);
// display.setTextWrap(false);
// display.setCursor(30, 3);
// display.print("SENSOR");
// display.drawBitmap(3, 3, image_menu_settings_gear_bits, 16, 16, 1);
// display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
// display.setTextSize(2);
// if (menu4 == 0) {
// if (ttcb == 0) {
// display.setTextSize(2);
// display.setCursor(42, 35);
// display.print("HC04");
// display.setTextSize(1);
// display.setCursor(1, 56);
// display.print("ENTER");
// display.setCursor(104, 56);
// display.print("EXIT");
// } else if (ttcb == 1) {
// display.setTextSize(2);
// display.setCursor(43, 35);
// display.print("BC01");
// display.setTextSize(1);
// display.setCursor(1, 56);
// display.print("ENTER");
// display.setCursor(104, 56);
// display.print("EXIT");
// }
// display.drawBitmap(96, 31, image_check_bits, 12, 16, 1);
// display.drawRoundRect(37, 30, 56, 24, 4, 1);
// // display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// // display.drawRect(112, 2, 13, 8, 1); // Line pin
// // display.drawLine(125, 4, 125, 7, 1); // Line pin
// display.display();
// delay(10);
// }
// if (digitalRead(Enter) == LOW) {
// delay(5);
// buzzer();
// menu4++;
// if (menu4 > 2) {
// menu4 = 0;
// }
// while (digitalRead(Enter) == LOW)
// ;
// } else if (menu4 == 1) {
// display.drawBitmap(30, 46, image_ButtonRight_bits, 4, 7, 1);
// display.setTextSize(2);
// if (digitalRead(down) == LOW) {
// delay(5);
// buzzer();
// x++;
// if (x > 1) {
// x = 0;
// }
// while (digitalRead(down) == LOW)
// ;
// }
// if (digitalRead(up) == LOW) {
// delay(5);
// buzzer();
// x--;
// if (x < 0) {
// x = 1;
// }
// while (digitalRead(up) == 0)
// ;
// }
// if (x == 0) {
// display.setTextSize(2);
// display.setCursor(42, 35);
// display.print("HC04");
// display.setTextSize(1);
// display.setCursor(1, 56);
// display.print("SELECT");
// display.setCursor(104, 56);
// display.print("EXIT");
// display.drawBitmap(102, 38, image_arrow_up_bits, 5, 7, 1);
// display.drawBitmap(95, 38, image_arrow_down_bits, 5, 7, 1);
// display.drawRoundRect(37, 30, 56, 24, 4, 1);
// // display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// // display.drawRect(112, 2, 13, 8, 1); // Line pin
// // display.drawLine(125, 4, 125, 7, 1); // Line pin
// display.display();
// delay(10);
// } else if (x == 1) {
// display.setTextSize(2);
// display.setCursor(43, 35);
// display.print("BC01");
// display.setTextSize(1);
// display.setCursor(1, 56);
// display.print("SELECT");
// display.setCursor(104, 56);
// display.print("EXIT");
// display.drawBitmap(102, 38, image_arrow_up_bits, 5, 7, 1);
// display.drawBitmap(95, 38, image_arrow_down_bits, 5, 7, 1);
// display.drawRoundRect(37, 30, 56, 24, 4, 1);
// //display.drawBitmap(104, 43, image_cloud_bits, 17, 16, 1);
// // display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// // display.drawRect(112, 2, 13, 8, 1); // Line pin
// // display.drawLine(125, 4, 125, 7, 1); // Line pin
// display.display();
// delay(10);
// }
// }
// if (menu4 == 2) {
// EEPROM.update(100, x);
// delay(100);
// if (EEPROM.read(100) == 0) {
// display.setTextSize(2);
// display.setCursor(42, 35);
// display.print("HC04");
// display.setTextSize(1);
// display.setCursor(1, 56);
// display.print("SAVE");
// display.setCursor(104, 56);
// display.print("EXIT");
// display.drawRoundRect(37, 30, 56, 24, 4, 1);
// // display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// // display.drawRect(112, 2, 13, 8, 1); // Line pin
// // display.drawLine(125, 4, 125, 7, 1); // Line pin
// display.display();
// delay(10);
// }
// if (EEPROM.read(100) == 1) {
// display.setTextSize(2);
// display.setCursor(43, 35);
// display.print("BC01");
// display.setTextSize(1);
// display.setCursor(1, 56);
// display.print("SAVE");
// display.setCursor(104, 56);
// display.print("EXIT");
// display.drawRoundRect(37, 30, 56, 24, 4, 1);
// // display.drawBitmap(104, 43, image_cloud_bits, 17, 16, 1);
// // display.fillRect(114, 4, gtpin, 4, 1); // Báo mức Pin còn lại
// // display.drawRect(112, 2, 13, 8, 1); // Line pin
// // display.drawLine(125, 4, 125, 7, 1); // Line pin
// display.display();
// delay(10);
// }
// }
// if (digitalRead(back) == 0) {
// delay(5);
// buzzer();
// menu = 1;
// menu1 = 0;
// menu4 = 0;
// }
// display.display();
// delay(10);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CHƯƠNG TRÌNH NGẮT INTERRUP
void timer_isr() {
e++;
if (e >= 300) {
e = 0;
a++;
}
}
//KẾT THÚC
Loading
ds18b20
ds18b20